Skip to content

Commit ef61b86

Browse files
committed
BAEL-2197:Code rework
1 parent 7070aae commit ef61b86

1 file changed

Lines changed: 47 additions & 68 deletions

File tree

Lines changed: 47 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,93 @@
11
package findItems;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.Assert.assertEquals;
4+
45
import java.text.ParseException;
5-
import java.text.SimpleDateFormat;
66
import java.util.ArrayList;
77
import java.util.Collections;
8-
import java.util.Date;
98
import java.util.List;
109
import java.util.stream.Collectors;
10+
1111
import org.junit.Test;
1212

1313
public class FindItemsBasedOnValues {
1414

15-
static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");
15+
List<Employee> EmplList = new ArrayList<Employee>();
16+
List<Department> deptList = new ArrayList<Department>();
1617

1718
public static void main(String[] args) throws ParseException {
1819
FindItemsBasedOnValues findItems = new FindItemsBasedOnValues();
19-
findItems.givenListOfCompanies_thenListOfClientsIsFilteredCorrectly();
20+
findItems.givenDepartmentList_thenEmployeeListIsFilteredCorrectly();
2021
}
2122

2223
@Test
23-
public void givenListOfCompanies_thenListOfClientsIsFilteredCorrectly() throws ParseException {
24-
List<Client> expectedList = new ArrayList<Client>();
25-
Client expectedClient = new Client(1001, DATE_FORMAT.parse("01-02-2018"));
26-
expectedList.add(expectedClient);
27-
28-
List<Company> listOfCompanies = new ArrayList<Company>();
29-
List<Client> listOfClients = new ArrayList<Client>();
30-
populate(listOfCompanies, listOfClients);
31-
32-
List<Client> filteredList = listOfClients.stream()
33-
.filter(client -> listOfCompanies.stream()
34-
.anyMatch(company -> company.getType()
35-
.equals("eMart") && company.getProjectId()
36-
.equals(client.getProjectId()) && company.getStart()
37-
.after(client.getDate()) && company.getEnd()
38-
.before(client.getDate())))
24+
public void givenDepartmentList_thenEmployeeListIsFilteredCorrectly() {
25+
Integer expectedId = 1002;
26+
27+
populate(EmplList, deptList);
28+
29+
List<Employee> filteredList = EmplList.stream()
30+
.filter(empl -> deptList.stream()
31+
.anyMatch(dept -> dept.getDepartment()
32+
.equals("sales") && empl.getEmployeeId()
33+
.equals(dept.getEmployeeId())))
3934
.collect(Collectors.toList());
4035

41-
assertEquals(expectedClient.getProjectId(), filteredList.get(0)
42-
.getProjectId());
43-
assertEquals(expectedClient.getDate(), filteredList.get(0)
44-
.getDate());
36+
assertEquals(expectedId, filteredList.get(0)
37+
.getEmployeeId());
4538
}
4639

47-
private void populate(List<Company> companyList, List<Client> clientList) throws ParseException {
48-
Company company1 = new Company(1001, DATE_FORMAT.parse("01-03-2018"), DATE_FORMAT.parse("01-01-2018"), "eMart");
49-
Company company2 = new Company(1002, DATE_FORMAT.parse("01-02-2018"), DATE_FORMAT.parse("01-04-2018"), "commerce");
50-
Company company3 = new Company(1003, DATE_FORMAT.parse("01-06-2018"), DATE_FORMAT.parse("01-02-2018"), "eMart");
51-
Company company4 = new Company(1004, DATE_FORMAT.parse("01-03-2018"), DATE_FORMAT.parse("01-06-2018"), "blog");
40+
private void populate(List<Employee> EmplList, List<Department> deptList) {
41+
Employee employee1 = new Employee(1001, "empl1");
42+
Employee employee2 = new Employee(1002, "empl2");
43+
Employee employee3 = new Employee(1003, "empl3");
5244

53-
Collections.addAll(companyList, company1, company2, company3, company4);
45+
Collections.addAll(EmplList, employee1, employee2, employee3);
5446

55-
Client client1 = new Client(1001, DATE_FORMAT.parse("01-02-2018"));
56-
Client client2 = new Client(1003, DATE_FORMAT.parse("01-04-2018"));
57-
Client client3 = new Client(1005, DATE_FORMAT.parse("01-07-2018"));
58-
Client client4 = new Client(1007, DATE_FORMAT.parse("01-08-2018"));
47+
Department department1 = new Department(1002, "sales");
48+
Department department2 = new Department(1003, "marketing");
49+
Department department3 = new Department(1004, "sales");
5950

60-
Collections.addAll(clientList, client1, client2, client3, client4);
51+
Collections.addAll(deptList, department1, department2, department3);
6152
}
6253
}
6354

64-
class Company {
65-
Long projectId;
66-
Date start;
67-
Date end;
68-
String type;
55+
class Employee {
56+
Integer employeeId;
57+
String employeeName;
6958

70-
public Company(long projectId, Date start, Date end, String type) {
59+
public Employee(Integer employeeId, String employeeName) {
7160
super();
72-
this.projectId = projectId;
73-
this.start = start;
74-
this.end = end;
75-
this.type = type;
76-
}
77-
78-
public Long getProjectId() {
79-
return projectId;
80-
}
81-
82-
public Date getStart() {
83-
return start;
61+
this.employeeId = employeeId;
62+
this.employeeName = employeeName;
8463
}
8564

86-
public Date getEnd() {
87-
return end;
65+
public Integer getEmployeeId() {
66+
return employeeId;
8867
}
8968

90-
public String getType() {
91-
return type;
69+
public String getEmployeeName() {
70+
return employeeName;
9271
}
9372

9473
}
9574

96-
class Client {
97-
Long projectId;
98-
Date date;
75+
class Department {
76+
Integer employeeId;
77+
String department;
9978

100-
public Client(long projectId, Date date) {
79+
public Department(Integer employeeId, String department) {
10180
super();
102-
this.projectId = projectId;
103-
this.date = date;
81+
this.employeeId = employeeId;
82+
this.department = department;
10483
}
10584

106-
public Long getProjectId() {
107-
return projectId;
85+
public Integer getEmployeeId() {
86+
return employeeId;
10887
}
10988

110-
public Date getDate() {
111-
return date;
89+
public String getDepartment() {
90+
return department;
11291
}
11392

11493
}

0 commit comments

Comments
 (0)