org.junit.platform.engine.UniqueId Java Examples

The following examples show how to use org.junit.platform.engine.UniqueId. 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: EngineExecutionTestListener.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
void verifyViolation(UniqueId testId, String messagePart) {
    verifyStarted(testId);
    FinishedTest test = finishedTests.stream().filter(result -> result.hasId(testId)).collect(onlyElement());
    assertThat(test.result.getStatus())
            .as("Test status of " + test)
            .isEqualTo(FAILED);
    assertThat(test.result.getThrowable().isPresent())
            .as("Test has thrown Throwable: " + test)
            .isTrue();
    assertThat(test.result.getThrowable().get())
            .as("Test Throwable of " + test)
            .isInstanceOf(AssertionError.class);
    assertThat(test.result.getThrowable().get().getMessage())
            .as("AssertionError message of " + test)
            .containsSequence(messagePart);
}
 
Example #3
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void an_unique_id() {
    UniqueId ruleIdToDiscover = simpleRulesId(engineId)
            .append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withUniqueId(ruleIdToDiscover);

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

    assertThat(descriptor.getUniqueId()).isEqualTo(ruleIdToDiscover);
    assertThat(descriptor.getDisplayName()).isEqualTo(SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    assertThat(descriptor.getChildren()).isEmpty();
    assertThat(descriptor.getDescendants()).isEmpty();
    assertThat(descriptor.getType()).isEqualTo(TEST);
    assertThat(descriptor.getSource().get()).isEqualTo(FieldSource.from(field(SimpleRules.class, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME)));
    assertThat(descriptor.getParent().get().getSource().get()).isEqualTo(ClassSource.from(SimpleRules.class));
}
 
Example #4
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 #5
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 #6
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 #7
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void mixed_rules_by_unique_id_and_class_with_violation() {
    UniqueId fieldRuleInLibrary = simpleRulesInLibraryId(engineId)
            .append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    UniqueId methodRuleInLibrary = simpleRulesInLibraryId(engineId)
            .append(METHOD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_METHOD_ONE_NAME);
    simulateCachedClassesForTest(SimpleRuleLibrary.class, UnwantedClass.CLASS_VIOLATING_RULES);
    simulateCachedClassesForTest(SimpleRuleField.class, UnwantedClass.CLASS_VIOLATING_RULES);

    EngineExecutionTestListener testListener = execute(engineId, new EngineDiscoveryTestRequest()
            .withClass(SimpleRuleField.class)
            .withUniqueId(fieldRuleInLibrary)
            .withUniqueId(methodRuleInLibrary));

    testListener.verifyViolation(simpleRuleFieldTestId(engineId), UnwantedClass.CLASS_VIOLATING_RULES.getSimpleName());
    testListener.verifyViolation(fieldRuleInLibrary, UnwantedClass.CLASS_VIOLATING_RULES.getSimpleName());
    testListener.verifyViolation(methodRuleInLibrary, UnwantedClass.CLASS_VIOLATING_RULES.getSimpleName());
}
 
Example #8
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void library_sub_rules() {
    simulateCachedClassesForTest(IgnoredLibrary.class, UnwantedClass.CLASS_VIOLATING_RULES);

    EngineExecutionTestListener testListener = execute(engineId, IgnoredLibrary.class);

    UniqueId classWithIgnoredMethod = engineId
            .append(CLASS_SEGMENT_TYPE, IgnoredLibrary.class.getName())
            .append(FIELD_SEGMENT_TYPE, IgnoredLibrary.UNIGNORED_LIB_TWO_FIELD)
            .append(CLASS_SEGMENT_TYPE, IgnoredMethod.class.getName());

    testListener.verifySkipped(classWithIgnoredMethod
            .append(METHOD_SEGMENT_TYPE, IgnoredMethod.IGNORED_RULE_METHOD));

    testListener.verifyViolation(classWithIgnoredMethod
            .append(METHOD_SEGMENT_TYPE, IgnoredMethod.UNIGNORED_RULE_METHOD));
}
 
Example #9
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void library_sub_rules() {
    simulateCachedClassesForTest(MetaIgnoredLibrary.class, UnwantedClass.CLASS_VIOLATING_RULES);

    EngineExecutionTestListener testListener = execute(engineId, MetaIgnoredLibrary.class);

    UniqueId classWithIgnoredMethod = engineId
            .append(CLASS_SEGMENT_TYPE, MetaIgnoredLibrary.class.getName())
            .append(FIELD_SEGMENT_TYPE, MetaIgnoredLibrary.UNIGNORED_LIB_TWO_FIELD)
            .append(CLASS_SEGMENT_TYPE, MetaIgnoredMethod.class.getName());

    testListener.verifySkipped(classWithIgnoredMethod
            .append(METHOD_SEGMENT_TYPE, MetaIgnoredMethod.IGNORED_RULE_METHOD));

    testListener.verifyViolation(classWithIgnoredMethod
            .append(METHOD_SEGMENT_TYPE, MetaIgnoredMethod.UNIGNORED_RULE_METHOD));
}
 
Example #10
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 #11
Source File: TaskName.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param id The unique test identifier.
 * @return A string representation of the current invocation (might be {@code null}).
 */
static String invocation(UniqueId id) {

    List<UniqueId.Segment> segments = id.getSegments();

    if (!segments.isEmpty()) {

        UniqueId.Segment last = segments.get(segments.size() - 1);

        switch (last.getType()) {
            case "dynamic-test":
            case "test-template-invocation":
                return last.getValue().replace("#", "");
        }
    }

    return null;
}
 
Example #12
Source File: TaskName.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a task name for the specified {@code identifier}.
 *
 * @param testSuite The name of the test suite.
 * @param identifier The test identifier.
 * @return A task name representing the given identifier.
 */
static TaskName of(String testSuite, TestIdentifier identifier) {

    TaskName result = new TaskName();
    result.fullyQualifiedName = testSuite;

    TestSource testSource = identifier.getSource().orElse(null);

    if (testSource instanceof ClassSource) {

        ClassSource classSource = (ClassSource)testSource;
        result.nestedSuiteId = nestedSuiteId(testSuite, classSource.getClassName());
    }

    if (testSource instanceof MethodSource) {

        MethodSource methodSource = (MethodSource)testSource;
        result.nestedSuiteId = nestedSuiteId(testSuite, methodSource.getClassName());
        result.invocation = invocation(UniqueId.parse(identifier.getUniqueId()));
        result.testName = testName(methodSource.getMethodName(),
                methodSource.getMethodParameterTypes());
    }

    return result;
}
 
Example #13
Source File: Configuration.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
/**
 * @return A formatted display name on success, {@code NULL} if the given
 *  identifier should be ignored.
 */
private String toName(TestIdentifier identifier) {

    String name = identifier.getDisplayName();
    List<Segment> segments = UniqueId.parse(identifier.getUniqueId()).getSegments();

    if (!segments.isEmpty()) {
        Segment lastSegment = segments.get(segments.size() - 1);

        name = VINTAGE_ENGINE.equals(testEngine)
                ? toVintageName(identifier, lastSegment)
                : toName(lastSegment);
    }

    return name;
}
 
Example #14
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private void resolveRequestedPackages(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    String[] packages = discoveryRequest.getSelectorsByType(PackageSelector.class).stream()
            .map(PackageSelector::getPackageName)
            .toArray(String[]::new);
    Stream<JavaClass> classes = getContainedClasses(packages);

    filterCandidatesAndLoadClasses(classes, discoveryRequest)
            .forEach(clazz -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, clazz), cache.get()));
}
 
Example #15
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private Set<UniqueId> getExpectedIdsForSimpleRules(UniqueId append) {
    UniqueId simpleRules = simpleRulesId(append);
    Set<UniqueId> simpleRulesFields = SimpleRules.RULE_FIELD_NAMES.stream().map(fieldName -> simpleRules
            .append(FIELD_SEGMENT_TYPE, fieldName)).collect(toSet());
    Set<UniqueId> simpleRulesMethods = SimpleRules.RULE_METHOD_NAMES.stream().map(methodName -> simpleRules
            .append(METHOD_SEGMENT_TYPE, methodName)).collect(toSet());
    return Stream.of(simpleRulesFields, simpleRulesMethods).flatMap(Set::stream).collect(toSet());
}
 
Example #16
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private void resolveRequestedClasspathRoot(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    Stream<JavaClass> classes = discoveryRequest.getSelectorsByType(ClasspathRootSelector.class).stream()
            .flatMap(this::getContainedClasses);
    filterCandidatesAndLoadClasses(classes, discoveryRequest)
            .forEach(clazz -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, clazz), cache.get()));
}
 
Example #17
Source File: ElementResolver.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@MayResolveTypesViaReflection(reason = "Within the ArchUnitTestEngine we may resolve types via reflection, since they are needed anyway")
private Class<?> classOf(UniqueId.Segment segment) {
    try {
        return Class.forName(segment.getValue());
    } catch (ClassNotFoundException e) {
        throw new ArchTestInitializationException(e, "Failed to load class from %s segment %s",
                UniqueId.class.getSimpleName(), segment);
    }
}
 
Example #18
Source File: ElementResolver.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private static Deque<UniqueId.Segment> getRemainingSegments(UniqueId rootId, UniqueId targetId) {
    Deque<UniqueId.Segment> remainingSegments = new LinkedList<>(targetId.getSegments());
    rootId.getSegments().forEach(segment -> {
        checkState(segment.equals(remainingSegments.peekFirst()),
                "targetId %s should start with rootId %s", targetId, rootId);
        remainingSegments.pollFirst();
    });
    return remainingSegments;
}
 
Example #19
Source File: MyCustomEngine.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 5 votes vote down vote up
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest,
        UniqueId uniqueId) {
    // Discover test(s) and return a TestDescriptor object
    TestDescriptor testDescriptor = new EngineDescriptor(uniqueId,
            "My test");
    return testDescriptor;
}
 
Example #20
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 #21
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 #22
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 #23
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void complex_tags() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(ComplexTags.class);

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

    Map<UniqueId, Set<TestTag>> tagsById = new HashMap<>();
    descriptor.accept(d -> tagsById.put(d.getUniqueId(), d.getTags()));

    assertThat(getTagsForIdEndingIn(ComplexTags.class.getSimpleName(), tagsById))
            .containsOnly(TestTag.create("library-tag"));

    assertThat(getTagsForIdEndingIn(TestClassWithTags.class.getSimpleName(), tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("rules-tag"),
                    TestTag.create("tag-one"),
                    TestTag.create("tag-two"));

    assertThat(getTagsForIdEndingIn(TestClassWithTags.FIELD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("rules-tag"),
                    TestTag.create("tag-one"),
                    TestTag.create("tag-two"));

    assertThat(getTagsForIdEndingIn(ComplexTags.FIELD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("field-tag"));

    assertThat(getTagsForIdEndingIn(ComplexTags.METHOD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("method-tag"));
}
 
Example #24
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void rule_by_unique_id_without_violation() {
    UniqueId fieldRuleInLibrary = simpleRulesInLibraryId(engineId)
            .append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    simulateCachedClassesForTest(SimpleRuleLibrary.class, UnwantedClass.CLASS_SATISFYING_RULES);

    EngineExecutionTestListener testListener = execute(engineId, new EngineDiscoveryTestRequest()
            .withUniqueId(fieldRuleInLibrary));

    testListener.verifySuccessful(fieldRuleInLibrary);
    testListener.verifyNoOtherStartExceptHierarchyOf(fieldRuleInLibrary);
}
 
Example #25
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void rule_by_unique_id_with_violation() {
    UniqueId fieldRuleInLibrary = simpleRulesInLibraryId(engineId)
            .append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    simulateCachedClassesForTest(SimpleRuleLibrary.class, UnwantedClass.CLASS_VIOLATING_RULES);

    EngineExecutionTestListener testListener = execute(engineId, new EngineDiscoveryTestRequest()
            .withUniqueId(fieldRuleInLibrary));

    testListener.verifyViolation(fieldRuleInLibrary, UnwantedClass.CLASS_VIOLATING_RULES.getSimpleName());
    testListener.verifyNoOtherStartExceptHierarchyOf(fieldRuleInLibrary);
}
 
Example #26
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private Set<UniqueId> privateRuleLibraryIds(UniqueId uniqueId) {
    UniqueId libraryId = uniqueId
            .append(CLASS_SEGMENT_TYPE, LibraryWithPrivateTests.class.getName())
            .append(FIELD_SEGMENT_TYPE, LibraryWithPrivateTests.PRIVATE_RULES_FIELD_NAME)
            .append(CLASS_SEGMENT_TYPE, LibraryWithPrivateTests.SubRules.class.getName())
            .append(FIELD_SEGMENT_TYPE, LibraryWithPrivateTests.SubRules.PRIVATE_RULES_FIELD_NAME);
    return ImmutableSet.of(privateRuleFieldId(libraryId), privateRuleMethodId(libraryId));
}
 
Example #27
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void with_reason() {
    simulateCachedClassesForTest(IgnoredField.class, UnwantedClass.CLASS_VIOLATING_RULES);

    EngineExecutionTestListener testListener = execute(engineId, IgnoredField.class);

    UniqueId ignoredId = engineId
            .append(CLASS_SEGMENT_TYPE, IgnoredField.class.getName())
            .append(FIELD_SEGMENT_TYPE, IgnoredField.IGNORED_RULE_FIELD);
    testListener.verifySkipped(ignoredId, "some example description");
}
 
Example #28
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private Set<UniqueId> getExpectedIdsForComplexRuleLibrary(UniqueId uniqueId) {
    UniqueId complexRuleLibrary = uniqueId.append(CLASS_SEGMENT_TYPE, ComplexRuleLibrary.class.getName());
    Set<UniqueId> simpleRuleLibraryIds = getExpectedIdsForSimpleRuleLibrary(complexRuleLibrary
            .append(FIELD_SEGMENT_TYPE, ComplexRuleLibrary.RULES_ONE_FIELD));
    Set<UniqueId> simpleRulesIds = getExpectedIdsForSimpleRules(complexRuleLibrary
            .append(FIELD_SEGMENT_TYPE, ComplexRuleLibrary.RULES_TWO_FIELD));

    return Stream.of(simpleRuleLibraryIds, simpleRulesIds).flatMap(Set::stream).collect(toSet());
}
 
Example #29
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void with_reason() {
    simulateCachedClassesForTest(MetaIgnoredField.class, UnwantedClass.CLASS_VIOLATING_RULES);

    EngineExecutionTestListener testListener = execute(engineId, MetaIgnoredField.class);

    UniqueId ignoredId = engineId
            .append(CLASS_SEGMENT_TYPE, MetaIgnoredField.class.getName())
            .append(FIELD_SEGMENT_TYPE, MetaIgnoredField.IGNORED_RULE_FIELD);
    testListener.verifySkipped(ignoredId, "some example description");
}
 
Example #30
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private Set<UniqueId> getExpectedIdsForSimpleRuleLibrary(UniqueId uniqueId) {
    UniqueId simpleRuleLibrary = uniqueId.append(CLASS_SEGMENT_TYPE, SimpleRuleLibrary.class.getName());
    Set<UniqueId> simpleRulesIds = getExpectedIdsForSimpleRules(
            simpleRuleLibrary.append(FIELD_SEGMENT_TYPE, SimpleRuleLibrary.RULES_ONE_FIELD));
    Set<UniqueId> simpleRuleFieldIds = singleton(simpleRuleFieldTestId(
            simpleRuleLibrary.append(FIELD_SEGMENT_TYPE, SimpleRuleLibrary.RULES_TWO_FIELD)));

    return Stream.of(simpleRulesIds, simpleRuleFieldIds)
            .flatMap(Set::stream).collect(toSet());
}