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