dynamic-animation/src/androidTest/java/androidx/dynamicanimation/tests/SpringTests.java
@Test
    public void testAnimateToFinalPosition() throws InterruptedException {
        final SpringAnimation anim = new SpringAnimation(mView1, DynamicAnimation.SCALE_Y, 0.0f);
        final DynamicAnimation.OnAnimationEndListener mockEndListener = mock(
                DynamicAnimation.OnAnimationEndListener.class);
        anim.addEndListener(mockEndListener);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                anim.animateToFinalPosition(0.0f);
            }
        });
        assertTrue(anim.isRunning());
        Thread.sleep(100);
        assertTrue(anim.isRunning());
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                anim.animateToFinalPosition(1.0f);
            }
        });

        assertTrue(anim.isRunning());
        // Verify that it indeed ends at the value from the second animateToFinalPosition() call.
        verify(mockEndListener, timeout(1500)).onAnimationEnd(anim, false, 1.0f, 0.0f);
    }
/**
     * Verifies animateToFinalPosition works both when the anim hasn't started and when it's
     * running.
     */
Verifies animateToFinalPosition works both when the anim hasn't started and when it's
running.
Verifies animateToFinalPosition works both when the anim hasn ' t started and when it ' s running .
@Test
    public void testAnimateToFinalPosition() throws InterruptedException {
        final SpringAnimation anim = new SpringAnimation(mView1, DynamicAnimation.SCALE_Y, 0.0f);
        final DynamicAnimation.OnAnimationEndListener mockEndListener = mock(
                DynamicAnimation.OnAnimationEndListener.class);
        anim.addEndListener(mockEndListener);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                anim.animateToFinalPosition(0.0f);
            }
        });
        assertTrue(anim.isRunning());
        Thread.sleep(100);
        assertTrue(anim.isRunning());
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                anim.animateToFinalPosition(1.0f);
            }
        });
        assertTrue(anim.isRunning());
        verify(mockEndListener, timeout(1500)).onAnimationEnd(anim, false, 1.0f, 0.0f);
    }
@ Test public void testAnimateToFinalPosition ( ) throws InterruptedException { final SpringAnimation anim = new SpringAnimation ( mView1 , DynamicAnimation . SCALE_Y , 0.0f ) ; final DynamicAnimation . OnAnimationEndListener mockEndListener = mock ( DynamicAnimation . OnAnimationEndListener . class ) ; anim . addEndListener ( mockEndListener ) ; InstrumentationRegistry . getInstrumentation ( ) . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { anim . animateToFinalPosition ( 0.0f ) ; } } ) ; assertTrue ( anim . isRunning ( ) ) ; Thread . sleep ( 100 ) ; assertTrue ( anim . isRunning ( ) ) ; InstrumentationRegistry . getInstrumentation ( ) . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { anim . animateToFinalPosition ( 1.0f ) ; } } ) ; assertTrue ( anim . isRunning ( ) ) ; verify ( mockEndListener , timeout ( 1500 ) ) . onAnimationEnd ( anim , false , 1.0f , 0.0f ) ; }
Verifies animateToFinalPosition works both when the anim hasn't started and when it's
 running.
Verifies animateToFinalPosition works both when the anim hasn ' t started and when it ' s running .
// Verify that it indeed ends at the value from the second animateToFinalPosition() call.