BAEL-900 Guide to dynamic tests in Junit 5 (#1932)

* BAEL-900 Guide to dynamic tests in Junit 5

* BAEL-900 Guide to Dynamic Tests in Junit 5

* Revert "BAEL-900 Guide to Dynamic Tests in Junit 5"

This reverts commit d0d45c9067223347da20d0f2c80de391fcade38e.

* BAEL-900 Guide to Dynamic Tests in Junit 5

* BAEL-900 Guide to dynamic tests in Junit 5

* removed unnecessary annotation

* BAEL-900 unused imports removed
This commit is contained in:
Yasin 2017-05-27 01:47:42 +05:30 committed by maibin
parent 49724d1691
commit b9b642c6a9
3 changed files with 80 additions and 0 deletions

View File

@ -18,6 +18,9 @@ import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.function.ThrowingConsumer;
import com.baeldung.helpers.Employee;
import com.baeldung.helpers.EmployeeDao;
public class DynamicTestsExample {
@TestFactory
@ -111,6 +114,29 @@ public class DynamicTestsExample {
}
@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);
}
class DomainNameResolver {
private Map<String, String> ipByDomainName = new HashMap<>();

View File

@ -0,0 +1,38 @@
package com.baeldung.helpers;
public class Employee {
private long id;
private String firstName;
public Employee(long id) {
this.id = id;
this.firstName = "";
}
public Employee(long id, String firstName) {
this.id = id;
this.firstName = firstName;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Override
public String toString() {
return "Employee [id=" + id + ", firstName=" + firstName + "]";
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.helpers;
public class EmployeeDao {
public Employee save(long id) {
return new Employee(id);
}
public Employee save(long id, String firstName) {
return new Employee(id, firstName);
}
public Employee update(Employee employee) {
return employee;
}
}