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
17package android.support.transition;
18
19import static org.junit.Assert.assertEquals;
20import static org.mockito.Matchers.any;
21import static org.mockito.Mockito.never;
22import static org.mockito.Mockito.verify;
23
24import android.support.test.filters.MediumTest;
25import android.support.transition.test.R;
26import android.view.View;
27
28import org.junit.Test;
29
30@MediumTest
31public class ChangeTransformTest extends BaseTransitionTest {
32
33    @Override
34    Transition createTransition() {
35        return new ChangeTransform();
36    }
37
38    @Test
39    public void testTranslation() throws Throwable {
40        enterScene(R.layout.scene1);
41
42        final View redSquare = rule.getActivity().findViewById(R.id.redSquare);
43
44        rule.runOnUiThread(new Runnable() {
45            @Override
46            public void run() {
47                TransitionManager.beginDelayedTransition(mRoot, mTransition);
48                redSquare.setTranslationX(500);
49                redSquare.setTranslationY(600);
50            }
51        });
52        waitForStart();
53
54        verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running
55        // There is no way to validate the intermediate matrix because it uses
56        // hidden properties of the View to execute.
57        waitForEnd();
58        assertEquals(500f, redSquare.getTranslationX(), 0.0f);
59        assertEquals(600f, redSquare.getTranslationY(), 0.0f);
60    }
61
62    @Test
63    public void testRotation() throws Throwable {
64        enterScene(R.layout.scene1);
65
66        final View redSquare = rule.getActivity().findViewById(R.id.redSquare);
67
68        rule.runOnUiThread(new Runnable() {
69            @Override
70            public void run() {
71                TransitionManager.beginDelayedTransition(mRoot, mTransition);
72                redSquare.setRotation(45);
73            }
74        });
75        waitForStart();
76
77        verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running
78        // There is no way to validate the intermediate matrix because it uses
79        // hidden properties of the View to execute.
80        waitForEnd();
81        assertEquals(45f, redSquare.getRotation(), 0.0f);
82    }
83
84    @Test
85    public void testScale() throws Throwable {
86        enterScene(R.layout.scene1);
87
88        final View redSquare = rule.getActivity().findViewById(R.id.redSquare);
89
90        rule.runOnUiThread(new Runnable() {
91            @Override
92            public void run() {
93                TransitionManager.beginDelayedTransition(mRoot, mTransition);
94                redSquare.setScaleX(2f);
95                redSquare.setScaleY(3f);
96            }
97        });
98        waitForStart();
99
100        verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running
101        // There is no way to validate the intermediate matrix because it uses
102        // hidden properties of the View to execute.
103        waitForEnd();
104        assertEquals(2f, redSquare.getScaleX(), 0.0f);
105        assertEquals(3f, redSquare.getScaleY(), 0.0f);
106    }
107
108    @Test
109    public void testReparent() throws Throwable {
110        final ChangeTransform changeTransform = (ChangeTransform) mTransition;
111        assertEquals(true, changeTransform.getReparent());
112        enterScene(R.layout.scene5);
113        startTransition(R.layout.scene9);
114        verify(mListener, never()).onTransitionEnd(any(Transition.class)); // still running
115        waitForEnd();
116
117        resetListener();
118        changeTransform.setReparent(false);
119        assertEquals(false, changeTransform.getReparent());
120        startTransition(R.layout.scene5);
121        waitForEnd(); // no transition to run because reparent == false
122    }
123
124}
125