Search in sources :

Example 1 with DisplayNameGenerator

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.");
}
Also used : DisplayNameGenerator(org.junit.jupiter.api.DisplayNameGenerator) CustomDisplayNameGenerator(org.junit.jupiter.engine.descriptor.CustomDisplayNameGenerator) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Example 2 with DisplayNameGenerator

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.");
}
Also used : DisplayNameGenerator(org.junit.jupiter.api.DisplayNameGenerator) CustomDisplayNameGenerator(org.junit.jupiter.engine.descriptor.CustomDisplayNameGenerator) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Example 3 with DisplayNameGenerator

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.");
}
Also used : DisplayNameGenerator(org.junit.jupiter.api.DisplayNameGenerator) CustomDisplayNameGenerator(org.junit.jupiter.engine.descriptor.CustomDisplayNameGenerator) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Example 4 with DisplayNameGenerator

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.");
}
Also used : DisplayNameGenerator(org.junit.jupiter.api.DisplayNameGenerator) CustomDisplayNameGenerator(org.junit.jupiter.engine.descriptor.CustomDisplayNameGenerator) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Example 5 with DisplayNameGenerator

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();
}
Also used : DisplayNameGenerator(org.junit.jupiter.api.DisplayNameGenerator) CustomDisplayNameGenerator(org.junit.jupiter.engine.descriptor.CustomDisplayNameGenerator) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Aggregations

DisplayNameGenerator (org.junit.jupiter.api.DisplayNameGenerator)9 Test (org.junit.jupiter.api.Test)9 CustomDisplayNameGenerator (org.junit.jupiter.engine.descriptor.CustomDisplayNameGenerator)9 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)9