Jinseong Jeon | e11145f | 2018-12-13 10:57:29 -0800 | [diff] [blame] | 1 | // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package mockito_interface; |
| 5 | |
| 6 | import static org.mockito.Mockito.times; |
| 7 | import static org.mockito.Mockito.verify; |
| 8 | |
| 9 | import org.junit.Before; |
| 10 | import org.junit.Test; |
| 11 | import org.junit.runner.RunWith; |
| 12 | import org.junit.runners.Parameterized; |
| 13 | import org.mockito.Mock; |
| 14 | import org.mockito.MockitoAnnotations; |
| 15 | |
| 16 | @RunWith(Parameterized.class) |
| 17 | public class InterfaceTest { |
| 18 | @Mock |
| 19 | private Interface fld; |
| 20 | |
| 21 | private InterfaceUser user; |
| 22 | |
| 23 | private boolean flag; |
| 24 | |
| 25 | @Parameterized.Parameters(name = "flag: {0}") |
| 26 | public static Boolean[] data() { |
| 27 | return new Boolean[] {true, false}; |
| 28 | } |
| 29 | |
| 30 | public InterfaceTest(boolean flag) { |
| 31 | this.flag = flag; |
| 32 | } |
| 33 | |
| 34 | @Before |
| 35 | public void setUp() { |
| 36 | MockitoAnnotations.initMocks(this); |
| 37 | user = new InterfaceUser(fld); |
| 38 | } |
| 39 | |
| 40 | @Test |
| 41 | public void test() { |
| 42 | if (flag) { |
| 43 | user.consume(); |
| 44 | } |
| 45 | verify(fld, times(flag ? 1 : 0)).onEnterForeground(); |
| 46 | } |
| 47 | } |