2020import static org .junit .Assert .assertNotNull ;
2121import static org .junit .Assert .assertNull ;
2222import static org .junit .Assert .assertThat ;
23+ import static org .junit .Assert .assertTrue ;
2324
25+ import android .animation .Animator ;
26+ import android .animation .ObjectAnimator ;
27+ import android .animation .PropertyValuesHolder ;
2428import android .animation .ValueAnimator ;
2529import android .content .res .TypedArray ;
2630import android .os .Build .VERSION ;
2731import android .os .Build .VERSION_CODES ;
2832import com .google .android .material .testapp .animation .R ;
2933import androidx .appcompat .app .AppCompatActivity ;
34+ import android .view .View ;
3035import android .view .animation .PathInterpolator ;
3136import androidx .interpolator .view .animation .FastOutLinearInInterpolator ;
3237import androidx .interpolator .view .animation .FastOutSlowInInterpolator ;
@@ -56,12 +61,14 @@ public void loadMotionSpec() {
5661 }
5762
5863 @ Test
59- public void setOfObjectAnimatorMotionSpecHasAlphaAndTranslationTimings () {
64+ public void setOfObjectAnimatorMotionSpecHasAlphaAndTranslationTimingsAndValues () {
6065 MotionSpec spec =
6166 MotionSpec .createFromResource (
6267 activityTestRule .getActivity (), R .animator .valid_set_of_object_animator_motion_spec );
6368 assertNotNull (spec .getTiming ("alpha" ));
6469 assertNotNull (spec .getTiming ("translation" ));
70+ assertEquals (1 , spec .getPropertyValues ("alpha" ).length );
71+ assertEquals (1 , spec .getPropertyValues ("translation" ).length );
6572 }
6673
6774 @ Test
@@ -96,6 +103,17 @@ public void validateSetOfObjectAnimatorAlphaMotionTiming() {
96103 assertEquals (ValueAnimator .RESTART , alpha .getRepeatMode ());
97104 }
98105
106+ @ Test
107+ public void validateSetOfObjectAnimatorAlphaMotionValues () {
108+ MotionSpec spec =
109+ MotionSpec .createFromResource (
110+ activityTestRule .getActivity (), R .animator .valid_set_of_object_animator_motion_spec );
111+ View view = new View (activityTestRule .getActivity ());
112+ Animator alphaAnimator = spec .getAnimator ("alpha" , view , View .ALPHA );
113+ PropertyValuesHolder propertyValuesHolder = ((ObjectAnimator ) alphaAnimator ).getValues ()[0 ];
114+ assertTrue (fromAndToValuesMatch (propertyValuesHolder , "0.2" , "0.8" ));
115+ }
116+
99117 @ Test
100118 public void validateSetOfObjectAnimatorTranslationMotionTiming () {
101119 MotionSpec spec =
@@ -114,6 +132,30 @@ public void validateSetOfObjectAnimatorTranslationMotionTiming() {
114132 assertEquals (ValueAnimator .REVERSE , translation .getRepeatMode ());
115133 }
116134
135+ @ Test
136+ public void validateSetOfObjectAnimatorTranslationMotionValues () {
137+ MotionSpec spec =
138+ MotionSpec .createFromResource (
139+ activityTestRule .getActivity (), R .animator .valid_set_of_object_animator_motion_spec );
140+ View view = new View (activityTestRule .getActivity ());
141+ Animator translationAnimator = spec .getAnimator ("translation" , view , View .TRANSLATION_X );
142+ PropertyValuesHolder propertyValuesHolder =
143+ ((ObjectAnimator ) translationAnimator ).getValues ()[0 ];
144+ assertTrue (fromAndToValuesMatch (propertyValuesHolder , "0" , "101" ));
145+ }
146+
147+ @ Test
148+ public void validateSetOfObjectAnimatorEmptyMotionValues () {
149+ MotionSpec spec =
150+ MotionSpec .createFromResource (
151+ activityTestRule .getActivity (), R .animator .valid_set_of_object_animator_motion_spec );
152+ View view = new View (activityTestRule .getActivity ());
153+ Animator translationAnimator = spec .getAnimator ("foo" , view , View .TRANSLATION_X );
154+ PropertyValuesHolder propertyValuesHolder =
155+ ((ObjectAnimator ) translationAnimator ).getValues ()[0 ];
156+ assertTrue (fromAndToValuesMatch (propertyValuesHolder , "0.0" , "0.0" ));
157+ }
158+
117159 public void inflateInvalidSetOfSetMotionSpec () {
118160 assertNull (
119161 MotionSpec .createFromResource (
@@ -125,4 +167,19 @@ public void inflateInvalidSetOfValueAnimatorMotionSpec() {
125167 MotionSpec .createFromResource (
126168 activityTestRule .getActivity (), R .animator .invalid_set_of_value_animator_motion_spec ));
127169 }
170+
171+ @ SuppressWarnings ("StringSplitter" )
172+ private boolean fromAndToValuesMatch (
173+ PropertyValuesHolder propertyValuesHolder , String fromValue , String toValue ) {
174+ String [] valueStringTokens = propertyValuesHolder .toString ().split ("\\ s+" );
175+ int length = valueStringTokens .length ;
176+ if (length >= 2 ) {
177+ if (valueStringTokens [length - 2 ].equals (fromValue )
178+ && valueStringTokens [length - 1 ].equals (toValue )) {
179+ return true ;
180+ }
181+ }
182+
183+ return false ;
184+ }
128185}
0 commit comments