BAEL-6812 Test Main Method with JUnit
- fixed review comments
This commit is contained in:
parent
fd6b6aa6d5
commit
2f639b9aab
|
@ -12,28 +12,23 @@
|
|||
<artifactId>junit-5-basics-2</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>${commons-cli.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter-api.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -54,7 +49,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<commons-cli.version>1.5.0</commons-cli.version>
|
||||
<junit-jupiter-api.version>5.10.0</junit-jupiter-api.version>
|
||||
<mockito-core.version>5.4.0</mockito-core.version>
|
||||
<mockito-core.version>5.5.0</mockito-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -55,7 +55,6 @@ public class Bootstrapper {
|
|||
.build();
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
options.addOption(inputTypeOption);
|
||||
options.addOption(fileNameOption);
|
||||
return options;
|
||||
|
|
|
@ -21,9 +21,7 @@ public class InputReader {
|
|||
|
||||
private String readFromConsole() {
|
||||
System.out.println("Enter values for calculation: \n");
|
||||
String str = new Scanner(System.in).nextLine();
|
||||
|
||||
return str;
|
||||
return new Scanner(System.in).nextLine();
|
||||
}
|
||||
|
||||
private String readFromFile(String fileName) {
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.apache.commons.cli.ParseException;
|
|||
public class StaticMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("Received input parameters: " + Arrays.asList(args));
|
||||
|
||||
processRequest(args);
|
||||
|
@ -54,7 +53,6 @@ public class StaticMain {
|
|||
}
|
||||
|
||||
public static Options getOptions() {
|
||||
|
||||
Option inputTypeOption = Option.builder("i")
|
||||
.longOpt("input")
|
||||
.required(true)
|
||||
|
@ -70,7 +68,6 @@ public class StaticMain {
|
|||
.build();
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
options.addOption(inputTypeOption);
|
||||
options.addOption(fileNameOption);
|
||||
return options;
|
||||
|
|
|
@ -40,10 +40,8 @@ public class TestSimpleMain {
|
|||
System.setIn(fips);
|
||||
System.setOut(out);
|
||||
|
||||
//execute
|
||||
SimpleMain.main(arguments);
|
||||
|
||||
//verify
|
||||
String consoleOutput = byteArrayOutputStream.toString(Charset.defaultCharset());
|
||||
assertTrue(consoleOutput.contains("Calculated sum: 6"));
|
||||
|
||||
|
@ -63,10 +61,8 @@ public class TestSimpleMain {
|
|||
System.setIn(fips);
|
||||
System.setOut(out);
|
||||
|
||||
//execute
|
||||
SimpleMain.main(arguments);
|
||||
|
||||
//verify
|
||||
String consoleOutput = byteArrayOutputStream.toString(Charset.defaultCharset());
|
||||
assertTrue(consoleOutput.contains("Calculated sum: 10"));
|
||||
|
||||
|
|
|
@ -24,10 +24,8 @@ public class TestStaticMain {
|
|||
|
||||
ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
//execute
|
||||
StaticMain.main(arguments);
|
||||
|
||||
//verify
|
||||
mockedStatic.verify(() -> StaticMain.calculateSum(stringArgumentCaptor.capture()));
|
||||
|
||||
System.setIn(original);
|
||||
|
|
Loading…
Reference in New Issue