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 androidx.transition; 18 19import static org.hamcrest.core.Is.is; 20import static org.junit.Assert.assertThat; 21 22import android.support.test.filters.MediumTest; 23import android.view.View; 24import android.view.animation.LinearInterpolator; 25 26import androidx.transition.test.R; 27 28import org.hamcrest.Description; 29import org.hamcrest.TypeSafeMatcher; 30import org.junit.Test; 31 32@MediumTest 33public class ChangeBoundsTest extends BaseTransitionTest { 34 35 @Override 36 Transition createTransition() { 37 final ChangeBounds changeBounds = new ChangeBounds(); 38 changeBounds.setDuration(400); 39 changeBounds.setInterpolator(new LinearInterpolator()); 40 return changeBounds; 41 } 42 43 @Test 44 public void testResizeClip() { 45 ChangeBounds changeBounds = (ChangeBounds) mTransition; 46 assertThat(changeBounds.getResizeClip(), is(false)); 47 changeBounds.setResizeClip(true); 48 assertThat(changeBounds.getResizeClip(), is(true)); 49 } 50 51 @Test 52 public void testBasic() throws Throwable { 53 enterScene(R.layout.scene1); 54 final ViewHolder startHolder = new ViewHolder(rule.getActivity()); 55 assertThat(startHolder.red, is(atTop())); 56 assertThat(startHolder.green, is(below(startHolder.red))); 57 startTransition(R.layout.scene6); 58 waitForEnd(); 59 final ViewHolder endHolder = new ViewHolder(rule.getActivity()); 60 assertThat(endHolder.green, is(atTop())); 61 assertThat(endHolder.red, is(below(endHolder.green))); 62 } 63 64 private static TypeSafeMatcher<View> atTop() { 65 return new TypeSafeMatcher<View>() { 66 @Override 67 protected boolean matchesSafely(View view) { 68 return view.getTop() == 0; 69 } 70 71 @Override 72 public void describeTo(Description description) { 73 description.appendText("is placed at the top of its parent"); 74 } 75 }; 76 } 77 78 private static TypeSafeMatcher<View> below(final View other) { 79 return new TypeSafeMatcher<View>() { 80 @Override 81 protected boolean matchesSafely(View item) { 82 return other.getBottom() == item.getTop(); 83 } 84 85 @Override 86 public void describeTo(Description description) { 87 description.appendText("is placed below the specified view"); 88 } 89 }; 90 } 91 92 private static class ViewHolder { 93 94 public final View red; 95 public final View green; 96 97 ViewHolder(TransitionActivity activity) { 98 red = activity.findViewById(R.id.redSquare); 99 green = activity.findViewById(R.id.greenSquare); 100 } 101 } 102 103} 104