Search in sources :

Example 11 with PreconditionViolationException

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);
    }
}
Also used : IOException(java.io.IOException) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException)

Example 12 with PreconditionViolationException

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");
}
Also used : PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 13 with PreconditionViolationException

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);
}
Also used : PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException)

Example 14 with PreconditionViolationException

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());
}
Also used : PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 15 with PreconditionViolationException

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");
}
Also used : PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Aggregations

PreconditionViolationException (org.junit.platform.commons.util.PreconditionViolationException)18 Test (org.junit.jupiter.api.Test)12 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)3 IOException (java.io.IOException)2 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)2 TemporaryFolder (org.junit.rules.TemporaryFolder)1 Verifier (org.junit.rules.Verifier)1