|
21 | 21 | **************************************************************************************************/ |
22 | 22 | package com.smartdevicelink.managers.video; |
23 | 23 |
|
| 24 | +import android.content.Context; |
24 | 25 | import android.view.View; |
25 | 26 | import android.view.ViewGroup; |
26 | 27 | import android.widget.Button; |
|
45 | 46 | import org.mockito.ArgumentCaptor; |
46 | 47 | import org.mockito.Captor; |
47 | 48 | import org.mockito.Mock; |
48 | | -import org.mockito.invocation.InvocationOnMock; |
49 | 49 | import org.mockito.junit.MockitoJUnitRunner; |
50 | | -import org.mockito.stubbing.Answer; |
51 | 50 |
|
52 | 51 | import java.util.ArrayList; |
53 | 52 | import java.util.List; |
|
56 | 55 | import static org.mockito.ArgumentMatchers.eq; |
57 | 56 | import static org.mockito.ArgumentMatchers.isNull; |
58 | 57 | import static org.mockito.Mockito.any; |
59 | | -import static org.mockito.Mockito.doAnswer; |
60 | 58 | import static org.mockito.Mockito.doReturn; |
61 | 59 | import static org.mockito.Mockito.mock; |
62 | 60 | import static org.mockito.Mockito.times; |
@@ -222,36 +220,53 @@ public void testRefreshWithUserData() throws Exception { |
222 | 220 | } |
223 | 221 |
|
224 | 222 | private View createViews() { |
| 223 | + Context context = InstrumentationRegistry.getInstrumentation().getContext(); |
225 | 224 |
|
226 | | - View view = mock(View.class); |
| 225 | + final View view = new View(context) { |
| 226 | + private int count = 0; |
227 | 227 |
|
228 | | - ViewGroup parent1 = mock(ViewGroup.class); |
229 | | - ViewGroup parent2 = mock(ViewGroup.class); |
| 228 | + @Override |
| 229 | + public boolean isClickable() { |
| 230 | + int curCount = count++; |
| 231 | + return (curCount >= 1) && (curCount <= 4); |
| 232 | + } |
| 233 | + }; |
230 | 234 |
|
231 | | - when(parent1.getChildCount()).thenReturn(5); |
| 235 | + final ViewGroup parent1 = new ViewGroup(context) { |
| 236 | + @Override |
| 237 | + protected void onLayout(boolean b, int i, int i1, int i2, int i3) {} |
232 | 238 |
|
233 | | - when(parent1.getChildAt(0)).thenReturn(view); |
234 | | - when(parent1.getChildAt(1)).thenReturn(view); |
235 | | - when(parent1.getChildAt(2)).thenReturn(view); |
236 | | - when(parent1.getChildAt(3)).thenReturn(parent2); |
237 | | - when(parent1.getChildAt(4)).thenReturn(view); |
| 239 | + @Override |
| 240 | + public View getChildAt(int index) { |
| 241 | + return view; |
| 242 | + } |
238 | 243 |
|
239 | | - when(parent2.getChildCount()).thenReturn(2); |
240 | | - when(parent2.getChildAt(0)).thenReturn(view); |
241 | | - when(parent2.getChildAt(1)).thenReturn(view); |
| 244 | + @Override |
| 245 | + public int getChildCount() { |
| 246 | + return 2; |
| 247 | + } |
| 248 | + }; |
242 | 249 |
|
| 250 | + final ViewGroup parent2 = new ViewGroup(context) { |
| 251 | + @Override |
| 252 | + protected void onLayout(boolean b, int i, int i1, int i2, int i3) {} |
243 | 253 |
|
244 | | - doAnswer(new Answer<Boolean>() { |
245 | | - private int count = 0; |
| 254 | + @Override |
| 255 | + public View getChildAt(int index) { |
| 256 | + if (index == 3) { |
| 257 | + return parent1; |
| 258 | + } else { |
| 259 | + return view; |
| 260 | + } |
| 261 | + } |
246 | 262 |
|
247 | 263 | @Override |
248 | | - public Boolean answer(InvocationOnMock invocation) throws Throwable { |
249 | | - int curCount = count++; |
250 | | - return (curCount >= 1) && (curCount <= 4); |
| 264 | + public int getChildCount() { |
| 265 | + return 5; |
251 | 266 | } |
252 | | - }).when(view).isClickable(); |
| 267 | + }; |
253 | 268 |
|
254 | | - return parent1; |
| 269 | + return parent2; |
255 | 270 | } |
256 | 271 |
|
257 | 272 |
|
|
0 commit comments