Skip to content

Commit f41b088

Browse files
committed
chore: add better test coverage
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
1 parent cfeff6e commit f41b088

3 files changed

Lines changed: 669 additions & 200 deletions

File tree

src/main/java/com/redhat/exhort/cli/App.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
*/
1616
package com.redhat.exhort.cli;
1717

18-
import static com.redhat.exhort.cli.AppUtils.exitWithError;
19-
import static com.redhat.exhort.cli.AppUtils.printException;
20-
import static com.redhat.exhort.cli.AppUtils.printLine;
18+
import java.io.IOException;
19+
import java.nio.file.Files;
20+
import java.nio.file.Path;
21+
import java.nio.file.Paths;
22+
import java.util.concurrent.CompletableFuture;
23+
import java.util.concurrent.ExecutionException;
2124

2225
import com.fasterxml.jackson.annotation.JsonInclude;
2326
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -26,13 +29,10 @@
2629
import com.redhat.exhort.api.v4.AnalysisReport;
2730
import com.redhat.exhort.api.v4.ProviderReport;
2831
import com.redhat.exhort.api.v4.Source;
32+
import static com.redhat.exhort.cli.AppUtils.exitWithError;
33+
import static com.redhat.exhort.cli.AppUtils.printException;
34+
import static com.redhat.exhort.cli.AppUtils.printLine;
2935
import com.redhat.exhort.impl.ExhortApi;
30-
import java.io.IOException;
31-
import java.nio.file.Files;
32-
import java.nio.file.Path;
33-
import java.nio.file.Paths;
34-
import java.util.concurrent.CompletableFuture;
35-
import java.util.concurrent.ExecutionException;
3636

3737
public class App {
3838

@@ -81,7 +81,10 @@ private static CliArgs parseArgs(String[] args) {
8181

8282
Path path = validateFile(args[1]);
8383

84-
OutputFormat outputFormat = parseOutputFormat(command, args[2]);
84+
OutputFormat outputFormat = OutputFormat.JSON;
85+
if(args.length == 3) {
86+
outputFormat = parseOutputFormat(command, args[2]);
87+
}
8588

8689
return new CliArgs(command, path, outputFormat);
8790
}
@@ -99,10 +102,6 @@ private static Command parseCommand(String commandStr) {
99102
}
100103

101104
private static OutputFormat parseOutputFormat(Command command, String formatArg) {
102-
if (formatArg == null) {
103-
return OutputFormat.JSON;
104-
}
105-
106105
switch (formatArg) {
107106
case "--summary":
108107
return OutputFormat.SUMMARY;
@@ -125,9 +124,6 @@ private static Path validateFile(String filePath) {
125124
if (!Files.isRegularFile(path)) {
126125
throw new IllegalArgumentException("File is not a regular file: " + filePath);
127126
}
128-
if (!Files.isReadable(path)) {
129-
throw new IllegalArgumentException("File is not readable: " + filePath);
130-
}
131127
return path;
132128
}
133129

src/main/java/com/redhat/exhort/cli/AppUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ public static void exitWithError() {
2020
System.exit(1);
2121
}
2222

23-
public static void exitWithSuccess() {
24-
System.exit(0);
25-
}
26-
2723
public static void printLine(String message) {
2824
System.out.println(message);
2925
}

0 commit comments

Comments
 (0)