Search in sources :

Example 6 with PreconditionViolationException

use of org.junit.platform.commons.PreconditionViolationException in project junit5 by junit-team.

the class AbstractTestRuleAdapterTests method constructionWithUnassignableArgumentsFails.

@Test
void constructionWithUnassignableArgumentsFails() {
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> new TestableTestRuleAdapter(new SimpleRuleAnnotatedMember(new TemporaryFolder()), Verifier.class));
    assertEquals(exception.getMessage(), "class org.junit.rules.Verifier is not assignable from class org.junit.rules.TemporaryFolder");
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) Verifier(org.junit.rules.Verifier) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 7 with PreconditionViolationException

use of org.junit.platform.commons.PreconditionViolationException in project junit5 by junit-team.

the class DefaultJupiterConfigurationTests method getDefaultTestInstanceLifecyclePreconditions.

@Test
void getDefaultTestInstanceLifecyclePreconditions() {
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> new DefaultJupiterConfiguration(null));
    assertThat(exception).hasMessage("ConfigurationParameters must not be null");
}
Also used : PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 8 with PreconditionViolationException

use of org.junit.platform.commons.PreconditionViolationException in project junit5 by junit-team.

the class EmptyArgumentsProvider method provideArguments.

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
    Method testMethod = context.getRequiredTestMethod();
    Class<?>[] parameterTypes = testMethod.getParameterTypes();
    Preconditions.condition(parameterTypes.length > 0, () -> String.format("@EmptySource cannot provide an empty argument to method [%s]: the method does not declare any formal parameters.", testMethod.toGenericString()));
    Class<?> parameterType = parameterTypes[0];
    if (String.class.equals(parameterType)) {
        return Stream.of(arguments(""));
    }
    if (List.class.equals(parameterType)) {
        return Stream.of(arguments(Collections.emptyList()));
    }
    if (Set.class.equals(parameterType)) {
        return Stream.of(arguments(Collections.emptySet()));
    }
    if (Map.class.equals(parameterType)) {
        return Stream.of(arguments(Collections.emptyMap()));
    }
    if (parameterType.isArray()) {
        Object array = Array.newInstance(parameterType.getComponentType(), 0);
        return Stream.of(arguments(array));
    }
    // else
    throw new PreconditionViolationException(String.format("@EmptySource cannot provide an empty argument to method [%s]: [%s] is not a supported type.", testMethod.toGenericString(), parameterType.getName()));
}
Also used : Method(java.lang.reflect.Method) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException)

Example 9 with PreconditionViolationException

use of org.junit.platform.commons.PreconditionViolationException in project junit5 by junit-team.

the class SuiteTestDescriptorTests method discoveryPlanCanNotBeModifiedAfterDiscovery.

@Test
void discoveryPlanCanNotBeModifiedAfterDiscovery() {
    suite.addDiscoveryRequestFrom(SelectClassesSuite.class);
    suite.discover();
    assertAll(() -> {
        PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> suite.addDiscoveryRequestFrom(SelectClassesSuite.class));
        assertEquals("discovery request can not be modified after discovery", exception.getMessage());
    }, () -> {
        PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> suite.addDiscoveryRequestFrom(methodId));
        assertEquals("discovery request can not be modified after discovery", exception.getMessage());
    });
}
Also used : SelectClassesSuite(org.junit.platform.suite.engine.testsuites.SelectClassesSuite) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Aggregations

PreconditionViolationException (org.junit.platform.commons.PreconditionViolationException)9 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)1 DefaultJupiterConfiguration (org.junit.jupiter.engine.config.DefaultJupiterConfiguration)1 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)1 SelectClassesSuite (org.junit.platform.suite.engine.testsuites.SelectClassesSuite)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1 Verifier (org.junit.rules.Verifier)1