Skip to content

Commit 2bd7f86

Browse files
committed
feat: Adds Unit Tests Project & Employee Class implementations
1 parent 50680f2 commit 2bd7f86

File tree

2 files changed

+135
-46
lines changed

2 files changed

+135
-46
lines changed
Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,35 @@
11
package com.codedifferently.lesson15;
22

3-
public class Employee {
4-
private int id;
5-
private String name;
6-
private String department;
7-
private double salary;
8-
9-
public Employee(int id, String name, String department, double salary) {
10-
this.id = id;
11-
this.name = name;
12-
this.department = department;
13-
this.salary = salary;
14-
}
15-
16-
// Getters and setters
17-
public int getId() {
18-
return id;
19-
}
20-
21-
public void setId(int id) {
22-
this.id = id;
23-
}
24-
25-
public String getName() {
26-
return name;
27-
}
3+
import com.google.common.annotations.VisibleForTesting;
284

29-
public void setName(String name) {
30-
this.name = name;
31-
}
32-
33-
public String getDepartment() {
34-
return department;
35-
}
36-
37-
public void setDepartment(String department) {
38-
this.department = department;
39-
}
40-
41-
public double getSalary() {
42-
return salary;
43-
}
44-
45-
public void setSalary(double salary) {
46-
this.salary = salary;
5+
public class Employee {
6+
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;
4734
}
4835
}

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

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codedifferently.lesson15;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
45

56
import org.junit.jupiter.api.Test;
67

@@ -12,8 +13,109 @@ public void testLesson15() {
1213
}
1314

1415
@Test
15-
public void testGetGreeting() {
16-
// Act
17-
Lesson15.main(null);
16+
public void employee_getID() {
17+
// Arrange
18+
int expectID = 12345;
19+
Employee employee = new Employee(expectID, null, null, 0);
20+
21+
// Act
22+
int actualID = employee.getId();
23+
24+
// Assert
25+
assertEquals(expectID, actualID);
1826
}
27+
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();
36+
37+
// Assert
38+
assertEquals(expectID, actualID);
39+
40+
}
41+
42+
@Test
43+
public void getName() {
44+
// Arrange
45+
Employee employee = new Employee(12345, "Will Smith", null, 100000);
46+
47+
// Act
48+
String expected = "Will Smith";
49+
50+
// Assert
51+
String actual = employee.getName();
52+
assertEquals(expected, actual);
53+
}
54+
55+
@Test
56+
public void setName() {
57+
//Arrange
58+
Employee employee = new Employee(12345, "Will Smith", null, 100000);
59+
60+
// Act
61+
String expected = "Will Smith";
62+
63+
// Assert
64+
String actual = employee.getName();
65+
assertEquals(expected, actual);
1966
}
67+
68+
@Test
69+
public void getDepartment() {
70+
//Arrange
71+
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
72+
73+
// Act
74+
String expected = "Producing";
75+
76+
//Assert
77+
String actual = employee.getDepartment();
78+
assertEquals(expected, actual);
79+
}
80+
81+
@Test
82+
public void setDepartment() {
83+
//Arrange
84+
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);
85+
86+
// Act
87+
String expected = "Producing";
88+
89+
// Assert
90+
String actual = employee.getDepartment();
91+
assertEquals(expected, actual);
92+
}
93+
94+
@Test
95+
public void getSalary() {
96+
// Arrange
97+
Employee employee = new Employee(12345, "Will Smith", "Producing", 50000);
98+
99+
// Act
100+
Short actual = null;
101+
Short expected = null;
102+
103+
// Assert
104+
assertEquals(expected, actual);
105+
}
106+
107+
@Test
108+
public void setSalary(double salary) {
109+
//Arrange
110+
Employee employee = new Employee(12345, "Will Smith", "Producing", 100000);
111+
112+
// Act
113+
int actualId = employee.setSalary();
114+
115+
Short expected = null;
116+
Short actual = null;
117+
// Assert
118+
assertEquals(expected, actual);
119+
}
120+
121+
}

0 commit comments

Comments
 (0)