removed unnecessary Mockito and refactored test method name

This commit is contained in:
Tom Hombergs 2018-10-15 21:40:00 +02:00
parent a513308b4d
commit eeb5e0892b

View File

@ -1,4 +1,4 @@
package findItems; package com.baeldung.findItems;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -10,24 +10,20 @@ import java.util.stream.Collectors;
import org.junit.Test; import org.junit.Test;
public class FindItemsBasedOnValues { public class FindItemsBasedOnOtherStreamUnitTest {
List<Employee> EmplList = new ArrayList<Employee>(); private List<Employee> employeeList = new ArrayList<Employee>();
List<Department> deptList = new ArrayList<Department>();
public static void main(String[] args) throws ParseException { private List<Department> departmentList = new ArrayList<Department>();
FindItemsBasedOnValues findItems = new FindItemsBasedOnValues();
findItems.givenDepartmentList_thenEmployeeListIsFilteredCorrectly();
}
@Test @Test
public void givenDepartmentList_thenEmployeeListIsFilteredCorrectly() { public void givenDepartmentList_thenEmployeeListIsFilteredCorrectly() {
Integer expectedId = 1002; Integer expectedId = 1002;
populate(EmplList, deptList); populate(employeeList, departmentList);
List<Employee> filteredList = EmplList.stream() List<Employee> filteredList = employeeList.stream()
.filter(empl -> deptList.stream() .filter(empl -> departmentList.stream()
.anyMatch(dept -> dept.getDepartment() .anyMatch(dept -> dept.getDepartment()
.equals("sales") && empl.getEmployeeId() .equals("sales") && empl.getEmployeeId()
.equals(dept.getEmployeeId()))) .equals(dept.getEmployeeId())))
@ -53,16 +49,16 @@ public class FindItemsBasedOnValues {
} }
class Employee { class Employee {
Integer employeeId; private Integer employeeId;
String employeeName; private String employeeName;
public Employee(Integer employeeId, String employeeName) { Employee(Integer employeeId, String employeeName) {
super(); super();
this.employeeId = employeeId; this.employeeId = employeeId;
this.employeeName = employeeName; this.employeeName = employeeName;
} }
public Integer getEmployeeId() { Integer getEmployeeId() {
return employeeId; return employeeId;
} }
@ -73,20 +69,20 @@ class Employee {
} }
class Department { class Department {
Integer employeeId; private Integer employeeId;
String department; private String department;
public Department(Integer employeeId, String department) { Department(Integer employeeId, String department) {
super(); super();
this.employeeId = employeeId; this.employeeId = employeeId;
this.department = department; this.department = department;
} }
public Integer getEmployeeId() { Integer getEmployeeId() {
return employeeId; return employeeId;
} }
public String getDepartment() { String getDepartment() {
return department; return department;
} }