|
| 1 | +package com.codedifferently.lesson15; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.BeforeEach; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +class Lesson15Test { |
| 9 | + |
| 10 | + private EmployeeManager manager; |
| 11 | + private Employee emp; |
| 12 | + |
| 13 | + @BeforeEach |
| 14 | + public void setUp() { |
| 15 | + manager = new EmployeeManager(); |
| 16 | + emp = new Employee(1, "Edgar Allen Poe", "Writer", 0.0); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + public void testAddEmployee() { |
| 21 | + // Act |
| 22 | + manager.addEmployee(emp); |
| 23 | + // Assert |
| 24 | + assertEquals(1, manager.getEmployeeCount()); |
| 25 | + assertEquals(emp, manager.getEmployee(1)); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testGetEmployee() { |
| 30 | + // Arrange |
| 31 | + manager.addEmployee(emp); |
| 32 | + Employee expectedValue = emp; |
| 33 | + // Act |
| 34 | + Employee actualValue = manager.getEmployee(1); |
| 35 | + // Assert |
| 36 | + assertEquals(expectedValue, actualValue, "The value retrieved should match the value added."); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testUpdateEmployee() { |
| 41 | + // Arrange |
| 42 | + manager.addEmployee(emp); |
| 43 | + Employee updatedEmployee = new Employee(1, "Frankenstein", "Admin", 0.0); |
| 44 | + // Act |
| 45 | + manager.updateEmployee(updatedEmployee); |
| 46 | + // Assert |
| 47 | + assertEquals( |
| 48 | + updatedEmployee, |
| 49 | + manager.getEmployee(1), |
| 50 | + "Updated employee details should match the new information."); |
| 51 | + } |
| 52 | +} |
0 commit comments