Skip to content

Commit 8826fe5

Browse files
committed
add gradle subproject
1 parent 7a0f3aa commit 8826fe5

File tree

8 files changed

+181
-1
lines changed

8 files changed

+181
-1
lines changed

cli/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies {
1010
implementation project(':ownership-cli')
1111
implementation project(':lnd-cli')
1212
implementation project(':cli-base')
13+
implementation project(':wizard-cli')
1314
implementation 'org.flywaydb:flyway-core'
1415
testImplementation testFixtures(project(':backend-transaction'))
1516
testImplementation testFixtures(project(':backend-transaction-models'))

settings.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rootProject.name = 'bitbook'
2-
include 'cli-base'
32
include 'cli'
3+
include 'cli-base'
44
include 'backend'
55
include 'backend-price'
66
include 'backend-address-transactions'
@@ -24,3 +24,5 @@ include 'lnd'
2424
include 'lnd-cli'
2525
include 'ownership'
2626
include 'ownership-cli'
27+
include 'wizard'
28+
include 'wizard-cli'

wizard-cli/build.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id 'bitbook.java-library-conventions'
3+
}
4+
5+
dependencies {
6+
implementation project(':cli-base')
7+
implementation project(':wizard')
8+
testImplementation testFixtures(project(':backend-transaction-models'))
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.springframework.shell.Availability;
6+
import org.springframework.shell.standard.ShellComponent;
7+
import org.springframework.shell.standard.ShellMethod;
8+
9+
@ShellComponent
10+
public class WizardCommands {
11+
private final WizardService wizardService;
12+
private final PromptChangeListener promptChangeListener;
13+
14+
public WizardCommands(WizardService wizardService, PromptChangeListener promptChangeListener) {
15+
this.wizardService = wizardService;
16+
this.promptChangeListener = promptChangeListener;
17+
}
18+
19+
@ShellMethod("Start the wizard which helps you complete the ownership information")
20+
public void wizard() {
21+
wizardService.enableWizard();
22+
promptChangeListener.changePrompt("wizard$ ");
23+
}
24+
25+
@ShellMethod("Exit the wizard")
26+
public void exitWizard() {
27+
wizardService.disableWizard();
28+
promptChangeListener.changePromptToDefault();
29+
}
30+
31+
public Availability exitWizardAvailability() {
32+
if (wizardService.isEnabled()) {
33+
return Availability.available();
34+
}
35+
return Availability.unavailable("wizard is not active");
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
}

wizard/build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plugins {
2+
id 'bitbook.java-library-conventions'
3+
}
4+
5+
dependencies {
6+
implementation project(':ownership')
7+
testImplementation testFixtures(project(':backend-transaction-models'))
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package de.cotto.bitbook.wizard;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class WizardService {
7+
private boolean enabled;
8+
9+
public WizardService() {
10+
// default constructor
11+
}
12+
13+
public void enableWizard() {
14+
enabled = true;
15+
}
16+
17+
public boolean isEnabled() {
18+
return enabled;
19+
}
20+
21+
public void disableWizard() {
22+
enabled = false;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package de.cotto.bitbook.wizard;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.mockito.InjectMocks;
6+
import org.mockito.junit.jupiter.MockitoExtension;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
@ExtendWith(MockitoExtension.class)
11+
class WizardServiceTest {
12+
@InjectMocks
13+
private WizardService wizardService;
14+
15+
@Test
16+
void isEnabled() {
17+
assertThat(wizardService.isEnabled()).isFalse();
18+
}
19+
20+
@Test
21+
void enableWizard() {
22+
wizardService.enableWizard();
23+
assertThat(wizardService.isEnabled()).isTrue();
24+
}
25+
26+
@Test
27+
void disableWizard() {
28+
wizardService.disableWizard();
29+
assertThat(wizardService.isEnabled()).isFalse();
30+
}
31+
}

0 commit comments

Comments
 (0)