Browse Source

Added Test to writeToFile Method from Admin Class

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
7c2d302bf1
  1. 23
      src/test/java/org/example/AdminTest.java

23
src/test/java/org/example/AdminTest.java

@ -1,7 +1,12 @@
package org.example;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.*;
@ -22,5 +27,23 @@ class AdminTest {
assertTrue(printedOutput.contains("A1001"));
assertTrue(printedOutput.contains("Admin"));
}
@Test
void writeToFile() throws IOException {
Admin admin = new Admin("Simon", "A1001", "Admin") ;
String filename = "testAdminData.txt";
admin.writeToFile(admin, filename);
String content = Files.readString(Path.of(filename));
assertEquals("Simon\nA1001\nAdmin", content);
Files.delete(Path.of(filename));
}
}
Loading…
Cancel
Save