Skip to content

Commit 06276ae

Browse files
committed
chore: fixed Employee.java & added in EmployeeTest.java
1 parent 2bd7f86 commit 06276ae

File tree

3 files changed

+245
-108
lines changed

3 files changed

+245
-108
lines changed
Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
11
package com.codedifferently.lesson15;
22

3-
import com.google.common.annotations.VisibleForTesting;
3+
44

55
public class Employee {
66
private static final String Details = null;
7-
private int id;
8-
private String name;
9-
private String department;
10-
private double salary;
11-
12-
public Employee(int id, String name, String department, double salary) {
13-
this.id = id;
14-
this.name = name;
15-
this.department = department;
16-
this.salary = salary;
17-
}
18-
19-
public void testGetDetails() {
20-
Employee employee = new Employee(id, "Will Smith", department, 101);
21-
String expected = "Employee Name: Will Smith, id: 101:";
22-
String actual = employee.getDetails();
23-
24-
assertEquals(expected, actual);
25-
}
26-
27-
private void assertEquals(String expected, String actual) {
28-
// TODO Auto-generated method stub
29-
throw new UnsupportedOperationException("Unimplemented method 'assertEquals'");
30-
}
31-
32-
public String getDetails() {
33-
return Details;
7+
private int id;
8+
private String name;
9+
private String department;
10+
private double salary;
11+
12+
public Employee(int id, String name, String department, double salary) {
13+
this.id = id;
14+
this.name = name;
15+
this.department = department;
16+
this.salary = salary;
17+
}
18+
19+
// Getters and setters
20+
public int getId() {
21+
return id;
22+
}
23+
24+
public void setId(int id) {
25+
this.id = id;
26+
}
27+
28+
public String getName() {
29+
return name;
30+
}
31+
32+
public String getDepartment() {
33+
return department;
34+
}
35+
36+
public double setSalary(int id) {
37+
return salary;
38+
}
39+
40+
// public void testGetDetails() {
41+
// Employee employee = new Employee(id, "Will Smith", department, 101);
42+
// String expected = "Employee Name: Will Smith, id: 101:";
43+
// String actual = employee.getDetails();
44+
45+
// assertEquals(expected, actual);
46+
// }
47+
48+
public String getDetails() {
49+
return Details;
3450
}
3551
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 employee_getID() {
11+
// Arrange
12+
int expectID = 12345;
13+
Employee employee = new Employee(expectID, null, null, 0);
14+
15+
// Act
16+
int actualID = employee.getId();
17+
18+
// Assert
19+
assertEquals(expectID, actualID);
20+
}
21+
22+
public void testGetDetails() {
23+
Employee employee = new Employee(id,"Will Smith", 101);
24+
String expected = "Employee Name: Will Smith, id: 101:";
25+
String actual = employee.getDetails();
26+
27+
assertEquals(expected, actual);
28+
}
29+
30+
@Test
31+
public void employee_setID() {
32+
// Arrange
33+
int expectID = 12345;
34+
Employee employee = new Employee(expectID, "Will Smith", "Producing", expectID);
35+
36+
// Act
37+
int actualID = employee.setId();
38+
39+
// Assert
40+
assertEquals(expectID, actualID);
41+
}
42+
43+
@Test
44+
public void getName() {
45+
// Arrange
46+
Employee employee = new Employee(12345, "Will Smith", null, 100000);
47+
48+
// Act
49+
String expected = "Will Smith";
50+
51+
// Assert
52+
String actual = employee.getName();
53+
assertEquals(expected, actual);
54+
}
55+
56+
@Test
57+
public void setName() {
58+
// Arrange
59+
Employee employee = new Employee(12345, "Will Smith", null, 100000);
60+
61+
// Act
62+
String expected = "Will Smith";
63+
64+
// Assert
65+
String actual = employee.getName();
66+
assertEquals(expected, actual);
67+
}
68+
69+
@Test
70+
public void getDepartment() {
71+
// Arrange
72+
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
73+
74+
// Act
75+
String expected = "Producing";
76+
77+
// Assert
78+
String actual = employee.getDepartment();
79+
assertEquals(expected, actual);
80+
}
81+
82+
@Test
83+
public void setDepartment() {
84+
// Arrange
85+
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
86+
87+
// Act
88+
String expected = "Producing";
89+
90+
// Assert
91+
String actual = employee.getDepartment();
92+
assertEquals(expected, actual);
93+
}
94+
95+
@Test
96+
public void getSalary() {
97+
// Arrange
98+
Employee employee = new Employee(12345, "Will Smith", "Producing", 50000);
99+
100+
// Act
101+
Short actual = null;
102+
Short expected = null;
103+
104+
// Assert
105+
assertEquals(expected, actual);
106+
}
107+
108+
@Test
109+
public void setSalary(double salary) {
110+
// Arrange
111+
Employee employee = new Employee(12345, "Will Smith", "Producing", 100000);
112+
113+
// Act
114+
int actualId = employee.setSalary();
115+
116+
Short expected = null;
117+
Short actual = null;
118+
// Assert
119+
assertEquals(expected, actual);
120+
}
121+
}
122+
123+

lesson_15/tdd/tdd_app/src/test/java/com/codedifferently/lesson15/Lesson15Test.java

Lines changed: 78 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -14,108 +14,106 @@ public void testLesson15() {
1414

1515
@Test
1616
public void employee_getID() {
17-
// Arrange
18-
int expectID = 12345;
19-
Employee employee = new Employee(expectID, null, null, 0);
17+
// Arrange
18+
int expectID = 12345;
19+
Employee employee = new Employee(expectID, null, null, 0);
2020

21-
// Act
22-
int actualID = employee.getId();
21+
// Act
22+
int actualID = employee.getId();
2323

24-
// Assert
25-
assertEquals(expectID, actualID);
24+
// Assert
25+
assertEquals(expectID, actualID);
2626
}
2727

28-
@Test
29-
public void employee_setID() {
30-
// Arrange
31-
int expectID = 12345;
32-
Employee employee = new Employee(expectID, "Will Smith", "Producing", expectID);
33-
34-
// Act
35-
int actualID = employee.setID();
28+
@Test
29+
public void employee_setID() {
30+
// Arrange
31+
int expectID = 12345;
32+
Employee employee = new Employee(expectID, "Will Smith", "Producing", expectID);
3633

37-
// Assert
38-
assertEquals(expectID, actualID);
34+
// Act
35+
int actualID = employee.setID();
3936

40-
}
37+
// Assert
38+
assertEquals(expectID, actualID);
39+
}
4140

42-
@Test
43-
public void getName() {
44-
// Arrange
45-
Employee employee = new Employee(12345, "Will Smith", null, 100000);
41+
@Test
42+
public void getName() {
43+
// Arrange
44+
Employee employee = new Employee(12345, "Will Smith", null, 100000);
4645

47-
// Act
48-
String expected = "Will Smith";
46+
// Act
47+
String expected = "Will Smith";
4948

50-
// Assert
51-
String actual = employee.getName();
52-
assertEquals(expected, actual);
53-
}
49+
// Assert
50+
String actual = employee.getName();
51+
assertEquals(expected, actual);
52+
}
5453

55-
@Test
56-
public void setName() {
57-
//Arrange
58-
Employee employee = new Employee(12345, "Will Smith", null, 100000);
54+
@Test
55+
public void setName() {
56+
// Arrange
57+
Employee employee = new Employee(12345, "Will Smith", null, 100000);
5958

60-
// Act
61-
String expected = "Will Smith";
59+
// Act
60+
String expected = "Will Smith";
6261

63-
// Assert
64-
String actual = employee.getName();
65-
assertEquals(expected, actual);
66-
}
62+
// Assert
63+
String actual = employee.getName();
64+
assertEquals(expected, actual);
65+
}
6766

68-
@Test
69-
public void getDepartment() {
70-
//Arrange
71-
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
67+
@Test
68+
public void getDepartment() {
69+
// Arrange
70+
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
7271

73-
// Act
74-
String expected = "Producing";
72+
// Act
73+
String expected = "Producing";
7574

76-
//Assert
77-
String actual = employee.getDepartment();
78-
assertEquals(expected, actual);
79-
}
75+
// Assert
76+
String actual = employee.getDepartment();
77+
assertEquals(expected, actual);
78+
}
8079

81-
@Test
82-
public void setDepartment() {
83-
//Arrange
84-
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
80+
@Test
81+
public void setDepartment() {
82+
// Arrange
83+
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
8584

86-
// Act
87-
String expected = "Producing";
85+
// Act
86+
String expected = "Producing";
8887

89-
// Assert
90-
String actual = employee.getDepartment();
91-
assertEquals(expected, actual);
92-
}
88+
// Assert
89+
String actual = employee.getDepartment();
90+
assertEquals(expected, actual);
91+
}
9392

94-
@Test
95-
public void getSalary() {
96-
// Arrange
97-
Employee employee = new Employee(12345, "Will Smith", "Producing", 50000);
93+
@Test
94+
public void getSalary() {
95+
// Arrange
96+
Employee employee = new Employee(12345, "Will Smith", "Producing", 50000);
9897

99-
// Act
100-
Short actual = null;
101-
Short expected = null;
98+
// Act
99+
Short actual = null;
100+
Short expected = null;
102101

103-
// Assert
104-
assertEquals(expected, actual);
105-
}
102+
// Assert
103+
assertEquals(expected, actual);
104+
}
106105

107-
@Test
108-
public void setSalary(double salary) {
109-
//Arrange
110-
Employee employee = new Employee(12345, "Will Smith", "Producing", 100000);
106+
@Test
107+
public void setSalary(double salary) {
108+
// Arrange
109+
Employee employee = new Employee(12345, "Will Smith", "Producing", 100000);
111110

112-
// Act
113-
int actualId = employee.setSalary();
111+
// Act
112+
int actualId = employee.setSalary();
114113

115-
Short expected = null;
116-
Short actual = null;
117-
// Assert
118-
assertEquals(expected, actual);
114+
Short expected = null;
115+
Short actual = null;
116+
// Assert
117+
assertEquals(expected, actual);
118+
}
119119
}
120-
121-
}

0 commit comments

Comments
 (0)