Search in sources :

Example 1 with PreconditionViolationException

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

the class TypeBasedParameterResolverTests method missingTypeTypeBasedParameterResolver.

@Test
void missingTypeTypeBasedParameterResolver() {
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, MissingTypeTypeBasedParameterResolver::new);
    assertEquals("Failed to discover parameter type supported by " + MissingTypeTypeBasedParameterResolver.class.getName() + "; potentially caused by lacking parameterized type in class declaration.", exception.getMessage());
}
Also used : PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 2 with PreconditionViolationException

use of org.junit.platform.commons.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.PreconditionViolationException)

Example 3 with PreconditionViolationException

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

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecyclePreconditions.

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

Example 4 with PreconditionViolationException

use of org.junit.platform.commons.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}
 * @param position the position inside the file; may be {@code null}
 * @see FileSelector
 * @see #selectFile(File)
 * @see #selectFile(String)
 * @see #selectFile(String, FilePosition)
 * @see #selectDirectory(String)
 * @see #selectDirectory(File)
 */
public static FileSelector selectFile(File file, FilePosition position) {
    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(), position);
    } 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.PreconditionViolationException)

Example 5 with PreconditionViolationException

use of org.junit.platform.commons.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.PreconditionViolationException)

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