|
| 1 | +package com.codedifferently.lesson15; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +public class EmployeeTest { |
| 7 | + |
| 8 | + @Test |
| 9 | + public void testSetId() { |
| 10 | + // Arrange - create a new employee with initial id |
| 11 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 12 | + |
| 13 | + // Act - get initial expected employee id |
| 14 | + int expected = 1; |
| 15 | + int employeeId = employee.getId(); |
| 16 | + |
| 17 | + // Assert - return expected id |
| 18 | + assertEquals(expected, employeeId); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + public void testGetId() { |
| 23 | + // Arrange - create a new employee with initial id |
| 24 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 25 | + |
| 26 | + // Act - set a new employee id |
| 27 | + employee.setId(4); |
| 28 | + |
| 29 | + // Assert - returns new employee id |
| 30 | + assertEquals(4, employee.getId()); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testGetName() { |
| 35 | + // Arrange - creates a new employee with initial name |
| 36 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 37 | + |
| 38 | + // Act - gets initial expected name of employee |
| 39 | + String expected = "Karen"; |
| 40 | + String employeeName = employee.getName(); |
| 41 | + |
| 42 | + // Assert - returns employee name |
| 43 | + assertEquals(expected, employeeName); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testSetName() { |
| 48 | + // Arrange - creates a new employee with initial name |
| 49 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 50 | + |
| 51 | + // Act - sets employee name to a new employee |
| 52 | + employee.setName("Kaleb"); |
| 53 | + |
| 54 | + // Assert - checks new employee name is updated |
| 55 | + assertEquals("Kaleb", employee.getName()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testGetDepartment() { |
| 60 | + // Arrange - creates a new employee under initial department |
| 61 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 62 | + |
| 63 | + // Act - retrieves employee department using getter method |
| 64 | + String expected = "Technical"; |
| 65 | + String employeeName = employee.getDepartment(); |
| 66 | + |
| 67 | + // Assert - checks employee department is correct; returns expected employee department |
| 68 | + assertEquals(expected, employeeName); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testSetDepartment() { |
| 73 | + // Arrange - creates new employee under initial department |
| 74 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 75 | + |
| 76 | + // Act - updates department employee is under with setter method |
| 77 | + employee.setDepartment("Fashion"); |
| 78 | + |
| 79 | + // Assert - returns updated department of employee |
| 80 | + assertEquals("Fashion", employee.getDepartment()); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testGetSalary() { |
| 85 | + // Arrange - creates new employee with initial salary |
| 86 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 87 | + |
| 88 | + // Act - retrieves new employee salary with getter method |
| 89 | + int expected = 300000; |
| 90 | + Double employeeSalary = employee.getSalary(); |
| 91 | + |
| 92 | + // Assert - verifys employee salary is correct; returns expected employee salary |
| 93 | + assertEquals(expected, employeeSalary); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testSetSalary() { |
| 98 | + // Arrange - creates new employee with inital salary |
| 99 | + Employee employee = new Employee(1, "Karen", "Technical", 300000); |
| 100 | + |
| 101 | + // Act - updates new employees salary with setter method |
| 102 | + employee.setSalary(350000); |
| 103 | + |
| 104 | + // Assert - ensures new salary is |
| 105 | + assertEquals(350000, employee.getSalary()); |
| 106 | + } |
| 107 | +} |
0 commit comments