Search in sources :

Example 6 with PreconditionViolationException

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

the class TagFilterTests method assertSyntaxViolationForExcludes.

private void assertSyntaxViolationForExcludes(String tag) {
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> excludeTags(tag));
    assertThat(exception).hasMessageStartingWith("Unable to parse tag expression");
}
Also used : PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException)

Example 7 with PreconditionViolationException

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

the class DefaultLauncherTests method registerTestExecutionListenersWithEmptyArray.

@Test
void registerTestExecutionListenersWithEmptyArray() {
    DefaultLauncher launcher = createLauncher(new DemoHierarchicalTestEngine("dummy id"));
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> launcher.registerTestExecutionListeners(new TestExecutionListener[0]));
    assertThat(exception).hasMessageContaining("listeners array must not be null or empty");
}
Also used : TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 8 with PreconditionViolationException

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

the class DefaultLauncherTests method registerTestExecutionListenersWithNullArray.

@Test
void registerTestExecutionListenersWithNullArray() {
    DefaultLauncher launcher = createLauncher(new DemoHierarchicalTestEngine("dummy id"));
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> launcher.registerTestExecutionListeners((TestExecutionListener[]) null));
    assertThat(exception).hasMessageContaining("listeners array must not be null or empty");
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 9 with PreconditionViolationException

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

the class DefaultLauncherTests method registerTestExecutionListenersWithArrayContainingNullElements.

@Test
void registerTestExecutionListenersWithArrayContainingNullElements() {
    DefaultLauncher launcher = createLauncher(new DemoHierarchicalTestEngine("dummy id"));
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> launcher.registerTestExecutionListeners(new TestExecutionListener[] { null }));
    assertThat(exception).hasMessageContaining("individual listeners must not be null");
}
Also used : TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 10 with PreconditionViolationException

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

the class DiscoverySelectors method selectDirectory.

/**
 * Create a {@code DirectorySelector} for the supplied {@linkplain File directory}.
 *
 * <p>This method selects the directory in its {@linkplain File#getCanonicalPath()
 * canonical} form and throws a {@link PreconditionViolationException} if the
 * directory does not exist.
 *
 * @param directory the directory to select; never {@code null}
 * @see DirectorySelector
 * @see #selectDirectory(String)
 * @see #selectFile(String)
 * @see #selectFile(File)
 */
public static DirectorySelector selectDirectory(File directory) {
    Preconditions.notNull(directory, "Directory must not be null");
    Preconditions.condition(directory.isDirectory(), () -> String.format("The supplied java.io.File [%s] must represent an existing directory", directory));
    try {
        return new DirectorySelector(directory.getCanonicalPath());
    } catch (IOException ex) {
        throw new PreconditionViolationException("Failed to retrieve canonical path for directory: " + directory, ex);
    }
}
Also used : IOException(java.io.IOException) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException)

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