1
1
package io .javaoperatorsdk .operator ;
2
2
3
- import static org .mockito . Mockito . mock ;
4
- import static org .mockito . Mockito . verify ;
5
- import static org .mockito . Mockito . when ;
3
+ import org .junit . jupiter . api . Assertions ;
4
+ import org .junit . jupiter . api . DisplayName ;
5
+ import org .junit . jupiter . api . Test ;
6
6
7
7
import io .fabric8 .kubernetes .client .CustomResource ;
8
8
import io .fabric8 .kubernetes .client .KubernetesClient ;
11
11
import io .javaoperatorsdk .operator .api .reconciler .Context ;
12
12
import io .javaoperatorsdk .operator .api .reconciler .Reconciler ;
13
13
import io .javaoperatorsdk .operator .api .reconciler .UpdateControl ;
14
- import org .junit .jupiter .api .Assertions ;
15
- import org .junit .jupiter .api .DisplayName ;
16
- import org .junit .jupiter .api .Test ;
14
+
15
+ import static org .mockito .Mockito .mock ;
16
+ import static org .mockito .Mockito .verify ;
17
+ import static org .mockito .Mockito .when ;
17
18
18
19
class OperatorTest {
19
20
20
- private final KubernetesClient kubernetesClient = mock (KubernetesClient .class );
21
- private final ConfigurationService configurationService = mock (ConfigurationService .class );
22
- private final ControllerConfiguration configuration = mock (ControllerConfiguration .class );
23
-
24
- private final Operator operator = new Operator (kubernetesClient , configurationService );
25
- private final FooReconciler fooReconciler = FooReconciler .create ();
26
-
27
- @ Test
28
- @ DisplayName ("should register `Reconciler` to Controller" )
29
- public void shouldRegisterReconcilerToController () {
30
- // given
31
- when (configurationService .getConfigurationFor (fooReconciler )).thenReturn (configuration );
32
- when (configuration .watchAllNamespaces ()).thenReturn (true );
33
- when (configuration .getName ()).thenReturn ("FOO" );
34
- when (configuration .getCustomResourceClass ()).thenReturn (FooReconciler .class );
35
-
36
- // when
37
- operator .register (fooReconciler );
38
-
39
- // then
40
- verify (configuration ).watchAllNamespaces ();
41
- verify (configuration ).getName ();
42
- verify (configuration ).getCustomResourceClass ();
43
- }
21
+ private final KubernetesClient kubernetesClient = mock (KubernetesClient .class );
22
+ private final ConfigurationService configurationService = mock (ConfigurationService .class );
23
+ private final ControllerConfiguration configuration = mock (ControllerConfiguration .class );
44
24
45
- @ Test
46
- @ DisplayName ("should throw `OperationException` when Configuration is null" )
47
- public void shouldThrowOperatorExceptionWhenConfigurationIsNull () {
48
- Assertions .assertThrows (OperatorException .class , () -> operator .register (fooReconciler , null ));
49
- }
25
+ private final Operator operator = new Operator (kubernetesClient , configurationService );
26
+ private final FooReconciler fooReconciler = FooReconciler .create ();
50
27
51
- private static class FooCustomResource extends CustomResource <FooSpec , FooStatus > {
52
- }
28
+ @ Test
29
+ @ DisplayName ("should register `Reconciler` to Controller" )
30
+ public void shouldRegisterReconcilerToController () {
31
+ // given
32
+ when (configurationService .getConfigurationFor (fooReconciler )).thenReturn (configuration );
33
+ when (configuration .watchAllNamespaces ()).thenReturn (true );
34
+ when (configuration .getName ()).thenReturn ("FOO" );
35
+ when (configuration .getCustomResourceClass ()).thenReturn (FooReconciler .class );
53
36
54
- private static class FooSpec {
55
- }
37
+ // when
38
+ operator . register ( fooReconciler );
56
39
57
- private static class FooStatus {
58
- }
40
+ // then
41
+ verify (configuration ).watchAllNamespaces ();
42
+ verify (configuration ).getName ();
43
+ verify (configuration ).getCustomResourceClass ();
44
+ }
59
45
60
- private static class FooReconciler implements Reconciler <FooCustomResource > {
46
+ @ Test
47
+ @ DisplayName ("should throw `OperationException` when Configuration is null" )
48
+ public void shouldThrowOperatorExceptionWhenConfigurationIsNull () {
49
+ Assertions .assertThrows (OperatorException .class , () -> operator .register (fooReconciler , null ));
50
+ }
61
51
62
- private FooReconciler () {
63
- }
52
+ private static class FooCustomResource extends CustomResource < FooSpec , FooStatus > {
53
+ }
64
54
65
- public static FooReconciler create () {
66
- return new FooReconciler ();
67
- }
55
+ private static class FooSpec {
56
+ }
57
+
58
+ private static class FooStatus {
59
+ }
60
+
61
+ private static class FooReconciler implements Reconciler <FooCustomResource > {
62
+
63
+ private FooReconciler () {}
64
+
65
+ public static FooReconciler create () {
66
+ return new FooReconciler ();
67
+ }
68
68
69
- @ Override
70
- public UpdateControl <FooCustomResource > reconcile (FooCustomResource resource , Context context ) {
71
- return UpdateControl .updateStatusSubResource (resource );
72
- }
69
+ @ Override
70
+ public UpdateControl <FooCustomResource > reconcile (FooCustomResource resource , Context context ) {
71
+ return UpdateControl .updateStatusSubResource (resource );
73
72
}
73
+ }
74
74
75
- }
75
+ }
0 commit comments