1313package io .kubernetes .client .informer ;
1414
1515import static org .mockito .Mockito .verify ;
16+ import static org .mockito .Mockito .when ;
1617
1718import io .kubernetes .client .informer .cache .DeltaFIFO ;
19+ import java .util .function .Supplier ;
1820import org .junit .Test ;
1921import org .junit .runner .RunWith ;
2022import org .mockito .Mock ;
@@ -27,32 +29,42 @@ public class ResyncRunnableTest {
2729
2830 @ Mock private DeltaFIFO deltaFIFO ;
2931
32+ @ Mock private Supplier <Boolean > shouldResync ;
33+
3034 @ Test
3135 public void testNullSupplier () {
32- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , null );
36+ when (shouldResync .get ()).thenReturn (true );
37+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
3338 underTest .run ();
3439 verify (deltaFIFO , Mockito .times (1 )).resync ();
40+ verify (shouldResync , Mockito .times (1 )).get ();
3541 }
3642
3743 @ Test
3844 public void testSupplierReturnsFalse () {
39- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , () -> false );
45+ when (shouldResync .get ()).thenReturn (false );
46+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
4047 underTest .run ();
4148 verify (deltaFIFO , Mockito .never ()).resync ();
49+ verify (shouldResync , Mockito .times (1 )).get ();
4250 }
4351
4452 @ Test
4553 public void testSupplierReturnsTrue () {
46- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , () -> true );
54+ when (shouldResync .get ()).thenReturn (true );
55+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
4756 underTest .run ();
4857 verify (deltaFIFO , Mockito .times (1 )).resync ();
58+ verify (shouldResync , Mockito .times (1 )).get ();
4959 }
5060
5161 // "() -> null" is going to be treated as false
5262 @ Test
5363 public void testSupplierReturnsNull () {
54- ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , () -> null );
64+ when (shouldResync .get ()).thenReturn (null );
65+ ResyncRunnable underTest = new ResyncRunnable (deltaFIFO , shouldResync );
5566 underTest .run ();
5667 verify (deltaFIFO , Mockito .never ()).resync ();
68+ verify (shouldResync , Mockito .times (1 )).get ();
5769 }
5870}
0 commit comments