|
1 | 1 | package com.codedifferently.lesson15; |
2 | 2 |
|
3 | | -import static org.assertj.core.api.Assertions.assertThat; |
4 | | - |
5 | | -import org.junit.jupiter.api.Test; |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
6 | 4 | import org.junit.jupiter.api.BeforeEach; |
| 5 | +import org.junit.jupiter.api.Test; |
7 | 6 |
|
8 | | -import com.codedifferently.lesson14.ecommerce.EcommerceSystem; |
9 | 7 |
|
10 | 8 | public class EmployeeTest { |
11 | 9 |
|
12 | | - EmployeeTest employeeTest; |
13 | | - |
| 10 | + Employee employee; |
| 11 | + //Set up |
14 | 12 | @BeforeEach |
15 | | - void setUp() { |
16 | | - employeeTest = new EmployeeTest(); |
17 | | - } |
| 13 | + void setUp() { |
| 14 | + employee = new Employee(19, "Chigazo", "Finance", 200000.00); |
| 15 | + } |
18 | 16 |
|
19 | 17 | @Test |
20 | | - public void getIdTest() { |
21 | | - // test if id matches set id |
22 | | - |
23 | | - Id idObject = new Id(57); |
| 18 | + //Method beign tested |
| 19 | + public void testGetId() { |
| 20 | + //Execersise |
| 21 | + int actualId = employee.getId(); |
24 | 22 |
|
25 | | - int expectedId = idObject.getId(); |
26 | | - |
27 | | - assertThat(expectedId).isEqualTo(57); |
| 23 | + int expectedId = 19; |
| 24 | + //Assert(Checking the value) |
| 25 | + assertEquals(expectedId, actualId); |
28 | 26 | } |
29 | 27 |
|
30 | 28 | @Test |
31 | | - public void setIdTest() { |
32 | | - // tests if changed id matches new id |
33 | | - employeeTest.setId(); |
| 29 | + public void testSetID() { |
| 30 | + //Arrange |
| 31 | + int expectedSetId = 91; |
| 32 | + //Act |
| 33 | + employee.setId(expectedSetId); |
| 34 | + //Assert |
| 35 | + assertEquals(expectedSetId, employee.getId()); |
34 | 36 | } |
35 | 37 |
|
36 | 38 | @Test |
37 | | - public void getNameTest() { |
38 | | - // tests if changed name matches name |
39 | | - employeeTest.getName(); |
| 39 | + public void testGetName() { |
| 40 | + |
| 41 | + String actualName = employee.getName(); |
| 42 | + |
| 43 | + String expectedName = "Chigazo"; |
| 44 | + |
| 45 | + assertEquals(expectedName, actualName); |
40 | 46 | } |
41 | 47 |
|
42 | 48 | @Test |
43 | | - public void setNameTest() { |
44 | | - // tests if changed id matches new id |
45 | | - employeeTest.setName(); |
| 49 | + public void testSetName() { |
| 50 | + //Arrange |
| 51 | + String expectedSetName = "Austin"; |
| 52 | + //Act |
| 53 | + employee.setName(expectedSetName); |
| 54 | + //Assert |
| 55 | + assertEquals(expectedSetName, employee.getName()); |
46 | 56 | } |
47 | 57 |
|
48 | 58 | @Test |
49 | 59 | public void getDepartmentTest() { |
50 | | - employeeTest.getDepartment(); |
51 | | - } |
| 60 | + String expectedDepartment = employee.getDepartment(); |
52 | 61 |
|
53 | | - @Test |
54 | | - public void setDepartmentTest() { |
55 | | - employeeTest.setDepartment(); |
| 62 | + String actualDepartment = "Finance"; |
| 63 | + |
| 64 | + assertEquals(expectedDepartment, actualDepartment); |
56 | 65 | } |
57 | 66 |
|
| 67 | + // @Test |
| 68 | + // public void setDepartmentTest() { |
| 69 | + // employee.setDepartment(); |
| 70 | + // } |
| 71 | + |
58 | 72 | @Test |
59 | 73 | public void getSalaryTest() { |
60 | | - employeeTest.getSalary(); |
61 | | - } |
| 74 | + double expectedSalary = employee.getSalary(); |
62 | 75 |
|
63 | | - @Test |
64 | | - public void setSalaryTest() { |
65 | | - employeeTest.setSalary(); |
| 76 | + double actualSalary = 200000.00; |
| 77 | + |
| 78 | + assertEquals(expectedSalary, actualSalary); |
66 | 79 | } |
67 | 80 |
|
| 81 | + // @Test |
| 82 | + // public void setSalaryTest() { |
| 83 | + // employee.setSalary(); |
| 84 | + // } |
| 85 | + |
68 | 86 | private void getId() { |
69 | 87 | throw new UnsupportedOperationException("Not supported yet."); |
70 | 88 | } |
|
0 commit comments