77import com .github .containersolutions .operator .sample .TestCustomResource ;
88import io .fabric8 .kubernetes .api .model .ObjectMetaBuilder ;
99import io .fabric8 .kubernetes .client .CustomResource ;
10- import io .fabric8 .kubernetes .client .CustomResourceDoneable ;
11- import io .fabric8 .kubernetes .client .CustomResourceList ;
1210import io .fabric8 .kubernetes .client .Watcher ;
13- import io .fabric8 .kubernetes .client .dsl .Replaceable ;
14- import io .fabric8 .kubernetes .client .dsl .internal .CustomResourceOperationsImpl ;
1511import org .junit .jupiter .api .BeforeEach ;
1612import org .junit .jupiter .api .Test ;
1713import org .mockito .ArgumentMatchers ;
@@ -27,19 +23,19 @@ class EventDispatcherTest {
2723 private CustomResource testCustomResource ;
2824 private EventDispatcher eventDispatcher ;
2925 private ResourceController <CustomResource > resourceController = mock (ResourceController .class );
30- private CustomResourceOperationsImpl < CustomResource , CustomResourceList < CustomResource >,
31- CustomResourceDoneable < CustomResource >> resourceOperation = mock ( CustomResourceOperationsImpl . class );
26+ private EventDispatcher . CustomResourceReplaceFacade customResourceReplaceFacade = mock ( EventDispatcher . CustomResourceReplaceFacade . class );
27+
3228
3329 @ BeforeEach
3430 void setup () {
35- eventDispatcher = new EventDispatcher (resourceController , resourceOperation ,
36- Controller .DEFAULT_FINALIZER );
31+ eventDispatcher = new EventDispatcher (resourceController ,
32+ Controller .DEFAULT_FINALIZER , customResourceReplaceFacade );
3733
3834 testCustomResource = getResource ();
3935
4036 when (resourceController .createOrUpdateResource (eq (testCustomResource ))).thenReturn (Optional .of (testCustomResource ));
4137 when (resourceController .deleteResource (eq (testCustomResource ))).thenReturn (true );
42- when (resourceOperation . lockResourceVersion (any ())).thenReturn (mock ( Replaceable . class ) );
38+ when (customResourceReplaceFacade . replaceWithLock (any ())).thenReturn (null );
4339 }
4440
4541 @ Test
@@ -92,7 +88,7 @@ void removesDefaultFinalizerOnDelete() {
9288 eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
9389
9490 assertEquals (0 , testCustomResource .getMetadata ().getFinalizers ().size ());
95- verify (resourceOperation , times (1 )).lockResourceVersion (any ());
91+ verify (customResourceReplaceFacade , times (1 )).replaceWithLock (any ());
9692 }
9793
9894 @ Test
@@ -104,7 +100,7 @@ void doesNotRemovesTheFinalizerIfTheDeleteMethodRemovesFalse() {
104100 eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
105101
106102 assertEquals (1 , testCustomResource .getMetadata ().getFinalizers ().size ());
107- verify (resourceOperation , never ()).lockResourceVersion (any ());
103+ verify (customResourceReplaceFacade , never ()).replaceWithLock (any ());
108104 }
109105
110106 @ Test
@@ -113,8 +109,7 @@ void doesNotUpdateTheResourceIfEmptyOptionalReturned() {
113109 when (resourceController .createOrUpdateResource (eq (testCustomResource ))).thenReturn (Optional .empty ());
114110
115111 eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
116-
117- verify (resourceOperation , never ()).lockResourceVersion (any ());
112+ verify (customResourceReplaceFacade , never ()).replaceWithLock (any ());
118113 }
119114
120115 @ Test
@@ -124,7 +119,7 @@ void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned() {
124119 eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
125120
126121 assertEquals (1 , testCustomResource .getMetadata ().getFinalizers ().size ());
127- verify (resourceOperation , times (1 )).lockResourceVersion (any ());
122+ verify (customResourceReplaceFacade , times (1 )).replaceWithLock (any ());
128123 }
129124
130125 @ Test
@@ -135,7 +130,7 @@ void doesNotAddFinalizerIfOptionalIsReturnedButMarkedForDeletion() {
135130 eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
136131
137132 assertEquals (0 , testCustomResource .getMetadata ().getFinalizers ().size ());
138- verify (resourceOperation , never ()).lockResourceVersion (any ());
133+ verify (customResourceReplaceFacade , never ()).replaceWithLock (any ());
139134 }
140135
141136 private void markForDeletion (CustomResource customResource ) {
0 commit comments