|
|
@ -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)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |