|
| 1 | +package com.codedifferently.lesson15; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +public class EmployeeTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + public void test_getId() { |
| 11 | + |
| 12 | + // Arrange |
| 13 | + int expectedId = 1; |
| 14 | + Employee employee = new Employee(expectedId, null, null, 0); |
| 15 | + |
| 16 | + // Act |
| 17 | + int actualId = employee.getId(); |
| 18 | + // Assert |
| 19 | + assertEquals(expectedId, actualId); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void test_setId() { |
| 24 | + // Arrange |
| 25 | + Employee employee = new Employee(0, null, null, 0); |
| 26 | + |
| 27 | + // Act |
| 28 | + int expectedId = 1; |
| 29 | + employee.setId(expectedId); |
| 30 | + // Assert |
| 31 | + assertEquals(expectedId, employee.getId(), "Id should be set to expected value"); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void test_getName() { |
| 36 | + |
| 37 | + // Arrange |
| 38 | + String expectedName = "John Doe"; |
| 39 | + Employee employee = new Employee(1, expectedName, "Engineering", 50000.0); |
| 40 | + // Act |
| 41 | + String actualName = employee.getName(); |
| 42 | + // Assert |
| 43 | + assertEquals(expectedName, actualName, "Name should match the expected value"); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void test_setName() { |
| 48 | + |
| 49 | + // Arrange |
| 50 | + Employee employee = new Employee(1, "Jane Doe", "Engineering", 50000.0); |
| 51 | + // Act |
| 52 | + String expectedName = "John Doe"; |
| 53 | + employee.setName(expectedName); |
| 54 | + // Assert |
| 55 | + assertEquals(expectedName, employee.getName(), "Name should be set to expected value"); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void test_getDepartment() { |
| 60 | + |
| 61 | + // Arrange |
| 62 | + String expectedDepartment = "Engineering"; |
| 63 | + Employee employee = new Employee(1, "John Doe", expectedDepartment, 50000.0); |
| 64 | + // Act |
| 65 | + String actualDepartment = employee.getDepartment(); |
| 66 | + // Assert |
| 67 | + assertEquals( |
| 68 | + expectedDepartment, actualDepartment, "Department should match the expected value"); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void test_setDepartment() { |
| 73 | + // Arrange |
| 74 | + Employee employee = new Employee(1, "John Doe", "Engineering", 50000.0); |
| 75 | + String expectedDepartment = "Marketing"; |
| 76 | + |
| 77 | + // Act |
| 78 | + employee.setDepartment(expectedDepartment); |
| 79 | + |
| 80 | + // Assert |
| 81 | + assertEquals( |
| 82 | + expectedDepartment, employee.getDepartment(), "Department should be set to expected value"); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void test_getSalary() { |
| 87 | + // Arrange |
| 88 | + double expectedSalary = 50000.0; |
| 89 | + Employee employee = new Employee(1, "John Doe", "Engineering", expectedSalary); |
| 90 | + |
| 91 | + // Act |
| 92 | + double actualSalary = employee.getSalary(); |
| 93 | + |
| 94 | + // Assert |
| 95 | + assertEquals(expectedSalary, actualSalary, "Salary should match the expected value"); |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + public void test_setSalary() { |
| 100 | + // Arrange |
| 101 | + Employee employee = new Employee(1, "John Doe", "Engineering", 50000.0); |
| 102 | + double expectedSalary = 60000.0; |
| 103 | + |
| 104 | + // Act |
| 105 | + employee.setSalary(expectedSalary); |
| 106 | + |
| 107 | + // Assert |
| 108 | + assertEquals(expectedSalary, employee.getSalary(), "Salary should be set to expected value"); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void test_getDetails() { |
| 113 | + // Arrange |
| 114 | + Employee employee = new Employee(1, "John Doe", "Engineering", 50000.0); |
| 115 | + String expectedDetails = |
| 116 | + "Employee's ID: 1 Name: John Doe Department: Engineering Salary: 50000.0"; |
| 117 | + |
| 118 | + // Act |
| 119 | + String actualDetails = employee.getDetails(); |
| 120 | + |
| 121 | + // Assert |
| 122 | + assertEquals(expectedDetails, actualDetails, "Details should match the expected format"); |
| 123 | + } |
| 124 | +} |
0 commit comments