org.junit.platform.engine.TestDescriptor Java Examples

The following examples show how to use org.junit.platform.engine.TestDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestClassExecutor.java    From webtester2-core with Apache License 2.0 6 votes vote down vote up
public static void execute(Class<?> testClass) throws Exception {
    try {

        JupiterTestEngine engine = new JupiterTestEngine();

        TestClassEngineDiscoveryRequest discoveryRequest = new TestClassEngineDiscoveryRequest(testClass);
        TestDescriptor testDescriptor = engine.discover(discoveryRequest, UniqueId.forEngine("foo-bar"));

        EngineExecutionListener listener = new NoOpEngineExecutionListener();
        ConfigurationParameters parameters = new NoConfigurationParameters();
        engine.execute(new ExecutionRequest(testDescriptor, listener, parameters));

    } catch (UndeclaredThrowableException e) {
        Throwable cause = getFirstNonUndeclaredThrowableCause(e);
        if (cause instanceof Error) {
            throw ( Error ) cause;
        } else if (cause instanceof RuntimeException) {
            throw ( RuntimeException ) cause;
        } else if (cause instanceof Exception) {
            throw ( Exception ) cause;
        } else {
            throw e;
        }
    }
}
 
Example #2
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void subpackages() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withPackage(SimpleRuleLibrary.class.getPackage().getName())
            .withClassNameFilter(excludeClassNamePatterns(".*(W|w)rong.*"));

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(toUniqueIds(rootDescriptor))
            .as("tests discovered by " + PackageSelector.class.getSimpleName())
            .contains(
                    engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleLibrary.class.getName()),
                    simpleRulesId(engineId));

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("children discovered by " + PackageSelector.class.getSimpleName())
            .contains(
                    simpleRulesInLibraryId(engineId).append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME),
                    simpleRuleFieldTestId(engineId),
                    simpleRuleMethodTestId(engineId));
}
 
Example #3
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void a_class_with_simple_hierarchy__class_source() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(SimpleRuleLibrary.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    assertClassSource(getOnlyElement(descriptor.getChildren()), SimpleRuleLibrary.class);

    List<TestDescriptor> archRulesDescriptors = getArchRulesDescriptorsOfOnlyChild(descriptor).collect(toList());

    TestDescriptor testDescriptor = findRulesDescriptor(archRulesDescriptors, SimpleRules.class);
    assertClassSource(testDescriptor, SimpleRules.class);
    testDescriptor.getChildren().forEach(d ->
            assertThat(d.getSource().isPresent()).as("source is present").isTrue());

    testDescriptor = findRulesDescriptor(archRulesDescriptors, SimpleRuleField.class);
    assertClassSource(testDescriptor, SimpleRuleField.class);
    testDescriptor.getChildren().forEach(d ->
            assertThat(d.getSource().isPresent()).as("source is present").isTrue());
}
 
Example #4
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void mixed_class_methods_and_fields() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withField(SimpleRuleField.class, SimpleRuleField.SIMPLE_RULE_FIELD_NAME)
            .withMethod(SimpleRuleMethod.class, SimpleRuleMethod.SIMPLE_RULE_METHOD_NAME)
            .withClass(SimpleRules.class);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    Set<UniqueId> expectedLeafIds = new HashSet<>();
    expectedLeafIds.add(simpleRuleFieldTestId(engineId));
    expectedLeafIds.add(simpleRuleMethodTestId(engineId));
    Stream.concat(
            SimpleRules.RULE_FIELD_NAMES.stream().map(fieldName ->
                    simpleRulesId(engineId).append(FIELD_SEGMENT_TYPE, fieldName)),
            SimpleRules.RULE_METHOD_NAMES.stream().map(methodName ->
                    simpleRulesId(engineId).append(METHOD_SEGMENT_TYPE, methodName)))
            .forEach(expectedLeafIds::add);

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("children discovered by mixed selectors")
            .containsOnlyElementsOf(expectedLeafIds);
}
 
Example #5
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void filtering_excluded_packages() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withPackage(SimpleRuleLibrary.class.getPackage().getName())
            .withPackageNameFilter(excludePackageNames(
                    SimpleRuleField.class.getPackage().getName(),
                    SimpleRules.class.getPackage().getName(),
                    WrongRuleMethodNotStatic.class.getPackage().getName()));

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(toUniqueIds(rootDescriptor))
            .contains(engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleLibrary.class.getName()))
            .doesNotContain(
                    engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleField.class.getName()),
                    engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleMethod.class.getName()),
                    simpleRulesId(engineId));
}
 
Example #6
Source File: TestFilter.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FilterResult apply(TestDescriptor object) {

    final UniqueId id = object.getUniqueId();
    return alreadyTestedIds.computeIfAbsent(id, key -> {

        final Optional<String> testName = toTestName(object);
        final FilterResult result = testName.map(this::findMatchingResult)
                .orElse(included("Not a leaf descriptor"));

        if (result.excluded()) {
            final String reason = result.getReason().orElse("");
            eventDispatcher.executionFiltered(object, reason);
        }

        return result;
    });
}
 
Example #7
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void no_redundant_library_descriptors() {
    UniqueId simpleRulesId = simpleRulesInLibraryId(engineId);
    UniqueId ruleIdOne = simpleRulesId.append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    UniqueId ruleIdTwo = simpleRulesId.append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_TWO_NAME);
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withUniqueId(ruleIdOne)
            .withUniqueId(ruleIdTwo);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor simpleRules = getArchRulesDescriptorsOfOnlyChild(rootDescriptor).collect(onlyElement());

    assertThat(toUniqueIds(simpleRules))
            .as("ids of requested children of " + SimpleRules.class.getSimpleName())
            .containsOnly(ruleIdOne, ruleIdTwo);
}
 
Example #8
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void no_redundant_descriptors() {
    UniqueId redundantId = simpleRulesId(engineId)
            .append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withClass(SimpleRules.class)
            .withUniqueId(redundantId);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor test = getOnlyElement(rootDescriptor.getChildren());
    assertThat(test.getChildren()).as("all children of test").hasSize(4);
    List<TestDescriptor> descriptorsWithSpecifiedId = test.getChildren().stream()
            .filter(descriptor -> descriptor.getUniqueId().equals(redundantId))
            .collect(toList());
    assertThat(descriptorsWithSpecifiedId)
            .as("descriptors with id " + redundantId)
            .hasSize(1);
}
 
Example #9
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void meta_tags_of_test_classes() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(TestClassWithMetaTags.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor testClass = getOnlyElement(descriptor.getChildren());
    assertThat(testClass.getTags()).containsOnly(TestTag.create("meta-tags-one"), TestTag.create("meta-tags-two"));

    Set<? extends TestDescriptor> concreteRules = getAllLeafs(testClass);
    assertThat(concreteRules).as("concrete rules").hasSize(3);
    concreteRules.forEach(concreteRule ->
            assertThat(concreteRule.getTags()).containsOnly(TestTag.create("meta-tags-one"), TestTag.create("meta-tags-two"))
    );
}
 
Example #10
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private Set<? extends TestDescriptor> getAllLeafs(TestDescriptor descriptor) {
    Set<TestDescriptor> result = new HashSet<>();
    descriptor.accept(possibleLeaf -> {
        if (possibleLeaf.getChildren().isEmpty()) {
            result.add(possibleLeaf);
        }
    });
    return result;
}
 
Example #11
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private TestDescriptor getOnlyChildWithDescriptorContaining(String idPart, Class<?> testClass) {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(testClass);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    return getArchRulesDescriptorsOfOnlyChild(descriptor)
            .filter(d -> d.getUniqueId().toString().contains(idPart))
            .collect(onlyElement());
}
 
Example #12
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void all_without_filters() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withClasspathRoot(uriOfClass(SimpleRuleField.class))
            .withClasspathRoot(uriOfClass(SimpleRules.class));

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(toUniqueIds(rootDescriptor)).containsOnly(
            engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleField.class.getName()),
            simpleRulesId(engineId));
}
 
Example #13
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void filtering_included_packages() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withPackage(SimpleRuleLibrary.class.getPackage().getName())
            .withPackageNameFilter(includePackageNames(
                    SimpleRuleField.class.getPackage().getName(),
                    SimpleRules.class.getPackage().getName()));

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(toUniqueIds(rootDescriptor)).containsOnly(
            engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleField.class.getName()),
            engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleMethod.class.getName()),
            simpleRulesId(engineId));
}
 
Example #14
Source File: JupiterTestEngineForTests.java    From junit5-docker with Apache License 2.0 5 votes vote down vote up
private JupiterExecutionListener executeTests(LauncherDiscoveryRequest request) throws Exception {
    TestDescriptor testDescriptor = createTestDescriptorForCucumber(
        engine.discover(request, forEngine(engine.getId())), containers);
    eventRecorder.reset();
    engine.execute(new ExecutionRequest(testDescriptor, eventRecorder, request.getConfigurationParameters()));
    return eventRecorder;
}
 
Example #15
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void packages() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withPackage(SimpleRuleField.class.getPackage().getName())
            .withPackage(SimpleRules.class.getPackage().getName());

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(toUniqueIds(rootDescriptor))
            .as("tests discovered by " + PackageSelector.class.getSimpleName())
            .containsOnly(
                    engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleField.class.getName()),
                    engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleMethod.class.getName()),
                    simpleRulesId(engineId));
}
 
Example #16
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void fields() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withField(SimpleRuleField.class, SimpleRuleField.SIMPLE_RULE_FIELD_NAME)
            .withField(SimpleRules.class, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("children discovered by " + FieldSelector.class.getSimpleName())
            .containsOnly(
                    simpleRuleFieldTestId(engineId),
                    simpleRulesId(engineId)
                            .append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME));
}
 
Example #17
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void tags_of_test_classes() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(TestClassWithTags.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor testClass = getOnlyElement(descriptor.getChildren());
    assertThat(testClass.getTags()).containsOnly(TestTag.create("tag-one"), TestTag.create("tag-two"));

    Set<? extends TestDescriptor> concreteRules = getAllLeafs(testClass);
    assertThat(concreteRules).as("concrete rules").hasSize(3);
    concreteRules.forEach(concreteRule ->
            assertThat(concreteRule.getTags()).containsOnly(TestTag.create("tag-one"), TestTag.create("tag-two"))
    );
}
 
Example #18
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void meta_tag_of_test_classes() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(TestClassWithMetaTag.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor testClass = getOnlyElement(descriptor.getChildren());
    assertThat(testClass.getTags()).containsOnly(TestTag.create("meta-tag-one"), TestTag.create("meta-tag-two"));

    Set<? extends TestDescriptor> concreteRules = getAllLeafs(testClass);
    assertThat(concreteRules).as("concrete rules").hasSize(3);
    concreteRules.forEach(concreteRule ->
            assertThat(concreteRule.getTags()).containsOnly(TestTag.create("meta-tag-one"), TestTag.create("meta-tag-two"))
    );
}
 
Example #19
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void methods() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withMethod(SimpleRuleMethod.class, SimpleRuleMethod.SIMPLE_RULE_METHOD_NAME)
            .withMethod(SimpleRules.class, SimpleRules.SIMPLE_RULE_METHOD_ONE_NAME);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("children discovered by " + MethodSelector.class.getSimpleName())
            .containsOnly(
                    simpleRuleMethodTestId(engineId),
                    simpleRulesId(engineId)
                            .append(METHOD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_METHOD_ONE_NAME));
}
 
Example #20
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private EngineExecutionTestListener execute(UniqueId uniqueId, EngineDiscoveryTestRequest discoveryRequest) {
    TestDescriptor descriptor = testEngine.discover(discoveryRequest, uniqueId);

    EngineExecutionTestListener listener = new EngineExecutionTestListener();
    testEngine.execute(new ExecutionRequest(descriptor, listener, discoveryRequest.getConfigurationParameters()));
    return listener;
}
 
Example #21
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void filtering_excluded_class_names() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withClasspathRoot(uriOfClass(SimpleRuleField.class))
            .withClasspathRoot(uriOfClass(SimpleRuleMethod.class))
            .withClasspathRoot(uriOfClass(SimpleRules.class))
            .withClasspathRoot(uriOfClass(SimpleRuleLibrary.class))
            .withClassNameFilter(excludeClassNamePatterns(".*(Field|Rules).*"));

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(toUniqueIds(rootDescriptor)).containsOnly(
            engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleMethod.class.getName()),
            engineId.append(CLASS_SEGMENT_TYPE, SimpleRuleLibrary.class.getName()));
}
 
Example #22
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void a_class_with_simple_hierarchy__descriptor_types() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(SimpleRuleLibrary.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    Stream<TestDescriptor> archRulesDescriptors = getArchRulesDescriptorsOfOnlyChild(descriptor);
    boolean allAreContainer = archRulesDescriptors.allMatch(d -> d.getType().equals(CONTAINER));
    assertThat(allAreContainer).as("all rules descriptor have type " + CONTAINER).isTrue();
}
 
Example #23
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void classpath_roots() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withClasspathRoot(rootOfClass(Test.class))
            .withClasspathRoot(rootOfClass(SimpleRules.class))
            .withClassNameFilter(excludeClassNamePatterns(".*(W|w)rong.*"));

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("children discovered by " + ClasspathRootSelector.class.getSimpleName())
            .contains(simpleRulesInLibraryId(engineId).append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME))
            .contains(simpleRuleFieldTestId(engineId))
            .contains(simpleRuleMethodTestId(engineId));
}
 
Example #24
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void multiple_unique_ids() {
    UniqueId testId = simpleRulesId(engineId);
    UniqueId firstRuleIdToDiscover = testId.append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    UniqueId secondRuleIdToDiscover = testId.append(METHOD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_METHOD_ONE_NAME);
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest()
            .withUniqueId(firstRuleIdToDiscover)
            .withUniqueId(secondRuleIdToDiscover);

    TestDescriptor test = getOnlyElement(testEngine.discover(discoveryRequest, engineId).getChildren());

    Set<UniqueId> discoveredRuleIds = toUniqueIds(test);
    assertThat(discoveredRuleIds).containsOnly(firstRuleIdToDiscover, secondRuleIdToDiscover);
}
 
Example #25
Source File: TestDescriptorForCucumber.java    From junit5-docker with Apache License 2.0 5 votes vote down vote up
private TestDescriptor wrapDescriptorForCucumber() {
    TestDescriptor usedDescriptor = this.testDescriptor;
    if (testDescriptor instanceof TestMethodTestDescriptor) {
        usedDescriptor =
            new MethodTestDescriptorForCucumber((TestMethodTestDescriptor) testDescriptor, containers);
    }
    if (testDescriptor instanceof ClassTestDescriptor) {
        usedDescriptor =
            new ClassTestDescriptorForCucumber((ClassTestDescriptor) testDescriptor, containers);
    }
    return usedDescriptor;
}
 
Example #26
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void private_instance_libraries() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(LibraryWithPrivateTests.class);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("all leaf unique ids of private members")
            .containsOnlyElementsOf(privateRuleLibraryIds(engineId));
}
 
Example #27
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void private_instance_members() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(ClassWithPrivateTests.class);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("all leaf unique ids of private members")
            .containsOnly(privateRuleFieldId(engineId), privateRuleMethodId(engineId));
}
 
Example #28
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void a_class_with_complex_hierarchy() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(ComplexRuleLibrary.class);

    TestDescriptor rootDescriptor = testEngine.discover(discoveryRequest, engineId);

    assertThat(getAllLeafUniqueIds(rootDescriptor))
            .as("all leaf unique ids of complex hierarchy")
            .containsOnlyElementsOf(getExpectedIdsForComplexRuleLibrary(engineId));
}
 
Example #29
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void a_class_with_simple_hierarchy__uniqueIds() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(SimpleRuleLibrary.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    Stream<TestDescriptor> archRulesDescriptors = getArchRulesDescriptorsOfOnlyChild(descriptor);

    Set<UniqueId> expectedIds = getExpectedIdsForSimpleRuleLibrary(engineId);
    Set<UniqueId> actualIds = archRulesDescriptors.flatMap(d -> d.getChildren().stream())
            .map(TestDescriptor::getUniqueId).collect(toSet());
    assertThat(actualIds).isEqualTo(expectedIds);
}
 
Example #30
Source File: MyCustomEngine.java    From mastering-junit5 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ExecutionRequest request) {
    // Use ExecutionRequest to execute TestDescriptor
    TestDescriptor rootTestDescriptor = request.getRootTestDescriptor();
    request.getEngineExecutionListener()
            .executionStarted(rootTestDescriptor);
}