dynamic-animation/src/androidTest/java/androidx/dynamicanimation/tests/SpringTests.java
@Test
    public void testFloatValueHolder() {
        final FloatValueHolder floatValueHolder = new FloatValueHolder(0f);
        DynamicAnimation.OnAnimationUpdateListener updateListener =
                new DynamicAnimation.OnAnimationUpdateListener() {
            private float mLastValue = 0f;
            @Override
            public void onAnimationUpdate(DynamicAnimation animation, float value, float velocity) {
                // New value >= value from last frame
                assertTrue(value >= mLastValue);
                mLastValue = value;
                assertEquals(value, floatValueHolder.getValue(), 0f);
            }
        };

        DynamicAnimation.OnAnimationUpdateListener mockListener =
                mock(DynamicAnimation.OnAnimationUpdateListener.class);

        final SpringAnimation anim = new SpringAnimation(floatValueHolder)
                .addUpdateListener(updateListener).addUpdateListener(mockListener);
        anim.setSpring(new SpringForce(1000).setDampingRatio(1.2f));

        DynamicAnimation.OnAnimationEndListener listener = mock(
                DynamicAnimation.OnAnimationEndListener.class);
        anim.addEndListener(listener);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                anim.setStartValue(0).start();
            }
        });

        verify(mockListener, timeout(1000).atLeast(10)).onAnimationUpdate(eq(anim), lt(1000f),
                any(float.class));
        verify(listener, timeout(1000)).onAnimationEnd(anim, false, 1000f, 0f);
    }
/**
     * Test that spring animation can work with a single property without an object.
     */
Test that spring animation can work with a single property without an object.
Test that spring animation can work with a single property without an object .
@Test
    public void testFloatValueHolder() {
        final FloatValueHolder floatValueHolder = new FloatValueHolder(0f);
        DynamicAnimation.OnAnimationUpdateListener updateListener =
                new DynamicAnimation.OnAnimationUpdateListener() {
            private float mLastValue = 0f;
            @Override
            public void onAnimationUpdate(DynamicAnimation animation, float value, float velocity) {
                assertTrue(value >= mLastValue);
                mLastValue = value;
                assertEquals(value, floatValueHolder.getValue(), 0f);
            }
        };
        DynamicAnimation.OnAnimationUpdateListener mockListener =
                mock(DynamicAnimation.OnAnimationUpdateListener.class);
        final SpringAnimation anim = new SpringAnimation(floatValueHolder)
                .addUpdateListener(updateListener).addUpdateListener(mockListener);
        anim.setSpring(new SpringForce(1000).setDampingRatio(1.2f));
        DynamicAnimation.OnAnimationEndListener listener = mock(
                DynamicAnimation.OnAnimationEndListener.class);
        anim.addEndListener(listener);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                anim.setStartValue(0).start();
            }
        });
        verify(mockListener, timeout(1000).atLeast(10)).onAnimationUpdate(eq(anim), lt(1000f),
                any(float.class));
        verify(listener, timeout(1000)).onAnimationEnd(anim, false, 1000f, 0f);
    }
@ Test public void testFloatValueHolder ( ) { final FloatValueHolder floatValueHolder = new FloatValueHolder ( 0f ) ; DynamicAnimation . OnAnimationUpdateListener updateListener = new DynamicAnimation . OnAnimationUpdateListener ( ) { private float mLastValue = 0f ; @ Override public void onAnimationUpdate ( DynamicAnimation animation , float value , float velocity ) { assertTrue ( value >= mLastValue ) ; mLastValue = value ; assertEquals ( value , floatValueHolder . getValue ( ) , 0f ) ; } } ; DynamicAnimation . OnAnimationUpdateListener mockListener = mock ( DynamicAnimation . OnAnimationUpdateListener . class ) ; final SpringAnimation anim = new SpringAnimation ( floatValueHolder ) . addUpdateListener ( updateListener ) . addUpdateListener ( mockListener ) ; anim . setSpring ( new SpringForce ( 1000 ) . setDampingRatio ( 1.2f ) ) ; DynamicAnimation . OnAnimationEndListener listener = mock ( DynamicAnimation . OnAnimationEndListener . class ) ; anim . addEndListener ( listener ) ; InstrumentationRegistry . getInstrumentation ( ) . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { anim . setStartValue ( 0 ) . start ( ) ; } } ) ; verify ( mockListener , timeout ( 1000 ) . atLeast ( 10 ) ) . onAnimationUpdate ( eq ( anim ) , lt ( 1000f ) , any ( float . class ) ) ; verify ( listener , timeout ( 1000 ) ) . onAnimationEnd ( anim , false , 1000f , 0f ) ; }
Test that spring animation can work with a single property without an object.
Test that spring animation can work with a single property without an object .
// New value >= value from last frame