removed unnecessary Mockito and refactored test method name
This commit is contained in:
parent
a513308b4d
commit
eeb5e0892b
@ -1,93 +1,89 @@
|
|||||||
package findItems;
|
package com.baeldung.findItems;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
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>();
|
|
||||||
|
private List<Department> departmentList = new ArrayList<Department>();
|
||||||
public static void main(String[] args) throws ParseException {
|
|
||||||
FindItemsBasedOnValues findItems = new FindItemsBasedOnValues();
|
@Test
|
||||||
findItems.givenDepartmentList_thenEmployeeListIsFilteredCorrectly();
|
public void givenDepartmentList_thenEmployeeListIsFilteredCorrectly() {
|
||||||
}
|
Integer expectedId = 1002;
|
||||||
|
|
||||||
@Test
|
populate(employeeList, departmentList);
|
||||||
public void givenDepartmentList_thenEmployeeListIsFilteredCorrectly() {
|
|
||||||
Integer expectedId = 1002;
|
List<Employee> filteredList = employeeList.stream()
|
||||||
|
.filter(empl -> departmentList.stream()
|
||||||
populate(EmplList, deptList);
|
.anyMatch(dept -> dept.getDepartment()
|
||||||
|
.equals("sales") && empl.getEmployeeId()
|
||||||
List<Employee> filteredList = EmplList.stream()
|
.equals(dept.getEmployeeId())))
|
||||||
.filter(empl -> deptList.stream()
|
.collect(Collectors.toList());
|
||||||
.anyMatch(dept -> dept.getDepartment()
|
|
||||||
.equals("sales") && empl.getEmployeeId()
|
assertEquals(expectedId, filteredList.get(0)
|
||||||
.equals(dept.getEmployeeId())))
|
.getEmployeeId());
|
||||||
.collect(Collectors.toList());
|
}
|
||||||
|
|
||||||
assertEquals(expectedId, filteredList.get(0)
|
private void populate(List<Employee> EmplList, List<Department> deptList) {
|
||||||
.getEmployeeId());
|
Employee employee1 = new Employee(1001, "empl1");
|
||||||
}
|
Employee employee2 = new Employee(1002, "empl2");
|
||||||
|
Employee employee3 = new Employee(1003, "empl3");
|
||||||
private void populate(List<Employee> EmplList, List<Department> deptList) {
|
|
||||||
Employee employee1 = new Employee(1001, "empl1");
|
Collections.addAll(EmplList, employee1, employee2, employee3);
|
||||||
Employee employee2 = new Employee(1002, "empl2");
|
|
||||||
Employee employee3 = new Employee(1003, "empl3");
|
Department department1 = new Department(1002, "sales");
|
||||||
|
Department department2 = new Department(1003, "marketing");
|
||||||
Collections.addAll(EmplList, employee1, employee2, employee3);
|
Department department3 = new Department(1004, "sales");
|
||||||
|
|
||||||
Department department1 = new Department(1002, "sales");
|
Collections.addAll(deptList, department1, department2, department3);
|
||||||
Department department2 = new Department(1003, "marketing");
|
}
|
||||||
Department department3 = new Department(1004, "sales");
|
}
|
||||||
|
|
||||||
Collections.addAll(deptList, department1, department2, department3);
|
class Employee {
|
||||||
}
|
private Integer employeeId;
|
||||||
}
|
private String employeeName;
|
||||||
|
|
||||||
class Employee {
|
Employee(Integer employeeId, String employeeName) {
|
||||||
Integer employeeId;
|
super();
|
||||||
String employeeName;
|
this.employeeId = employeeId;
|
||||||
|
this.employeeName = employeeName;
|
||||||
public Employee(Integer employeeId, String employeeName) {
|
}
|
||||||
super();
|
|
||||||
this.employeeId = employeeId;
|
Integer getEmployeeId() {
|
||||||
this.employeeName = employeeName;
|
return employeeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getEmployeeId() {
|
public String getEmployeeName() {
|
||||||
return employeeId;
|
return employeeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmployeeName() {
|
}
|
||||||
return employeeName;
|
|
||||||
}
|
class Department {
|
||||||
|
private Integer employeeId;
|
||||||
}
|
private String department;
|
||||||
|
|
||||||
class Department {
|
Department(Integer employeeId, String department) {
|
||||||
Integer employeeId;
|
super();
|
||||||
String department;
|
this.employeeId = employeeId;
|
||||||
|
this.department = department;
|
||||||
public Department(Integer employeeId, String department) {
|
}
|
||||||
super();
|
|
||||||
this.employeeId = employeeId;
|
Integer getEmployeeId() {
|
||||||
this.department = department;
|
return employeeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getEmployeeId() {
|
String getDepartment() {
|
||||||
return employeeId;
|
return department;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDepartment() {
|
|
||||||
return department;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user