|
|
@ -2,11 +2,10 @@ package org.example; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.PrintStream; |
|
|
|
import java.io.*; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
@ -42,8 +41,29 @@ class AdminTest { |
|
|
|
|
|
|
|
Files.delete(Path.of(filename)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void readFromFile() throws IOException { |
|
|
|
|
|
|
|
try (PrintWriter writer = new PrintWriter(new FileWriter("testAdminData.txt"))){ |
|
|
|
writer.println("Thomas"); |
|
|
|
writer.println("A1001"); |
|
|
|
writer.print("Admin"); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
String filename = "testAdminData.txt"; |
|
|
|
List<Admin> testAdmins = Admin.readFromFile(filename); |
|
|
|
|
|
|
|
assertEquals(1, testAdmins.size()); |
|
|
|
Admin admin = testAdmins.get(0); |
|
|
|
|
|
|
|
assertEquals("Thomas", admin.getName()); |
|
|
|
assertEquals("A1001", admin.getId()); |
|
|
|
assertEquals("Admin", admin.getRole()); |
|
|
|
|
|
|
|
Files.delete(Path.of(filename)); |
|
|
|
|
|
|
|
} |
|
|
|
} |