Search in sources :

Example 6 with DisplayNameGenerator

use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.

the class InstantiatingConfigurationParameterConverterTests method shouldTrimAndInstantiateConfiguredClass.

@Test
void shouldTrimAndInstantiateConfiguredClass(LogRecordListener listener) {
    ConfigurationParameters configurationParameters = mock(ConfigurationParameters.class);
    String classNameWithSpaces = " " + CustomDisplayNameGenerator.class.getName() + "  ";
    when(configurationParameters.get(KEY)).thenReturn(Optional.of(classNameWithSpaces));
    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 7 with DisplayNameGenerator

use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.

the class DefaultJupiterConfigurationTests method shouldGetStandardAsDefaultDisplayNameGeneratorWithoutConfigParamSet.

@Test
void shouldGetStandardAsDefaultDisplayNameGeneratorWithoutConfigParamSet() {
    ConfigurationParameters parameters = mock(ConfigurationParameters.class);
    String key = Constants.DEFAULT_DISPLAY_NAME_GENERATOR_PROPERTY_NAME;
    when(parameters.get(key)).thenReturn(Optional.empty());
    JupiterConfiguration configuration = new DefaultJupiterConfiguration(parameters);
    DisplayNameGenerator defaultDisplayNameGenerator = configuration.getDefaultDisplayNameGenerator();
    assertThat(defaultDisplayNameGenerator).isInstanceOf(DisplayNameGenerator.Standard.class);
}
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 8 with DisplayNameGenerator

use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.

the class DefaultJupiterConfigurationTests method shouldGetDefaultDisplayNameGeneratorWithConfigParamSet.

@Test
void shouldGetDefaultDisplayNameGeneratorWithConfigParamSet() {
    ConfigurationParameters parameters = mock(ConfigurationParameters.class);
    String key = Constants.DEFAULT_DISPLAY_NAME_GENERATOR_PROPERTY_NAME;
    when(parameters.get(key)).thenReturn(Optional.of(CustomDisplayNameGenerator.class.getName()));
    JupiterConfiguration configuration = new DefaultJupiterConfiguration(parameters);
    DisplayNameGenerator defaultDisplayNameGenerator = configuration.getDefaultDisplayNameGenerator();
    assertThat(defaultDisplayNameGenerator).isInstanceOf(CustomDisplayNameGenerator.class);
}
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 9 with DisplayNameGenerator

use of org.junit.jupiter.api.DisplayNameGenerator in project junit5 by junit-team.

the class InstantiatingConfigurationParameterConverterTests method shouldReturnEmptyOptionalIfConfigurationIsBlank.

@Test
void shouldReturnEmptyOptionalIfConfigurationIsBlank() {
    ConfigurationParameters configurationParameters = mock(ConfigurationParameters.class);
    when(configurationParameters.get(KEY)).thenReturn(Optional.of(""));
    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