commit
a8f3ef312b
|
@ -1 +0,0 @@
|
||||||
/bin/
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.baeldung.modulo;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.assertj.core.api.Java6Assertions.*;
|
||||||
|
|
||||||
|
public class ModuloUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenIntegerDivision_thenLosesRemainder(){
|
||||||
|
assertThat(11 / 4).isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenDoubleDivision_thenKeepsRemainder(){
|
||||||
|
assertThat(11 / 4.0).isEqualTo(2.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenModulo_thenReturnsRemainder(){
|
||||||
|
assertThat(11 % 4).isEqualTo(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ArithmeticException.class)
|
||||||
|
public void whenDivisionByZero_thenArithmeticException(){
|
||||||
|
double result = 1 / 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ArithmeticException.class)
|
||||||
|
public void whenModuloByZero_thenArithmeticException(){
|
||||||
|
double result = 1 % 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenDivisorIsOddAndModulusIs2_thenResultIs1(){
|
||||||
|
assertThat(3 % 2).isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenDivisorIsEvenAndModulusIs2_thenResultIs0(){
|
||||||
|
assertThat(4 % 2).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenItemsIsAddedToCircularQueue_thenNoArrayIndexOutOfBounds(){
|
||||||
|
int QUEUE_CAPACITY= 10;
|
||||||
|
int[] circularQueue = new int[QUEUE_CAPACITY];
|
||||||
|
int itemsInserted = 0;
|
||||||
|
for (int value = 0; value < 1000; value++) {
|
||||||
|
int writeIndex = ++itemsInserted % QUEUE_CAPACITY;
|
||||||
|
circularQueue[writeIndex] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue