1
+ package de .cotto .bitbook .wizard .cli ;
2
+
3
+ import de .cotto .bitbook .cli .PromptChangeListener ;
4
+ import de .cotto .bitbook .wizard .WizardService ;
5
+ import org .junit .jupiter .api .Nested ;
6
+ import org .junit .jupiter .api .Test ;
7
+ import org .junit .jupiter .api .extension .ExtendWith ;
8
+ import org .mockito .InjectMocks ;
9
+ import org .mockito .Mock ;
10
+ import org .mockito .junit .jupiter .MockitoExtension ;
11
+
12
+ import static org .assertj .core .api .Assertions .assertThat ;
13
+ import static org .mockito .Mockito .verify ;
14
+ import static org .mockito .Mockito .when ;
15
+
16
+ @ ExtendWith (MockitoExtension .class )
17
+ class WizardCommandsTest {
18
+ @ InjectMocks
19
+ private WizardCommands wizardCommands ;
20
+
21
+ @ Mock
22
+ private WizardService wizardService ;
23
+
24
+ @ Mock
25
+ private PromptChangeListener promptChangeListener ;
26
+
27
+ @ Nested
28
+ class WizardDisabled {
29
+ @ Test
30
+ void enables_wizard () {
31
+ wizardCommands .wizard ();
32
+ verify (wizardService ).enableWizard ();
33
+ }
34
+
35
+ @ Test
36
+ void exit_wizard_command_initially_not_available () {
37
+ assertThat (wizardCommands .exitWizardAvailability ().isAvailable ()).isEqualTo (false );
38
+ assertThat (wizardCommands .exitWizardAvailability ().getReason ()).isEqualTo ("wizard is not active" );
39
+ }
40
+ }
41
+
42
+ @ Nested
43
+ class WizardEnabled {
44
+ @ Test
45
+ void changes_prompt () {
46
+ wizardCommands .wizard ();
47
+ verify (promptChangeListener ).changePrompt ("wizard$ " );
48
+ }
49
+
50
+ @ Test
51
+ void exit_wizard_command_available () {
52
+ when (wizardService .isEnabled ()).thenReturn (true );
53
+ assertThat (wizardCommands .exitWizardAvailability ().isAvailable ()).isEqualTo (true );
54
+ }
55
+
56
+ @ Test
57
+ void exit_wizard_changes_prompt_to_default () {
58
+ wizardCommands .exitWizard ();
59
+ verify (promptChangeListener ).changePromptToDefault ();
60
+ }
61
+
62
+ @ Test
63
+ void exit_wizard_notifies_service () {
64
+ wizardCommands .exitWizard ();
65
+ verify (wizardService ).disableWizard ();
66
+ }
67
+ }
68
+ }
0 commit comments