Skip to content

Commit

Permalink
add gradle subproject
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Otto committed Apr 15, 2021
1 parent 7a0f3aa commit 8826fe5
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 1 deletion.
1 change: 1 addition & 0 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
implementation project(':ownership-cli')
implementation project(':lnd-cli')
implementation project(':cli-base')
implementation project(':wizard-cli')
implementation 'org.flywaydb:flyway-core'
testImplementation testFixtures(project(':backend-transaction'))
testImplementation testFixtures(project(':backend-transaction-models'))
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rootProject.name = 'bitbook'
include 'cli-base'
include 'cli'
include 'cli-base'
include 'backend'
include 'backend-price'
include 'backend-address-transactions'
Expand All @@ -24,3 +24,5 @@ include 'lnd'
include 'lnd-cli'
include 'ownership'
include 'ownership-cli'
include 'wizard'
include 'wizard-cli'
9 changes: 9 additions & 0 deletions wizard-cli/build.gradle
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'))
}
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");
}
}
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();
}
}
}
8 changes: 8 additions & 0 deletions wizard/build.gradle
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 wizard/src/main/java/de/cotto/bitbook/wizard/WizardService.java
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;
}
}
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();
}
}

0 comments on commit 8826fe5

Please sign in to comment.