refactor(test): move arguments variable to class

This commit is contained in:
Anthony Berg 2024-10-17 19:27:52 +02:00
parent 5041ac1f74
commit 80c7f92e88

View File

@ -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";