From eeb5e0892b759661283d187bb800cdce6d6844a9 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Mon, 15 Oct 2018 21:40:00 +0200 Subject: [PATCH] removed unnecessary Mockito and refactored test method name --- .../FindItemsBasedOnOtherStreamUnitTest.java | 180 +++++++++--------- 1 file changed, 88 insertions(+), 92 deletions(-) rename core-java-8/findItemsBasedOnValues/src/findItems/FindItemsBasedOnValues.java => core-java-collections/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java (63%) diff --git a/core-java-8/findItemsBasedOnValues/src/findItems/FindItemsBasedOnValues.java b/core-java-collections/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java similarity index 63% rename from core-java-8/findItemsBasedOnValues/src/findItems/FindItemsBasedOnValues.java rename to core-java-collections/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java index a0dcdddd85..326ea9fbe4 100644 --- a/core-java-8/findItemsBasedOnValues/src/findItems/FindItemsBasedOnValues.java +++ b/core-java-collections/src/test/java/com/baeldung/findItems/FindItemsBasedOnOtherStreamUnitTest.java @@ -1,93 +1,89 @@ -package findItems; - -import static org.junit.Assert.assertEquals; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import org.junit.Test; - -public class FindItemsBasedOnValues { - - List EmplList = new ArrayList(); - List deptList = new ArrayList(); - - public static void main(String[] args) throws ParseException { - FindItemsBasedOnValues findItems = new FindItemsBasedOnValues(); - findItems.givenDepartmentList_thenEmployeeListIsFilteredCorrectly(); - } - - @Test - public void givenDepartmentList_thenEmployeeListIsFilteredCorrectly() { - Integer expectedId = 1002; - - populate(EmplList, deptList); - - List filteredList = EmplList.stream() - .filter(empl -> deptList.stream() - .anyMatch(dept -> dept.getDepartment() - .equals("sales") && empl.getEmployeeId() - .equals(dept.getEmployeeId()))) - .collect(Collectors.toList()); - - assertEquals(expectedId, filteredList.get(0) - .getEmployeeId()); - } - - private void populate(List EmplList, List deptList) { - Employee employee1 = new Employee(1001, "empl1"); - Employee employee2 = new Employee(1002, "empl2"); - Employee employee3 = new Employee(1003, "empl3"); - - Collections.addAll(EmplList, employee1, employee2, employee3); - - Department department1 = new Department(1002, "sales"); - Department department2 = new Department(1003, "marketing"); - Department department3 = new Department(1004, "sales"); - - Collections.addAll(deptList, department1, department2, department3); - } -} - -class Employee { - Integer employeeId; - String employeeName; - - public Employee(Integer employeeId, String employeeName) { - super(); - this.employeeId = employeeId; - this.employeeName = employeeName; - } - - public Integer getEmployeeId() { - return employeeId; - } - - public String getEmployeeName() { - return employeeName; - } - -} - -class Department { - Integer employeeId; - String department; - - public Department(Integer employeeId, String department) { - super(); - this.employeeId = employeeId; - this.department = department; - } - - public Integer getEmployeeId() { - return employeeId; - } - - public String getDepartment() { - return department; - } - +package com.baeldung.findItems; + +import static org.junit.Assert.assertEquals; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Test; + +public class FindItemsBasedOnOtherStreamUnitTest { + + private List employeeList = new ArrayList(); + + private List departmentList = new ArrayList(); + + @Test + public void givenDepartmentList_thenEmployeeListIsFilteredCorrectly() { + Integer expectedId = 1002; + + populate(employeeList, departmentList); + + List filteredList = employeeList.stream() + .filter(empl -> departmentList.stream() + .anyMatch(dept -> dept.getDepartment() + .equals("sales") && empl.getEmployeeId() + .equals(dept.getEmployeeId()))) + .collect(Collectors.toList()); + + assertEquals(expectedId, filteredList.get(0) + .getEmployeeId()); + } + + private void populate(List EmplList, List deptList) { + Employee employee1 = new Employee(1001, "empl1"); + Employee employee2 = new Employee(1002, "empl2"); + Employee employee3 = new Employee(1003, "empl3"); + + Collections.addAll(EmplList, employee1, employee2, employee3); + + Department department1 = new Department(1002, "sales"); + 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; + + Employee(Integer employeeId, String employeeName) { + super(); + this.employeeId = employeeId; + this.employeeName = employeeName; + } + + Integer getEmployeeId() { + return employeeId; + } + + public String getEmployeeName() { + return employeeName; + } + +} + +class Department { + private Integer employeeId; + private String department; + + Department(Integer employeeId, String department) { + super(); + this.employeeId = employeeId; + this.department = department; + } + + Integer getEmployeeId() { + return employeeId; + } + + String getDepartment() { + return department; + } + } \ No newline at end of file