Skip to content

Commit 7159474

Browse files
committed
fix: Fix the total number of reported playbooks that are displayed in the report
1 parent 391d0fb commit 7159474

9 files changed

Lines changed: 13 additions & 39 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*.tape
12
*.iml
23
.idea
34
target

src/main/java/dev/dochia/cli/core/args/AuthArguments.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Proxy getProxy() {
8383
if (proxy != null && !proxy.isEmpty()) {
8484
try {
8585
String proxyUrl = proxy.replaceFirst("^(https?://)?", "");
86-
String[] parts = proxyUrl.split(":");
86+
String[] parts = proxyUrl.split(":", 2);
8787
if (parts.length == 2) {
8888
String host = parts[0];
8989
int port = Integer.parseInt(parts[1]);

src/main/java/dev/dochia/cli/core/args/FilterArguments.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ public List<HttpMethod> getHttpMethods() {
565565
*/
566566
public long getTotalPlaybooks() {
567567
return playbooks.stream()
568-
.filter(playbook -> AnnotationUtils.findAnnotation(playbook.getClass(), TrimAndValidate.class) == null)
569-
.filter(playbook -> AnnotationUtils.findAnnotation(playbook.getClass(), SanitizeAndValidate.class) == null)
570-
.filter(playbook -> AnnotationUtils.findAnnotation(playbook.getClass(), SpecialPlaybook.class) == null)
568+
.filter(playbook -> !AnnotationUtils.isAnnotationDeclaredLocally(TrimAndValidate.class, playbook.getClass()))
569+
.filter(playbook -> !AnnotationUtils.isAnnotationDeclaredLocally(SanitizeAndValidate.class, playbook.getClass()))
570+
.filter(playbook -> !AnnotationUtils.isAnnotationDeclaredLocally(SpecialPlaybook.class, playbook.getClass()))
571571
.count();
572572
}
573573

src/main/java/dev/dochia/cli/core/command/ListCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public ListCommand(@Any Instance<TestCasePlaybook> playbooksList, @Any Instance<
7777
this.playbooksList = playbooksList.stream()
7878
.filter(playbook -> AnnotationUtils.findAnnotation(playbook.getClass(), ValidateAndTrim.class) == null)
7979
.filter(playbook -> AnnotationUtils.findAnnotation(playbook.getClass(), ValidateAndSanitize.class) == null)
80+
.filter(playbook -> AnnotationUtils.findAnnotation(playbook.getClass(), SpecialPlaybook.class) == null)
8081
.toList();
8182
this.formats = formats.stream().flatMap(format -> format.matchingFormats().stream()).sorted().toList();
8283
this.mutators = mutators.stream().map(m -> new MutatorEntry(m.getClass().getSimpleName(), m.description())).sorted().toList();

src/main/java/dev/dochia/cli/core/command/ShortErrorMessageHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class ShortErrorMessageHandler implements CommandLine.IParameterException
1818
* @param args the command line arguments that were parsed when the exception was thrown
1919
* @return the exit code to return to the operating system
2020
*/
21+
@Override
2122
public int handleParseException(CommandLine.ParameterException ex, String[] args) {
2223
CommandLine cmd = ex.getCommandLine();
2324

src/main/java/dev/dochia/cli/core/util/CommonUtils.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626

2727
/** Some utility methods that don't fit in other classes. */
2828
public abstract class CommonUtils {
29-
private static final String COMMA = ", ";
30-
private static final String N_A = "N/A";
31-
3229
/**
3330
* Custom Faker instance for generating fake data. Uses romanian locale as a tweak to load a
3431
* dpchia specific file with limited number of fake values.

src/test/java/dev/dochia/cli/core/args/FilterArgumentsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,6 @@ void shouldSkipHttpMethods() {
361361

362362
@Test
363363
void shouldCountTotalPlaybooks() {
364-
Assertions.assertThat(filterArguments.getTotalPlaybooks()).isEqualTo(116);
364+
Assertions.assertThat(filterArguments.getTotalPlaybooks()).isEqualTo(124);
365365
}
366366
}

src/test/java/dev/dochia/cli/core/command/DochiaCommandTest.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.io.ByteArrayOutputStream;
99
import java.io.PrintStream;
10+
import java.nio.charset.StandardCharsets;
1011

1112
import static org.assertj.core.api.Assertions.assertThat;
1213

@@ -35,58 +36,44 @@ void tearDown() {
3536

3637
@Test
3738
void shouldDisplayHelpWhenNoArguments() {
38-
// When
3939
dochiaCommand.run();
4040

41-
// Then
42-
assertThat(outContent.toString())
41+
assertThat(outContent.toString(StandardCharsets.UTF_8))
4342
.contains("dochia – Bringing chaos with love!")
4443
.contains("dochia automatically generates and executes")
4544
.contains("Examples:");
4645
}
4746

4847
@Test
4948
void shouldDisplayHelpWhenHelpOption() {
50-
// Given
5149
dochiaCommand.licenses = false;
52-
53-
// When
5450
dochiaCommand.run();
5551

56-
// Then
57-
assertThat(outContent.toString())
52+
assertThat(outContent.toString(StandardCharsets.UTF_8))
5853
.contains("dochia – Bringing chaos with love!")
5954
.contains("dochia automatically generates");
6055
}
6156

6257
@Test
6358
void shouldDisplayLicenseWhenLicensesOption() {
64-
// Given
6559
dochiaCommand.licenses = true;
66-
67-
// When
6860
dochiaCommand.run();
6961

70-
// Then - Just verify it doesn't throw an exception
71-
assertThat(outContent.toString()).isNotEmpty();
62+
assertThat(outContent.toString(StandardCharsets.UTF_8)).isNotEmpty();
7263
}
7364

7465
@Test
7566
void shouldReturnZeroAsExitCode() {
76-
// When
7767
int exitCode = dochiaCommand.getExitCode();
7868

79-
// Then
8069
assertThat(exitCode).isZero();
8170
}
8271

8372
@Test
8473
void shouldDisplayLicensesSuccessfully() {
85-
// When
8674
int result = dochiaCommand.displayLicenses();
8775

88-
// Then
8976
assertThat(result).isZero();
90-
assertThat(outContent.toString()).isNotEmpty();
77+
assertThat(outContent.toString(StandardCharsets.UTF_8)).isNotEmpty();
9178
}
9279
}

src/test/java/dev/dochia/cli/core/command/ShortErrorMessageHandlerTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,18 @@ void setup() {
3838

3939
@Test
4040
void shouldPrintFullUsageAndReturnOkWhenHelpFullArgPresent() {
41-
// Given
4241
when(mockCommandLine.getOut()).thenReturn(new PrintWriter(out));
4342
String[] args = {"--help-full"};
4443
CommandLine.ParameterException ex =
4544
new CommandLine.ParameterException(mockCommandLine, "test error");
46-
47-
// When
4845
int exitCode = handler.handleParseException(ex, args);
4946

50-
// Then
5147
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
5248
verify(mockCommandLine).usage(any(PrintWriter.class));
5349
}
5450

5551
@Test
5652
void shouldPrintErrorAndSuggestionsWhenHelpFullNotPresent() {
57-
// Given
5853
when(mockCommandLine.getErr()).thenReturn(new PrintWriter(err));
5954
when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec);
6055
when(mockCommandSpec.exitCodeOnInvalidInput()).thenReturn(CommandLine.ExitCode.USAGE);
@@ -63,17 +58,14 @@ void shouldPrintErrorAndSuggestionsWhenHelpFullNotPresent() {
6358
CommandLine.ParameterException ex =
6459
new CommandLine.ParameterException(mockCommandLine, "test error");
6560

66-
// When
6761
int exitCode = handler.handleParseException(ex, args);
6862

69-
// Then
7063
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.USAGE);
7164
assertThat(err.toString()).contains("test error");
7265
}
7366

7467
@Test
7568
void shouldUseMappedExitCodeWhenExitCodeMapperPresent() {
76-
// Given
7769
when(mockCommandLine.getExitCodeExceptionMapper()).thenReturn(mockExitCodeMapper);
7870
when(mockCommandLine.getErr()).thenReturn(new PrintWriter(err));
7971
when(mockExitCodeMapper.getExitCode(any())).thenReturn(42);
@@ -82,17 +74,14 @@ void shouldUseMappedExitCodeWhenExitCodeMapperPresent() {
8274
CommandLine.ParameterException ex =
8375
new CommandLine.ParameterException(mockCommandLine, "test error");
8476

85-
// When
8677
int exitCode = handler.handleParseException(ex, args);
8778

88-
// Then
8979
assertThat(exitCode).isEqualTo(42);
9080
verify(mockExitCodeMapper).getExitCode(ex);
9181
}
9282

9383
@Test
9484
void shouldUseDefaultExitCodeWhenNoExitCodeMapper() {
95-
// Given
9685
when(mockCommandLine.getExitCodeExceptionMapper()).thenReturn(null);
9786
when(mockCommandLine.getErr()).thenReturn(new PrintWriter(err));
9887
when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec);
@@ -102,10 +91,8 @@ void shouldUseDefaultExitCodeWhenNoExitCodeMapper() {
10291
CommandLine.ParameterException ex =
10392
new CommandLine.ParameterException(mockCommandLine, "test error");
10493

105-
// When
10694
int exitCode = handler.handleParseException(ex, args);
10795

108-
// Then
10996
assertThat(exitCode).isEqualTo(123);
11097
}
11198
}

0 commit comments

Comments
 (0)