Browse Source

Added Test to readFromFile Method from Admin Class

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
80af156e68
  1. 26
      src/test/java/org/example/AdminTest.java

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

@ -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));
}
}
|||||||
100:0
Loading…
Cancel
Save