ParallaxFloatEffectTest.java revision e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771c
1// CHECKSTYLE:OFF Generated code 2/* This file is auto-generated from ParallaxIntEffectTest.java. DO NOT MODIFY. */ 3 4/* 5 * Copyright (C) 2016 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20package android.support.v17.leanback.widget; 21 22import static org.mockito.Mockito.times; 23import static org.mockito.Mockito.verify; 24 25import android.support.test.filters.SmallTest; 26import android.support.test.runner.AndroidJUnit4; 27 28import org.junit.Before; 29import org.junit.Test; 30import org.junit.runner.RunWith; 31import org.mockito.Mock; 32import org.mockito.Mockito; 33import org.mockito.MockitoAnnotations; 34 35@RunWith(AndroidJUnit4.class) 36@SmallTest 37public class ParallaxFloatEffectTest { 38 39 Parallax.FloatParallax mSource; 40 int mScreenMax; 41 ParallaxEffect.FloatEffect mEffect; 42 @Mock ParallaxTarget mTarget; 43 44 @Before 45 public void setUp() throws Exception { 46 MockitoAnnotations.initMocks(this); 47 mSource = new Parallax.FloatParallax<Parallax.FloatProperty>() { 48 49 public float getMaxValue() { 50 return mScreenMax; 51 } 52 53 @Override 54 public FloatProperty createProperty(String name, int index) { 55 return new FloatProperty(name, index); 56 } 57 }; 58 mEffect = new ParallaxEffect.FloatEffect(); 59 } 60 61 @Test 62 public void testOneVariable() { 63 mScreenMax = 1080; 64 Parallax.FloatProperty var1 = mSource.addProperty("var1"); 65 66 mEffect.setPropertyRanges(var1.atAbsolute(540), var1.atAbsolute(0)); 67 mEffect.target(mTarget); 68 69 // start 70 var1.setFloatValue(mSource, 540); 71 mEffect.performMapping(mSource); 72 verify(mTarget, times(1)).update(0f); 73 Mockito.reset(mTarget); 74 75 // 25% complete 76 var1.setFloatValue(mSource, 405); 77 mEffect.performMapping(mSource); 78 verify(mTarget, times(1)).update(0.25f); 79 Mockito.reset(mTarget); 80 81 // middle 82 var1.setFloatValue(mSource, 270); 83 mEffect.performMapping(mSource); 84 verify(mTarget, times(1)).update(.5f); 85 Mockito.reset(mTarget); 86 87 // 75% complete 88 var1.setFloatValue(mSource, 135); 89 mEffect.performMapping(mSource); 90 verify(mTarget, times(1)).update(0.75f); 91 Mockito.reset(mTarget); 92 93 // end 94 var1.setFloatValue(mSource, 0); 95 mEffect.performMapping(mSource); 96 verify(mTarget, times(1)).update(1f); 97 Mockito.reset(mTarget); 98 99 // after end 100 var1.setFloatValue(mSource, -1000); 101 mEffect.performMapping(mSource); 102 verify(mTarget, times(1)).update(1f); 103 Mockito.reset(mTarget); 104 105 // before start 106 var1.setFloatValue(mSource, 1000); 107 mEffect.performMapping(mSource); 108 verify(mTarget, times(1)).update(0f); 109 Mockito.reset(mTarget); 110 111 // unknown_before 112 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE); 113 mEffect.performMapping(mSource); 114 verify(mTarget, times(1)).update(1f); 115 Mockito.reset(mTarget); 116 117 // unknown_after 118 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_AFTER); 119 mEffect.performMapping(mSource); 120 verify(mTarget, times(1)).update(0f); 121 Mockito.reset(mTarget); 122 } 123 124 @Test(expected=IllegalStateException.class) 125 public void testVerifyKeyValueOfSameVariableInDesendantOrder() { 126 mScreenMax = 1080; 127 Parallax.FloatProperty var1 = mSource.addProperty("var1"); 128 129 mEffect.setPropertyRanges(var1.atAbsolute(540), var1.atAbsolute(550)); 130 mEffect.target(mTarget); 131 var1.setFloatValue(mSource, 0); 132 mEffect.performMapping(mSource); 133 } 134 135 @Test 136 public void testTwoVariable() { 137 mScreenMax = 1080; 138 Parallax.FloatProperty var1 = mSource.addProperty("var1"); 139 Parallax.FloatProperty var2 = mSource.addProperty("var2"); 140 141 mEffect.setPropertyRanges(var1.atAbsolute(540), var2.atAbsolute(540)); 142 mEffect.target(mTarget); 143 144 // start 145 var1.setFloatValue(mSource, 540); 146 var2.setFloatValue(mSource, 840); 147 mEffect.performMapping(mSource); 148 verify(mTarget, times(1)).update(0f); 149 Mockito.reset(mTarget); 150 151 // middle 152 var1.setFloatValue(mSource, 390); 153 var2.setFloatValue(mSource, 690); 154 mEffect.performMapping(mSource); 155 verify(mTarget, times(1)).update(.5f); 156 Mockito.reset(mTarget); 157 158 // end 159 var1.setFloatValue(mSource, 240); 160 var2.setFloatValue(mSource, 540); 161 mEffect.performMapping(mSource); 162 verify(mTarget, times(1)).update(1f); 163 Mockito.reset(mTarget); 164 165 // after end 166 var1.setFloatValue(mSource, 200); 167 var2.setFloatValue(mSource, 500); 168 mEffect.performMapping(mSource); 169 verify(mTarget, times(1)).update(1f); 170 Mockito.reset(mTarget); 171 172 // before start 173 var1.setFloatValue(mSource, 1000); 174 var2.setFloatValue(mSource, 1300); 175 mEffect.performMapping(mSource); 176 verify(mTarget, times(1)).update(0f); 177 Mockito.reset(mTarget); 178 179 // unknown_before 180 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE); 181 var2.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE); 182 mEffect.performMapping(mSource); 183 verify(mTarget, times(1)).update(1f); 184 Mockito.reset(mTarget); 185 186 // unknown_before 187 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE); 188 var2.setFloatValue(mSource, -1000); 189 mEffect.performMapping(mSource); 190 verify(mTarget, times(1)).update(1f); 191 Mockito.reset(mTarget); 192 193 // unknown_after 194 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_AFTER); 195 var2.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_AFTER); 196 mEffect.performMapping(mSource); 197 verify(mTarget, times(1)).update(0f); 198 Mockito.reset(mTarget); 199 200 // unknown_after 201 var1.setFloatValue(mSource, 1000); 202 var2.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_AFTER); 203 mEffect.performMapping(mSource); 204 verify(mTarget, times(1)).update(0f); 205 Mockito.reset(mTarget); 206 207 // unknown_before and less 208 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE); 209 var2.setFloatValue(mSource, 500); 210 mEffect.performMapping(mSource); 211 verify(mTarget, times(1)).update(1f); 212 Mockito.reset(mTarget); 213 214 // unknown_before and hit second 215 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE); 216 var2.setFloatValue(mSource, 540); 217 mEffect.performMapping(mSource); 218 verify(mTarget, times(1)).update(1f); 219 Mockito.reset(mTarget); 220 221 // unknown_before with estimation 222 var1.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE); 223 var2.setFloatValue(mSource, 1080); 224 mEffect.performMapping(mSource); 225 verify(mTarget, times(1)).update(0.5f); 226 Mockito.reset(mTarget); 227 228 // unknown_after with estimation 229 var1.setFloatValue(mSource, 0); 230 var2.setFloatValue(mSource, Parallax.FloatProperty.UNKNOWN_AFTER); 231 mEffect.performMapping(mSource); 232 verify(mTarget, times(1)).update(0.5f); 233 Mockito.reset(mTarget); 234 } 235 236} 237