-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugins { | ||
id 'bitbook.java-library-conventions' | ||
} | ||
|
||
dependencies { | ||
implementation project(':cli-base') | ||
implementation project(':wizard') | ||
testImplementation testFixtures(project(':backend-transaction-models')) | ||
} |
37 changes: 37 additions & 0 deletions
37
wizard-cli/src/main/java/de/cotto/bitbook/wizard/cli/WizardCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package de.cotto.bitbook.wizard.cli; | ||
|
||
import de.cotto.bitbook.cli.PromptChangeListener; | ||
import de.cotto.bitbook.wizard.WizardService; | ||
import org.springframework.shell.Availability; | ||
import org.springframework.shell.standard.ShellComponent; | ||
import org.springframework.shell.standard.ShellMethod; | ||
|
||
@ShellComponent | ||
public class WizardCommands { | ||
private final WizardService wizardService; | ||
private final PromptChangeListener promptChangeListener; | ||
|
||
public WizardCommands(WizardService wizardService, PromptChangeListener promptChangeListener) { | ||
this.wizardService = wizardService; | ||
this.promptChangeListener = promptChangeListener; | ||
} | ||
|
||
@ShellMethod("Start the wizard which helps you complete the ownership information") | ||
public void wizard() { | ||
wizardService.enableWizard(); | ||
promptChangeListener.changePrompt("wizard$ "); | ||
} | ||
|
||
@ShellMethod("Exit the wizard") | ||
public void exitWizard() { | ||
wizardService.disableWizard(); | ||
promptChangeListener.changePromptToDefault(); | ||
} | ||
|
||
public Availability exitWizardAvailability() { | ||
if (wizardService.isEnabled()) { | ||
return Availability.available(); | ||
} | ||
return Availability.unavailable("wizard is not active"); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
wizard-cli/src/test/java/de/cotto/bitbook/wizard/cli/WizardCommandsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.cotto.bitbook.wizard.cli; | ||
|
||
import de.cotto.bitbook.cli.PromptChangeListener; | ||
import de.cotto.bitbook.wizard.WizardService; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class WizardCommandsTest { | ||
@InjectMocks | ||
private WizardCommands wizardCommands; | ||
|
||
@Mock | ||
private WizardService wizardService; | ||
|
||
@Mock | ||
private PromptChangeListener promptChangeListener; | ||
|
||
@Nested | ||
class WizardDisabled { | ||
@Test | ||
void enables_wizard() { | ||
wizardCommands.wizard(); | ||
verify(wizardService).enableWizard(); | ||
} | ||
|
||
@Test | ||
void exit_wizard_command_initially_not_available() { | ||
assertThat(wizardCommands.exitWizardAvailability().isAvailable()).isEqualTo(false); | ||
assertThat(wizardCommands.exitWizardAvailability().getReason()).isEqualTo("wizard is not active"); | ||
} | ||
} | ||
|
||
@Nested | ||
class WizardEnabled { | ||
@Test | ||
void changes_prompt() { | ||
wizardCommands.wizard(); | ||
verify(promptChangeListener).changePrompt("wizard$ "); | ||
} | ||
|
||
@Test | ||
void exit_wizard_command_available() { | ||
when(wizardService.isEnabled()).thenReturn(true); | ||
assertThat(wizardCommands.exitWizardAvailability().isAvailable()).isEqualTo(true); | ||
} | ||
|
||
@Test | ||
void exit_wizard_changes_prompt_to_default() { | ||
wizardCommands.exitWizard(); | ||
verify(promptChangeListener).changePromptToDefault(); | ||
} | ||
|
||
@Test | ||
void exit_wizard_notifies_service() { | ||
wizardCommands.exitWizard(); | ||
verify(wizardService).disableWizard(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id 'bitbook.java-library-conventions' | ||
} | ||
|
||
dependencies { | ||
implementation project(':ownership') | ||
testImplementation testFixtures(project(':backend-transaction-models')) | ||
} |
24 changes: 24 additions & 0 deletions
24
wizard/src/main/java/de/cotto/bitbook/wizard/WizardService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.cotto.bitbook.wizard; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class WizardService { | ||
private boolean enabled; | ||
|
||
public WizardService() { | ||
// default constructor | ||
} | ||
|
||
public void enableWizard() { | ||
enabled = true; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void disableWizard() { | ||
enabled = false; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
wizard/src/test/java/de/cotto/bitbook/wizard/WizardServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.cotto.bitbook.wizard; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class WizardServiceTest { | ||
@InjectMocks | ||
private WizardService wizardService; | ||
|
||
@Test | ||
void isEnabled() { | ||
assertThat(wizardService.isEnabled()).isFalse(); | ||
} | ||
|
||
@Test | ||
void enableWizard() { | ||
wizardService.enableWizard(); | ||
assertThat(wizardService.isEnabled()).isTrue(); | ||
} | ||
|
||
@Test | ||
void disableWizard() { | ||
wizardService.disableWizard(); | ||
assertThat(wizardService.isEnabled()).isFalse(); | ||
} | ||
} |