Skip to content

Commit 8cb7234

Browse files
committed
chore: Fix sonarqube issues
1 parent 80de954 commit 8cb7234

7 files changed

Lines changed: 43 additions & 52 deletions

File tree

src/main/java/dev/dochia/cli/core/DochiaMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public int run(String... args) {
5454
commandLine.getCommandSpec().usageMessage().abbreviateSynopsis(true);
5555
commandLine.setExecutionStrategy(parseResult -> {
5656
if (commandLine.isUsageHelpRequested() || (parseResult.subcommand() != null && parseResult.subcommand().isUsageHelpRequested())) {
57-
commandLine.getOut().println(ConsoleUtils.getShortVersionOfHelp());
57+
commandLine.getOut().println(ConsoleUtils.SHORT_HELP);
5858
return CommandLine.ExitCode.OK;
5959
}
6060
if (parseResult.subcommand() != null && parseResult.subcommand().hasMatchedOption("--help-full")) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void run() {
8181
if (licenses) {
8282
System.exit(displayLicenses());
8383
}
84-
System.out.println(ConsoleUtils.getShortVersionOfHelp());
84+
System.out.println(ConsoleUtils.SHORT_HELP);
8585
}
8686

8787
private int displayLicenses() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public int handleParseException(CommandLine.ParameterException ex, String[] args
3131
err.println(cmd.getColorScheme().errorText(ex.getMessage())); // bold red
3232
CommandLine.UnmatchedArgumentException.printSuggestions(ex, err);
3333
ConsoleUtils.emptyLine();
34-
err.println(ConsoleUtils.getShortVersionOfHelp());
34+
err.println(ConsoleUtils.SHORT_HELP);
3535

3636
CommandLine.Model.CommandSpec spec = cmd.getCommandSpec();
3737

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void run() {
167167

168168
private void checkIfNotArgs() {
169169
if (apiArguments.getContract() == null && apiArguments.getServer() == null) {
170-
System.out.println(ConsoleUtils.getShortVersionOfHelp());
170+
System.out.println(ConsoleUtils.SHORT_HELP);
171171
System.exit(0);
172172
}
173173
}

src/main/java/dev/dochia/cli/core/io/ServiceCaller.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
import dev.dochia.cli.core.context.GlobalContext;
1616
import dev.dochia.cli.core.dsl.DSLParser;
1717
import dev.dochia.cli.core.dsl.api.Parser;
18-
import dev.dochia.cli.core.playbook.api.DryRun;
1918
import dev.dochia.cli.core.http.HttpMethod;
2019
import dev.dochia.cli.core.io.util.FormEncoder;
2120
import dev.dochia.cli.core.model.HttpRequest;
2221
import dev.dochia.cli.core.model.HttpResponse;
22+
import dev.dochia.cli.core.playbook.api.DryRun;
2323
import dev.dochia.cli.core.report.TestCaseListener;
2424
import dev.dochia.cli.core.strategy.FuzzingStrategy;
2525
import dev.dochia.cli.core.util.*;
@@ -465,10 +465,7 @@ private HttpResponse.HttpResponseBuilder populateDochiaResponseFromHttpResponse(
465465

466466
private String getResponseContentType(Response response) {
467467
MediaType defaultResponseMediaType = MediaType.parse(HttpResponse.unknownContentType());
468-
if (response.body() != null) {
469-
return String.valueOf(Optional.ofNullable(response.body().contentType()).orElse(defaultResponseMediaType));
470-
}
471-
return String.valueOf(defaultResponseMediaType);
468+
return String.valueOf(Optional.ofNullable(response.body().contentType()).orElse(defaultResponseMediaType));
472469
}
473470

474471
private void addBasicAuth(List<KeyValuePair<String, Object>> headers) {
@@ -547,11 +544,7 @@ private List<KeyValuePair<String, String>> buildQueryParameters(String payload,
547544
* @throws IOException If an I/O error occurs while reading the response body.
548545
*/
549546
public String getAsRawString(Response response) throws IOException {
550-
if (response.body() != null) {
551-
return response.body().string();
552-
}
553-
554-
return "";
547+
return Optional.ofNullable(response.body().string()).orElse("");
555548
}
556549

557550
private void recordServiceData(ServiceData serviceData) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public static String check(String[] pathElements, Predicate<String> checkFunctio
283283
}
284284
}
285285

286-
if (!result.toString().isEmpty()) {
286+
if (!result.isEmpty()) {
287287
return StringUtils.stripStart(result.toString().trim(), ", ");
288288
}
289289

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

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,41 @@ public abstract class ConsoleUtils {
2121

2222
private static final Pattern ANSI_REMOVE_PATTERN = Pattern.compile("\u001B\\[[;\\d]*m");
2323
public static final String SEPARATOR = " ";
24+
public static final String SHORT_HELP =
25+
"""
26+
dochia – Bringing chaos with love!
27+
28+
Description:
29+
dochia automatically generates and executes negative and boundary testing
30+
so you can focus on creative problem-solving.
31+
32+
dochia is designed to work with OpenAPI specifications and can be run in various modes.
33+
The simplest way to run dochia is to provide the OpenAPI spec and the server URL.
34+
35+
Examples:
36+
dochia test -c api.yml -s http://localhost:8080 -H 'Authorization=Bearer TOKEN'
37+
38+
Usage:
39+
dochia test -c <contract> -s <server> [OPTIONS]
40+
dochia (test | fuzz | replay | list | info | explain) [OPTIONS]
41+
42+
Common Options:
43+
-h, --help Show help and exit.
44+
-V, --version Print version and exit.
45+
-c, --contract=<contract> API contract or spec.
46+
-s, --server=<server> Base URL of the service.
47+
-H=<name=value> Custom headers applicable to all paths(e.g., auth tokens)
48+
--headers=<file> YAML file with custom headers specific per path (e.g., auth tokens).
49+
-R=<name=value> Fixed field values applicable to all paths.
50+
--reference-data=<file> YAML file with fixed field values specific per path.
51+
-f, --playbooks=<list> Playbook names to run.
52+
-p, --paths=<list> Specific paths to test.
53+
-d, --dry-run Simulate tests without executing.
54+
55+
For full commands and options, run:
56+
dochia (test | fuzz | replay | list | info | explain) --help-full
57+
58+
""";
2459

2560
/**
2661
* Get the width of the terminal.
@@ -178,41 +213,4 @@ public static void renderSameRowAndMoveToNextLine(String message) {
178213
public static void emptyLine() {
179214
LOGGER.noFormat(" ");
180215
}
181-
182-
public static String getShortVersionOfHelp() {
183-
return """
184-
dochia – Bringing chaos with love!
185-
186-
Description:
187-
dochia automatically generates and executes negative and boundary testing
188-
so you can focus on creative problem-solving.
189-
190-
dochia is designed to work with OpenAPI specifications and can be run in various modes.
191-
The simplest way to run dochia is to provide the OpenAPI spec and the server URL.
192-
193-
Examples:
194-
dochia test -c api.yml -s http://localhost:8080 -H 'Authorization=Bearer TOKEN'
195-
196-
Usage:
197-
dochia test -c <contract> -s <server> [OPTIONS]
198-
dochia (test | fuzz | replay | list | info | explain) [OPTIONS]
199-
200-
Common Options:
201-
-h, --help Show help and exit.
202-
-V, --version Print version and exit.
203-
-c, --contract=<contract> API contract or spec.
204-
-s, --server=<server> Base URL of the service.
205-
-H=<name=value> Custom headers applicable to all paths(e.g., auth tokens)
206-
--headers=<file> YAML file with custom headers specific per path (e.g., auth tokens).
207-
-R=<name=value> Fixed field values applicable to all paths.
208-
--reference-data=<file> YAML file with fixed field values specific per path.
209-
-f, --playbooks=<list> Playbook names to run.
210-
-p, --paths=<list> Specific paths to test.
211-
-d, --dry-run Simulate tests without executing.
212-
213-
For full commands and options, run:
214-
dochia (test | fuzz | replay | list | info | explain) --help-full
215-
216-
""";
217-
}
218216
}

0 commit comments

Comments
 (0)