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");
}
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");
}
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()));
}
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());
});
}
Aggregations