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 | |
Jinseong Jeon | e11145f | 2018-12-13 10:57:29 -0800 | [diff] [blame] | 9 | import org.mockito.Mock; |
| 10 | import org.mockito.MockitoAnnotations; |
| 11 | |
Jinseong Jeon | e11145f | 2018-12-13 10:57:29 -0800 | [diff] [blame] | 12 | public class InterfaceTest { |
Ian Zerny | acb4f32 | 2022-04-08 12:40:00 +0200 | [diff] [blame] | 13 | |
Jinseong Jeon | e11145f | 2018-12-13 10:57:29 -0800 | [diff] [blame] | 14 | @Mock |
| 15 | private Interface fld; |
| 16 | |
| 17 | private InterfaceUser user; |
| 18 | |
| 19 | private boolean flag; |
| 20 | |
Ian Zerny | acb4f32 | 2022-04-08 12:40:00 +0200 | [diff] [blame] | 21 | public static void main(String[] args) { |
| 22 | for (boolean flag : new boolean[] {true, false}) { |
| 23 | InterfaceTest test = new InterfaceTest(flag); |
| 24 | test.setUp(); |
| 25 | test.test(); |
| 26 | } |
Jinseong Jeon | e11145f | 2018-12-13 10:57:29 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | public InterfaceTest(boolean flag) { |
| 30 | this.flag = flag; |
| 31 | } |
| 32 | |
Jinseong Jeon | e11145f | 2018-12-13 10:57:29 -0800 | [diff] [blame] | 33 | public void setUp() { |
| 34 | MockitoAnnotations.initMocks(this); |
| 35 | user = new InterfaceUser(fld); |
| 36 | } |
| 37 | |
Jinseong Jeon | e11145f | 2018-12-13 10:57:29 -0800 | [diff] [blame] | 38 | public void test() { |
| 39 | if (flag) { |
| 40 | user.consume(); |
| 41 | } |
| 42 | verify(fld, times(flag ? 1 : 0)).onEnterForeground(); |
| 43 | } |
| 44 | } |