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:
@@ -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<>();
|
||||
|
||||
Reference in New Issue
Block a user