use of org.junit.platform.commons.util.PreconditionViolationException in project junit5 by junit-team.
the class DiscoverySelectors method selectFile.
/**
* Create a {@code FileSelector} for the supplied {@linkplain File file}.
*
* <p>This method selects the file in its {@linkplain File#getCanonicalPath()
* canonical} form and throws a {@link PreconditionViolationException} if the
* file does not exist.
*
* @param file the file to select; never {@code null}
* @see FileSelector
* @see #selectFile(String)
* @see #selectDirectory(String)
* @see #selectDirectory(File)
*/
public static FileSelector selectFile(File file) {
Preconditions.notNull(file, "File must not be null");
Preconditions.condition(file.isFile(), () -> String.format("The supplied java.io.File [%s] must represent an existing file", file));
try {
return new FileSelector(file.getCanonicalPath());
} catch (IOException ex) {
throw new PreconditionViolationException("Failed to retrieve canonical path for file: " + file, ex);
}
}
use of org.junit.platform.commons.util.PreconditionViolationException in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecyclePreconditions.
@Test
void getTestInstanceLifecyclePreconditions() {
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> getTestInstanceLifecycle(null, mock(ConfigurationParameters.class)));
assertThat(exception).hasMessage("testClass must not be null");
exception = assertThrows(PreconditionViolationException.class, () -> getTestInstanceLifecycle(getClass(), null));
assertThat(exception).hasMessage("ConfigurationParameters must not be null");
}
use of org.junit.platform.commons.util.PreconditionViolationException in project junit5 by junit-team.
the class AssertAllAssertionsTests method assertPrecondition.
private void assertPrecondition(String msg, Executable executable) {
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, executable);
assertMessageEquals(exception, msg);
}
use of org.junit.platform.commons.util.PreconditionViolationException in project junit5 by junit-team.
the class OrFilterTests method exceptionWithoutAnyFilters.
@Test
void exceptionWithoutAnyFilters() {
PreconditionViolationException actual = assertThrows(PreconditionViolationException.class, () -> {
new OrFilter(emptyList());
});
assertEquals("filters must not be empty", actual.getMessage());
}
use of org.junit.platform.commons.util.PreconditionViolationException in project junit5 by junit-team.
the class ValueArgumentsProviderTests method multipleInputsAreNotAllowed.
@Test
void multipleInputsAreNotAllowed() {
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> provideArguments(new short[1], new byte[0], new int[1], new long[0], new float[0], new double[0], new char[0], new String[0], new Class<?>[0]));
assertThat(exception).hasMessageContaining("Exactly one type of input must be provided in the @ValueSource annotation, but there were 2");
}
Aggregations