diff --git a/app/src/test/java/MainTest.java b/app/src/test/java/MainTest.java index 5f9ac18..d7cc6cd 100644 --- a/app/src/test/java/MainTest.java +++ b/app/src/test/java/MainTest.java @@ -13,8 +13,8 @@ class MainTest { // File handling variables @TempDir - static Path tempDir; - static Path tempFile; + private static Path tempDir; + private static Path tempFile; // PrintStream (to capture the console output) private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); @@ -24,6 +24,9 @@ class MainTest { private final PrintStream oldOut = System.out; private final PrintStream oldErr = System.err; + // Argument handling + private String[] arguments; + @BeforeAll static void start() throws IOException { tempFile = Files.createFile(tempDir.resolve("testing.txt")); @@ -34,6 +37,9 @@ class MainTest { // Create new PrintStream to capture console outputs System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); + + // Reset arguments to new array with only 1 item + arguments = new String[1]; } @AfterEach @@ -46,7 +52,7 @@ class MainTest { @Test @DisplayName("No arguments provided") void noArguments() { - String[] arguments = new String[0]; + arguments = new String[0]; Main.main(arguments); @@ -57,7 +63,7 @@ class MainTest { @Test @DisplayName("Too many arguments provided") void tooManyArguments() { - String[] arguments = new String[2]; + arguments = new String[2]; // Simulating a potential typo of the path with a space arguments[0] = "/path/to/"; arguments[1] = "file.txt";