use of org.junit.jupiter.api.io.CleanupMode in project junit5 by junit-team.
the class TempDirectory method injectFields.
private void injectFields(ExtensionContext context, Object testInstance, Class<?> testClass, Predicate<Field> predicate) {
findAnnotatedFields(testClass, TempDir.class, predicate).forEach(field -> {
assertSupportedType("field", field.getType());
try {
CleanupMode cleanupMode = determineCleanupModeForField(field);
makeAccessible(field).set(testInstance, getPathOrFile(field, field.getType(), cleanupMode, context));
} catch (Throwable t) {
ExceptionUtils.throwAsUncheckedException(t);
}
});
}
use of org.junit.jupiter.api.io.CleanupMode in project junit5 by junit-team.
the class TempDirectory method getPathOrFile.
private Object getPathOrFile(AnnotatedElement sourceElement, Class<?> type, CleanupMode cleanupMode, ExtensionContext extensionContext) {
Namespace namespace = //
getScope(extensionContext) == Scope.PER_DECLARATION ? //
NAMESPACE.append(sourceElement) : NAMESPACE;
Path path = //
extensionContext.getStore(namespace).getOrComputeIfAbsent(KEY, __ -> createTempDir(cleanupMode, extensionContext), //
CloseablePath.class).get();
return (type == Path.class) ? path : path.toFile();
}
use of org.junit.jupiter.api.io.CleanupMode in project junit5 by junit-team.
the class TempDirectory method resolveParameter.
/**
* Resolve the current temporary directory for the {@link Parameter} in the
* supplied {@link ParameterContext}.
*/
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
Class<?> parameterType = parameterContext.getParameter().getType();
assertSupportedType("parameter", parameterType);
CleanupMode cleanupMode = determineCleanupModeForParameter(parameterContext);
return getPathOrFile(parameterContext.getParameter(), parameterType, cleanupMode, extensionContext);
}
use of org.junit.jupiter.api.io.CleanupMode in project junit5 by junit-team.
the class DefaultJupiterConfigurationTests method getDefaultTempDirCleanupModeWithNoConfigParamSet.
@Test
void getDefaultTempDirCleanupModeWithNoConfigParamSet() {
JupiterConfiguration configuration = new DefaultJupiterConfiguration(mock(ConfigurationParameters.class));
CleanupMode cleanupMode = configuration.getDefaultTempDirCleanupMode();
assertThat(cleanupMode).isEqualTo(ALWAYS);
}
Aggregations