Search in sources :

Example 1 with Employee

use of com.baeldung.helpers.Employee in project tutorials by eugenp.

the class DynamicTestsExample method dynamicTestsForEmployeeWorkflows.

@TestFactory
Stream<DynamicTest> dynamicTestsForEmployeeWorkflows() {
    List<Employee> inputList = Arrays.asList(new Employee(1, "Fred"), new Employee(2), new Employee(3, "John"));
    EmployeeDao dao = new EmployeeDao();
    Stream<DynamicTest> saveEmployeeStream = inputList.stream().map(emp -> DynamicTest.dynamicTest("saveEmployee: " + emp.toString(), () -> {
        Employee returned = dao.save(emp.getId());
        assertEquals(returned.getId(), emp.getId());
    }));
    Stream<DynamicTest> saveEmployeeWithFirstNameStream = inputList.stream().filter(emp -> !emp.getFirstName().isEmpty()).map(emp -> DynamicTest.dynamicTest("saveEmployeeWithName" + emp.toString(), () -> {
        Employee returned = dao.save(emp.getId(), emp.getFirstName());
        assertEquals(returned.getId(), emp.getId());
        assertEquals(returned.getFirstName(), emp.getFirstName());
    }));
    return Stream.concat(saveEmployeeStream, saveEmployeeWithFirstNameStream);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TestFactory(org.junit.jupiter.api.TestFactory) Iterator(java.util.Iterator) Collection(java.util.Collection) HashMap(java.util.HashMap) Function(java.util.function.Function) List(java.util.List) Employee(com.baeldung.helpers.Employee) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) DynamicTest(org.junit.jupiter.api.DynamicTest) EmployeeDao(com.baeldung.helpers.EmployeeDao) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ThrowingConsumer(org.junit.jupiter.api.function.ThrowingConsumer) EmployeeDao(com.baeldung.helpers.EmployeeDao) Employee(com.baeldung.helpers.Employee) DynamicTest(org.junit.jupiter.api.DynamicTest) TestFactory(org.junit.jupiter.api.TestFactory)

Example 2 with Employee

use of com.baeldung.helpers.Employee in project tutorials by eugenp.

the class EmployeesTest method whenAddEmployee_thenGetEmployee.

@Test
public void whenAddEmployee_thenGetEmployee() throws SQLException {
    Employee emp = new Employee(1, "john");
    employeeDao.add(emp);
    assertEquals(1, employeeDao.findAll().size());
}
Also used : Employee(com.baeldung.helpers.Employee) Test(org.junit.jupiter.api.Test)

Aggregations

Employee (com.baeldung.helpers.Employee)2 EmployeeDao (com.baeldung.helpers.EmployeeDao)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 DynamicTest (org.junit.jupiter.api.DynamicTest)1 Test (org.junit.jupiter.api.Test)1 TestFactory (org.junit.jupiter.api.TestFactory)1 ThrowingConsumer (org.junit.jupiter.api.function.ThrowingConsumer)1