13
13
package io .kubernetes .client .informer ;
14
14
15
15
import static org .mockito .Mockito .verify ;
16
+ import static org .mockito .Mockito .when ;
16
17
17
18
import io .kubernetes .client .informer .cache .DeltaFIFO ;
19
+ import java .util .function .Supplier ;
18
20
import org .junit .Test ;
19
21
import org .junit .runner .RunWith ;
20
22
import org .mockito .Mock ;
@@ -27,32 +29,42 @@ public class ResyncRunnableTest {
27
29
28
30
@ Mock private DeltaFIFO deltaFIFO ;
29
31
32
+ @ Mock private Supplier <Boolean > shouldResync ;
33
+
30
34
@ Test
31
35
public void testNullSupplier () {
32
- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , null );
36
+ when (shouldResync .get ()).thenReturn (true );
37
+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
33
38
underTest .run ();
34
39
verify (deltaFIFO , Mockito .times (1 )).resync ();
40
+ verify (shouldResync , Mockito .times (1 )).get ();
35
41
}
36
42
37
43
@ Test
38
44
public void testSupplierReturnsFalse () {
39
- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , () -> false );
45
+ when (shouldResync .get ()).thenReturn (false );
46
+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
40
47
underTest .run ();
41
48
verify (deltaFIFO , Mockito .never ()).resync ();
49
+ verify (shouldResync , Mockito .times (1 )).get ();
42
50
}
43
51
44
52
@ Test
45
53
public void testSupplierReturnsTrue () {
46
- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , () -> true );
54
+ when (shouldResync .get ()).thenReturn (true );
55
+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
47
56
underTest .run ();
48
57
verify (deltaFIFO , Mockito .times (1 )).resync ();
58
+ verify (shouldResync , Mockito .times (1 )).get ();
49
59
}
50
60
51
61
// "() -> null" is going to be treated as false
52
62
@ Test
53
63
public void testSupplierReturnsNull () {
54
- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , () -> null );
64
+ when (shouldResync .get ()).thenReturn (null );
65
+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
55
66
underTest .run ();
56
67
verify (deltaFIFO , Mockito .never ()).resync ();
68
+ verify (shouldResync , Mockito .times (1 )).get ();
57
69
}
58
70
}
0 commit comments