Skip to content

Commit 21a18a5

Browse files
committed
chore: Remove unused code and add missing unit tests
1 parent 726123b commit 21a18a5

5 files changed

Lines changed: 109 additions & 55 deletions

File tree

src/main/java/dev/dochia/cli/core/generator/simple/UnicodeGenerator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public abstract class UnicodeGenerator {
2424
private static final String ZALGO_TEXT = " ̵̡̡̢̡̨̨̢͚̬̱̤̰̗͉͚̖͙͎͔͔̺̳͕̫̬͚̹͖̬̭̖̪̗͕̜̣̥̣̼͍͉̖͍̪͈̖͚̙͛͒͂̎̊̿̀̅̈͌͋̃̾̈̾̇͛͌͘͜͜͠͝ͅͅͅ ̷͕̗̇͛̅̀̑̇̈͗͌͛̐̀͆̐̊̅̋̈́̂̈́̈́͑̓͂͂̌̈́̽͌͐̐͂͐̈́̍̂͗̂͘͠͝͝͝ͅ ̷̨̢̧̢̡̨̛͕̯̭̹͖̮̘̤̩̥̟̖͈̯̠̖͈̜͈̥̫͔̘̭͉͎͇̤̦̯͙̹̠̼̮͕̲̖̟̲̦̣͇̳͖̳̭͇͓̭͌̓̀̅̋̋̀̈́̎̄͛̾̊͐̎̉̏͊͐̑͊͒̐̔̏̔̋̑̌͆̏̀̉͆̆́̓̆̉̀̒̆̆̉̀̂̎̈̔͗̔̕̕͘̕̚̚̕͘͜͝͝͝͝͝͠ͅ ̷̧̡̥͈͓͙͈̫͙͎͈̻̔̊̎̏̑̒̐̐̆̉̍͠͝͝ ̴̡̛̛͓͎͇̘͈͇̱̟̠̳͇̬̺̲̭̪̬̼̝̠̙̹̩̱̪͔͉͎̱͚͍̬͈̤͈͙͖̝̲̦̞̺̟̟̺͇̳͈̠̘̺̪̱̮̉̀̍̏̐̃̅̐̊̾͆̐͋͊̿̉̆̾͊̀͊͒͌̀͛̎́́͂̐͂̎͛̆͜͜͜͠ͅ ̶̧̧͖̻̥̝̺̼̙̫̩̹̣̲̩̲͍̺̘͕̤͉̹̥͉̮̮̟̘̥̺̯̗̠͈̬͚̦̦͚̫̫̦̉́̾̀̅͋̋̇̕̕͜͜͝ͅͅ ̶̧̛̛̝̟̤̬̙͔̻͙͚̹̣̳̳͔̥̘̠̗̦̠͚͎̖̮̳̗̥̫͚̯̬̩̎́̽͒̋̓̀͂̈́̓́̎͐͊͒̎͒͌̿̿̔͐̈́͑̊̄̓̎͐̓̓̍͘̕̚̚͜͜ ̶̢̡̡̨̡̡̘̫̫̠̟̻̳̻͈̲̖͚͇̼̩̥̥͎̥̯͚̞̘̼̞͍̮̗͈̱͚͙̠͔̞̮̱̭͍͍̪̲̜͓͍̣̯̲̠̲̤̅͊̑̇̆́̈́̓̿̄̐̓̐͐́͛̆͜͝͝͝͠ͅ ̶̧̡̨̧̡̧̥̥̱̪͇̞̭͙͚͔̜̠͓͈̞͈̣̹̝̩̦̟̻̰͙̯̼̜̞̮̬̝͚̺̟͎̻̱̙̦̜̭̲̰͎̳̣̈͜͜͜ͅ ̸̹̟̯̝͚̪̼͓͕͕̹͖̣̠͓̫͇͚͔̼̊́͑̊̊̅͗͠ͅ";
2525
@Getter
2626
private static final List<String> spacesHeaders = Arrays.asList(" ", "\u0009");
27-
private static final List<String> whitespacesHeaders = Arrays.asList(
28-
"\u1680", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009",
29-
"\u200A", "\u2028", "\u2029", "\u202F", "\u205F", "\u3000", "\u00A0");
3027
private static final List<String> whitespacesFields = Arrays.asList(
3128
" ", "\u1680", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006",
3229
"\u2007", "\u2008", "\u2009", "\u200A", "\u2028", "\u2029", "\u202F", "\u205F", "\u3000", "\u00A0");

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,6 @@ public static void setLogLevel(String pkg, String level) {
104104
LogContext.getLogContext().getLogger(pkg).setLevel(Level.parse(level.toUpperCase(Locale.ROOT)));
105105
}
106106

107-
/**
108-
* Writes a Map of data to a YAML file using the Jackson ObjectMapper.
109-
*
110-
* @param yaml the path to the YAML file to be written
111-
* @param data the data to be written to the YAML file
112-
* @throws IOException if an I/O error occurs during the writing process
113-
*/
114-
public static void writeToYaml(String yaml, Map<String, Map<String, Object>> data)
115-
throws IOException {
116-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
117-
mapper.writeValue(new File(yaml), data);
118-
}
119-
120107
/**
121108
* This method replaces the existing value of the {@code jsonPropertyForReplacement} with the
122109
* supplied value. For complex replacement like merging with refData values or processing the
@@ -263,33 +250,6 @@ public static Object getAsAppropriateType(String initialValue) {
263250
: initialValue;
264251
}
265252

266-
/**
267-
* Checks each element in the given array against a specified predicate and constructs a
268-
* comma-separated string of elements that satisfy the predicate. The resulting string is stripped
269-
* of leading commas and spaces.
270-
*
271-
* @param pathElements The array of strings to be checked.
272-
* @param checkFunction The predicate used to test each element in the array. Elements that
273-
* satisfy the predicate will be included in the result.
274-
* @return A comma-separated string of elements that satisfy the predicate, or {@code N_A} if no
275-
* elements meet the criteria.
276-
*/
277-
public static String check(String[] pathElements, Predicate<String> checkFunction) {
278-
StringBuilder result = new StringBuilder();
279-
280-
for (String pathElement : pathElements) {
281-
if (checkFunction.test(pathElement)) {
282-
result.append(COMMA).append(pathElement);
283-
}
284-
}
285-
286-
if (!result.isEmpty()) {
287-
return StringUtils.stripStart(result.toString().trim(), ", ");
288-
}
289-
290-
return N_A;
291-
}
292-
293253
/**
294254
* Selects a random element from the provided iterable.
295255
*

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.net.Proxy;
1111

1212
import static org.assertj.core.api.Assertions.assertThat;
13-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1413

1514
@QuarkusTest
1615
class AuthArgumentsTest {

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ void shouldDisplayHelpWhenHelpOption() {
5959
.contains("dochia automatically generates");
6060
}
6161

62-
@Test
63-
void shouldDisplayLicensesWhenLicensesOption() {
64-
// Given
65-
dochiaCommand.licenses = true;
66-
67-
// When
68-
dochiaCommand.run();
69-
70-
// Then
71-
assertThat(outContent.toString()).isNotEmpty();
72-
}
7362

7463
@Test
7564
void shouldDisplayLicenseWhenLicensesOption() {
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package dev.dochia.cli.core.command;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.mockito.ArgumentCaptor;
6+
import org.mockito.Captor;
7+
import org.mockito.Mock;
8+
import org.mockito.junit.jupiter.MockitoExtension;
9+
import picocli.CommandLine;
10+
11+
import java.io.PrintWriter;
12+
import java.io.StringWriter;
13+
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
import static org.mockito.ArgumentMatchers.any;
16+
import static org.mockito.Mockito.verify;
17+
import static org.mockito.Mockito.when;
18+
19+
@ExtendWith(MockitoExtension.class)
20+
class ShortErrorMessageHandlerTest {
21+
22+
@Mock
23+
private CommandLine mockCommandLine;
24+
@Mock
25+
private CommandLine.Model.CommandSpec mockCommandSpec;
26+
@Mock
27+
private CommandLine.IExitCodeExceptionMapper mockExitCodeMapper;
28+
@Captor
29+
private ArgumentCaptor<String> stringCaptor;
30+
31+
private final StringWriter out = new StringWriter();
32+
private final StringWriter err = new StringWriter();
33+
private final ShortErrorMessageHandler handler = new ShortErrorMessageHandler();
34+
35+
private CommandLine.Help.ColorScheme createColorScheme() {
36+
return CommandLine.Help.defaultColorScheme(CommandLine.Help.Ansi.OFF);
37+
}
38+
39+
@Test
40+
void shouldPrintFullUsageAndReturnOkWhenHelpFullArgPresent() {
41+
// Given
42+
when(mockCommandLine.getOut()).thenReturn(new PrintWriter(out));
43+
String[] args = {"--help-full"};
44+
CommandLine.ParameterException ex = new CommandLine.ParameterException(mockCommandLine, "test error");
45+
46+
// When
47+
int exitCode = handler.handleParseException(ex, args);
48+
49+
// Then
50+
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
51+
verify(mockCommandLine).usage(any(PrintWriter.class));
52+
}
53+
54+
@Test
55+
void shouldPrintErrorAndSuggestionsWhenHelpFullNotPresent() {
56+
// Given
57+
when(mockCommandLine.getErr()).thenReturn(new PrintWriter(err));
58+
when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec);
59+
when(mockCommandSpec.exitCodeOnInvalidInput()).thenReturn(CommandLine.ExitCode.USAGE);
60+
when(mockCommandLine.getColorScheme()).thenReturn(createColorScheme());
61+
String[] args = {};
62+
CommandLine.ParameterException ex = new CommandLine.ParameterException(mockCommandLine, "test error");
63+
64+
// When
65+
int exitCode = handler.handleParseException(ex, args);
66+
67+
// Then
68+
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.USAGE);
69+
assertThat(err.toString())
70+
.contains("test error");
71+
}
72+
73+
@Test
74+
void shouldUseMappedExitCodeWhenExitCodeMapperPresent() {
75+
// Given
76+
when(mockCommandLine.getExitCodeExceptionMapper()).thenReturn(mockExitCodeMapper);
77+
when(mockCommandLine.getErr()).thenReturn(new PrintWriter(err));
78+
when(mockExitCodeMapper.getExitCode(any())).thenReturn(42);
79+
when(mockCommandLine.getColorScheme()).thenReturn(createColorScheme());
80+
String[] args = {};
81+
CommandLine.ParameterException ex = new CommandLine.ParameterException(mockCommandLine, "test error");
82+
83+
// When
84+
int exitCode = handler.handleParseException(ex, args);
85+
86+
// Then
87+
assertThat(exitCode).isEqualTo(42);
88+
verify(mockExitCodeMapper).getExitCode(ex);
89+
}
90+
91+
@Test
92+
void shouldUseDefaultExitCodeWhenNoExitCodeMapper() {
93+
// Given
94+
when(mockCommandLine.getExitCodeExceptionMapper()).thenReturn(null);
95+
when(mockCommandLine.getErr()).thenReturn(new PrintWriter(err));
96+
// when(mockCommandLine.getUsageHelpWidth()).thenReturn(80);
97+
when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec);
98+
when(mockCommandSpec.exitCodeOnInvalidInput()).thenReturn(123);
99+
when(mockCommandLine.getColorScheme()).thenReturn(createColorScheme());
100+
String[] args = {};
101+
CommandLine.ParameterException ex = new CommandLine.ParameterException(mockCommandLine, "test error");
102+
103+
// When
104+
int exitCode = handler.handleParseException(ex, args);
105+
106+
// Then
107+
assertThat(exitCode).isEqualTo(123);
108+
}
109+
}

0 commit comments

Comments
 (0)