dynamic-animation/src/androidTest/java/androidx/dynamicanimation/tests/SpringTests.java
@Test
    public void testInvalidStartingCondition() {
        final SpringAnimation anim = new SpringAnimation(mView1, DynamicAnimation.X);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                // Expect exception from not setting spring final position before calling start.
                try {
                    anim.start();
                    fail("No exception is thrown when calling start() from non-main thread.");
                } catch (UnsupportedOperationException e) {
                }

                // Expect exception from having a final position < min value
                try {
                    anim.setMinValue(50);
                    // Final position < min value, expect exception.
                    anim.setStartValue(50).animateToFinalPosition(40);
                    fail("No exception is thrown when spring position is less than min value.");
                } catch (UnsupportedOperationException e) {
                }

                // Expect exception from not setting spring final position before calling start.
                try {
                    anim.setMaxValue(60);
                    // Final position < min value, expect exception.
                    anim.setStartValue(60).animateToFinalPosition(70);
                    fail("No exception is thrown when spring position is greater than max value.");
                } catch (UnsupportedOperationException e) {
                }
            }
        });
    }
/**
     * Test invalid start condition: no spring position specified, final position > max value,
     * and final position < min. Expect exception in all these cases.
     */
Test invalid start condition: no spring position specified, final position > max value,
and final position < min. Expect exception in all these cases.
Test invalid start condition : no spring position specified final position > max value and final position < min . Expect exception in all these cases .
@Test
    public void testInvalidStartingCondition() {
        final SpringAnimation anim = new SpringAnimation(mView1, DynamicAnimation.X);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                try {
                    anim.start();
                    fail("No exception is thrown when calling start() from non-main thread.");
                } catch (UnsupportedOperationException e) {
                }
                try {
                    anim.setMinValue(50);
                    anim.setStartValue(50).animateToFinalPosition(40);
                    fail("No exception is thrown when spring position is less than min value.");
                } catch (UnsupportedOperationException e) {
                }
                try {
                    anim.setMaxValue(60);
                    anim.setStartValue(60).animateToFinalPosition(70);
                    fail("No exception is thrown when spring position is greater than max value.");
                } catch (UnsupportedOperationException e) {
                }
            }
        });
    }
@ Test public void testInvalidStartingCondition ( ) { final SpringAnimation anim = new SpringAnimation ( mView1 , DynamicAnimation . X ) ; InstrumentationRegistry . getInstrumentation ( ) . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { try { anim . start ( ) ; fail ( "No exception is thrown when calling start() from non-main thread." ) ; } catch ( UnsupportedOperationException e ) { } try { anim . setMinValue ( 50 ) ; anim . setStartValue ( 50 ) . animateToFinalPosition ( 40 ) ; fail ( "No exception is thrown when spring position is less than min value." ) ; } catch ( UnsupportedOperationException e ) { } try { anim . setMaxValue ( 60 ) ; anim . setStartValue ( 60 ) . animateToFinalPosition ( 70 ) ; fail ( "No exception is thrown when spring position is greater than max value." ) ; } catch ( UnsupportedOperationException e ) { } } } ) ; }
Test invalid start condition: no spring position specified, final position > max value,
 and final position < min.
Test invalid start condition : no spring position specified final position > max value and final position < min .
// Expect exception from not setting spring final position before calling start. // Expect exception from having a final position < min value // Final position < min value, expect exception. // Expect exception from not setting spring final position before calling start. // Final position < min value, expect exception.