Skip to content

Commit c227af5

Browse files
committed
Add two tests.
1 parent 9b20d73 commit c227af5

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

exercises/concept/tim-from-marketing-2/.meta/src/reference/java/Employee.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ public String getDepartment() {
2929

3030
@Override
3131
public boolean equals(Object o) {
32-
if (this == o)
32+
if (this == o) {
3333
return true;
34-
if (o == null || getClass() != o.getClass())
34+
}
35+
if (o == null || getClass() != o.getClass()) {
3536
return false;
37+
}
3638
Employee employee = (Employee) o;
3739
return id == employee.id && Objects.equals(name, employee.name)
3840
&& Objects.equals(department, employee.department);

exercises/concept/tim-from-marketing-2/.meta/src/reference/java/EmployeeDatabase.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ public String getEmployeeDetailsById(int employeeId) {
2626
nullableEmployee.ifPresentOrElse(
2727
employee1 -> {
2828
Optional.ofNullable(employee1.getName())
29-
.ifPresentOrElse(name -> stringBuilder.append(employeeId).append(" - ")
30-
.append(employee1.getName()).append(" - ")
31-
.append(employee1.getDepartment()),
32-
() -> {
33-
stringBuilder.append("No employee found for id: ").append(employeeId);
34-
});
29+
.ifPresentOrElse(name -> stringBuilder
30+
.append(employeeId).append(" - ")
31+
.append(employee1.getName()).append(" - ")
32+
.append(employee1.getDepartment()),
33+
() -> {
34+
stringBuilder.append("No employee found for id: ").append(employeeId);
35+
});
3536
},
3637
() -> {
3738
stringBuilder.append("That id does not exist: ").append(employeeId);

exercises/concept/tim-from-marketing-2/src/test/java/EmployeeDatabaseTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ void initList() {
1818
listOfEmployees.add(new Employee(2, "Joe", "Sales"));
1919
listOfEmployees.add(new Employee(3, "Jane", "IT"));
2020
listOfEmployees.add(new Employee(4, null, null));
21+
listOfEmployees.add(new Employee(5, null, "IT"));
22+
listOfEmployees.add(new Employee(6, "Alice", null));
2123
}
2224

2325
@BeforeEach
@@ -76,9 +78,25 @@ void retrieveEmployeeDetailsById_withNullFields() {
7678

7779
@Test
7880
@Tag("task:7")
81+
@DisplayName("Retrieve employee details by id when name is null and department is not null")
82+
void retrieveEmployeeDetailsById_whenNameIsNull() {
83+
assertThat(employeeDatabase.getEmployeeDetailsById(5))
84+
.isEqualTo("No employee found for id: 5");
85+
}
86+
87+
@Test
88+
@Tag("task:8")
89+
@DisplayName("Retrieve employee details by id when department is null and name is not null")
90+
void retrieveEmployeeDetailsById_whenDepartmentIsNull() {
91+
assertThat(employeeDatabase.getEmployeeDetailsById(6))
92+
.isEqualTo("No employee found for id: 6");
93+
}
94+
95+
@Test
96+
@Tag("task:9")
7997
@DisplayName("Retrieve employee details by id when the id does not exist")
8098
void retrieveEmployeeDetailsById_forANonExistingId() {
81-
assertThat(employeeDatabase.getEmployeeDetailsById(7))
82-
.isEqualTo("No employee found for id: 7");
99+
assertThat(employeeDatabase.getEmployeeDetailsById(10))
100+
.isEqualTo("No employee found for id: 10");
83101
}
84102
}

0 commit comments

Comments
 (0)