78 lines
2.7 KiB
Java
78 lines
2.7 KiB
Java
package oving6.office;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class ClerkTest {
|
|
|
|
private Clerk clerk;
|
|
private Printer printer;
|
|
|
|
@BeforeEach
|
|
public void setUp() {
|
|
printer = new Printer();
|
|
clerk = new Clerk(printer);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Perform calculations")
|
|
public void testDoCalculations() {
|
|
assertEquals(0, clerk.getTaskCount(),
|
|
"Testing the initialization of the number of tasks performed");
|
|
|
|
double calc1 = clerk.doCalculations((x, y) -> x + y, 2.0, 3.5);
|
|
assertEquals(5.5, calc1, "Testing calculation with addition: 2.0 + 3.5");
|
|
assertEquals(1, clerk.getTaskCount(), "Testing the number of tasks after 1 calculation");
|
|
|
|
double calc2 = clerk.doCalculations((x, y) -> x / y, 2.0, 4.0);
|
|
assertEquals(0.5, calc2, "Testing calculation with division: 2.0/4.0");
|
|
assertEquals(2, clerk.getTaskCount(), "Testing the number of tasks after two calculations");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Print documents")
|
|
public void testPrintDocuments() {
|
|
assertEquals(0, clerk.getTaskCount(),
|
|
"Testing the initialization of the number of tasks performed");
|
|
|
|
// Print a document
|
|
clerk.printDocument("document1");
|
|
assertTrue(printer.getPrintHistory(clerk).contains("document1"),
|
|
"Testing if the document that was printed was added to the printer history");
|
|
assertEquals(1, clerk.getTaskCount(), "Testing the number of tasks after 1 print");
|
|
assertEquals(1, printer.getPrintHistory(clerk).size(),
|
|
"Testing the number of prints in the history after 1 print");
|
|
|
|
// Print another document
|
|
clerk.printDocument("document2");
|
|
assertTrue(printer.getPrintHistory(clerk).contains("document2"),
|
|
"Testing if document 2 that was printed was added to the printer history");
|
|
assertEquals(2, clerk.getTaskCount(), "Testing the number of tasks after 2 prints");
|
|
assertEquals(2, printer.getPrintHistory(clerk).size(),
|
|
"Testing the number of prints in the history after 2 prints");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Retrieve task count")
|
|
public void testTaskCount() {
|
|
assertEquals(0, clerk.getTaskCount(),
|
|
"Testing the initialization of the number of tasks performed");
|
|
|
|
clerk.printDocument("document1");
|
|
assertEquals(1, clerk.getTaskCount(), "Testing the number of tasks after 1 print");
|
|
|
|
clerk.doCalculations((x, y) -> x + y, 2.0, 3.5);
|
|
assertEquals(2, clerk.getTaskCount(),
|
|
"Testing the number of tasks after 1 print and 1 calculation");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Retrieve resource count")
|
|
public void testResourceCount() {
|
|
assertEquals(1, clerk.getResourceCount(), "Testing the number of resources for one worker");
|
|
}
|
|
}
|