use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.
the class InstantiatingConfigurationParameterConverterTests method shouldReturnEmptyOptionalIfNoClassFound.
@Test
void shouldReturnEmptyOptionalIfNoClassFound(LogRecordListener listener) {
ConfigurationParameters configurationParameters = mock(ConfigurationParameters.class);
when(configurationParameters.get(KEY)).thenReturn(Optional.of("random-string"));
InstantiatingConfigurationParameterConverter<DisplayNameGenerator> converter = new InstantiatingConfigurationParameterConverter<>(DisplayNameGenerator.class, "display name generator");
Optional<DisplayNameGenerator> displayNameGenerator = converter.get(configurationParameters, KEY);
assertThat(displayNameGenerator).isEmpty();
assertExpectedLogMessage(listener, Level.WARNING, "Failed to load default display name generator " + "class 'random-string' set via the 'junit.jupiter.displayname.generator.default' " + "configuration parameter. Falling back to default behavior.");
}
use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.
the class InstantiatingConfigurationParameterConverterTests method shouldInstantiateConfiguredClass.
@Test
void shouldInstantiateConfiguredClass(LogRecordListener listener) {
ConfigurationParameters configurationParameters = mock(ConfigurationParameters.class);
when(configurationParameters.get(KEY)).thenReturn(Optional.of(CustomDisplayNameGenerator.class.getName()));
InstantiatingConfigurationParameterConverter<DisplayNameGenerator> converter = new InstantiatingConfigurationParameterConverter<>(DisplayNameGenerator.class, "display name generator");
DisplayNameGenerator displayNameGenerator = converter.get(configurationParameters, KEY).orElseThrow();
assertThat(displayNameGenerator).isInstanceOf(CustomDisplayNameGenerator.class);
assertExpectedLogMessage(listener, Level.CONFIG, "Using default display name generator " + "'org.junit.jupiter.engine.descriptor.CustomDisplayNameGenerator' set via the " + "'junit.jupiter.displayname.generator.default' configuration parameter.");
}
use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.
the class InstantiatingConfigurationParameterConverterTests method shouldReturnEmptyOptionalIfClassFoundIsNotATypeOfExpectedType.
@Test
void shouldReturnEmptyOptionalIfClassFoundIsNotATypeOfExpectedType(LogRecordListener listener) {
ConfigurationParameters configurationParameters = mock(ConfigurationParameters.class);
when(configurationParameters.get(KEY)).thenReturn(Optional.of(Object.class.getName()));
InstantiatingConfigurationParameterConverter<DisplayNameGenerator> converter = new InstantiatingConfigurationParameterConverter<>(DisplayNameGenerator.class, "display name generator");
Optional<DisplayNameGenerator> displayNameGenerator = converter.get(configurationParameters, KEY);
assertThat(displayNameGenerator).isEmpty();
assertExpectedLogMessage(listener, Level.WARNING, "Failed to load default display name generator class 'java.lang.Object' " + "set via the 'junit.jupiter.displayname.generator.default' configuration parameter. " + "Falling back to default behavior.");
}
use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.
the class InstantiatingConfigurationParameterConverterTests method shouldReturnEmptyOptionalIfClassNameIsNotFullyQualified.
@Test
void shouldReturnEmptyOptionalIfClassNameIsNotFullyQualified(LogRecordListener listener) {
ConfigurationParameters configurationParameters = mock(ConfigurationParameters.class);
when(configurationParameters.get(KEY)).thenReturn(Optional.of(CustomDisplayNameGenerator.class.getSimpleName()));
InstantiatingConfigurationParameterConverter<DisplayNameGenerator> converter = new InstantiatingConfigurationParameterConverter<>(DisplayNameGenerator.class, "display name generator");
Optional<DisplayNameGenerator> displayNameGenerator = converter.get(configurationParameters, KEY);
assertThat(displayNameGenerator).isEmpty();
assertExpectedLogMessage(listener, Level.WARNING, "Failed to load default display name generator class 'CustomDisplayNameGenerator' " + "set via the 'junit.jupiter.displayname.generator.default' configuration parameter. " + "Falling back to default behavior.");
}
use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.
the class InstantiatingConfigurationParameterConverterTests method shouldReturnEmptyOptionalIfNoConfigurationFound.
@Test
void shouldReturnEmptyOptionalIfNoConfigurationFound() {
ConfigurationParameters configurationParameters = mock(ConfigurationParameters.class);
when(configurationParameters.get(KEY)).thenReturn(Optional.empty());
InstantiatingConfigurationParameterConverter<DisplayNameGenerator> converter = new InstantiatingConfigurationParameterConverter<>(DisplayNameGenerator.class, "display name generator");
Optional<DisplayNameGenerator> displayNameGenerator = converter.get(configurationParameters, KEY);
assertThat(displayNameGenerator).isEmpty();
}
Aggregations