1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.transition; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.mockito.Matchers.any; 21 import static org.mockito.Mockito.never; 22 import static org.mockito.Mockito.verify; 23 24 import android.support.test.filters.MediumTest; 25 import android.view.View; 26 27 import androidx.transition.test.R; 28 29 import org.junit.Test; 30 31 @MediumTest 32 public class ChangeTransformTest extends BaseTransitionTest { 33 34 @Override 35 Transition createTransition() { 36 return new ChangeTransform(); 37 } 38 39 @Test 40 public void testTranslation() throws Throwable { 41 enterScene(R.layout.scene1); 42 43 final View redSquare = rule.getActivity().findViewById(R.id.redSquare); 44 45 rule.runOnUiThread(new Runnable() { 46 @Override 47 public void run() { 48 TransitionManager.beginDelayedTransition(mRoot, mTransition); 49 redSquare.setTranslationX(500); 50 redSquare.setTranslationY(600); 51 } 52 }); 53 waitForStart(); 54 55 verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running 56 // There is no way to validate the intermediate matrix because it uses 57 // hidden properties of the View to execute. 58 waitForEnd(); 59 assertEquals(500f, redSquare.getTranslationX(), 0.0f); 60 assertEquals(600f, redSquare.getTranslationY(), 0.0f); 61 } 62 63 @Test 64 public void testRotation() throws Throwable { 65 enterScene(R.layout.scene1); 66 67 final View redSquare = rule.getActivity().findViewById(R.id.redSquare); 68 69 rule.runOnUiThread(new Runnable() { 70 @Override 71 public void run() { 72 TransitionManager.beginDelayedTransition(mRoot, mTransition); 73 redSquare.setRotation(45); 74 } 75 }); 76 waitForStart(); 77 78 verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running 79 // There is no way to validate the intermediate matrix because it uses 80 // hidden properties of the View to execute. 81 waitForEnd(); 82 assertEquals(45f, redSquare.getRotation(), 0.0f); 83 } 84 85 @Test 86 public void testScale() throws Throwable { 87 enterScene(R.layout.scene1); 88 89 final View redSquare = rule.getActivity().findViewById(R.id.redSquare); 90 91 rule.runOnUiThread(new Runnable() { 92 @Override 93 public void run() { 94 TransitionManager.beginDelayedTransition(mRoot, mTransition); 95 redSquare.setScaleX(2f); 96 redSquare.setScaleY(3f); 97 } 98 }); 99 waitForStart(); 100 101 verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running 102 // There is no way to validate the intermediate matrix because it uses 103 // hidden properties of the View to execute. 104 waitForEnd(); 105 assertEquals(2f, redSquare.getScaleX(), 0.0f); 106 assertEquals(3f, redSquare.getScaleY(), 0.0f); 107 } 108 109 @Test 110 public void testReparent() throws Throwable { 111 final ChangeTransform changeTransform = (ChangeTransform) mTransition; 112 assertEquals(true, changeTransform.getReparent()); 113 enterScene(R.layout.scene5); 114 startTransition(R.layout.scene9); 115 verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running 116 waitForEnd(); 117 118 resetListener(); 119 changeTransform.setReparent(false); 120 assertEquals(false, changeTransform.getReparent()); 121 startTransition(R.layout.scene5); 122 waitForEnd(); // no transition to run because reparent == false 123 } 124 125 } 126