### Question:
GenieDefaultPropertiesPostProcessor implements EnvironmentPostProcessor { @Override public void postProcessEnvironment(final ConfigurableEnvironment environment, final SpringApplication application) { final Resource defaultProperties = new ClassPathResource(DEFAULT_PROPERTIES_FILE); final PropertySource<?> defaultSource = PropertySourceUtils.loadYamlPropertySource(DEFAULT_PROPERTY_SOURCE_NAME, defaultProperties); environment.getPropertySources().addLast(defaultSource); if (Arrays.asList(environment.getActiveProfiles()).contains(PROD_PROFILE)) { final Resource defaultProdProperties = new ClassPathResource(DEFAULT_PROD_PROPERTIES_FILE); final PropertySource<?> defaultProdSource = PropertySourceUtils.loadYamlPropertySource(DEFAULT_PROD_PROPERTY_SOURCE_NAME, defaultProdProperties); environment.getPropertySources().addBefore(DEFAULT_PROPERTY_SOURCE_NAME, defaultProdSource); } }  @Override void postProcessEnvironment(final ConfigurableEnvironment environment, final SpringApplication application);  }### Answer:
@Test void testSmokeProperty() { this.contextRunner .run( context -> { final SpringApplication application = Mockito.mock(SpringApplication.class); final ConfigurableEnvironment environment = context.getEnvironment(); Assertions.assertThat( environment .getPropertySources() .contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROPERTY_SOURCE_NAME) ).isFalse(); Assertions.assertThat( environment .getPropertySources() .contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROD_PROPERTY_SOURCE_NAME) ).isFalse(); Assertions.assertThat(environment.getProperty("genie.smoke")).isNull(); this.processor.postProcessEnvironment(environment, application); Assertions.assertThat( environment .getPropertySources() .contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROPERTY_SOURCE_NAME) ).isTrue(); Assertions.assertThat( environment .getPropertySources() .contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROD_PROPERTY_SOURCE_NAME) ).isFalse(); Assertions .assertThat(environment.getProperty("genie.smoke", Boolean.class, false)) .isTrue(); } ); }
@Test void testProdSmokeProperty() { this.contextRunner .withPropertyValues("spring.profiles.active=prod") .run( context -> { final SpringApplication application = Mockito.mock(SpringApplication.class); final ConfigurableEnvironment environment = context.getEnvironment(); final MutablePropertySources propertySources = environment.getPropertySources(); Assertions.assertThat( propertySources.contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROPERTY_SOURCE_NAME) ).isFalse(); Assertions.assertThat( propertySources.contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROD_PROPERTY_SOURCE_NAME) ).isFalse(); Assertions.assertThat(environment.getProperty("genie.smoke")).isNull(); this.processor.postProcessEnvironment(environment, application); Assertions.assertThat( propertySources.contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROPERTY_SOURCE_NAME) ).isTrue(); Assertions.assertThat( propertySources.contains(GenieDefaultPropertiesPostProcessor.DEFAULT_PROD_PROPERTY_SOURCE_NAME) ).isTrue(); final PropertySource<?> defaultPropertySource = propertySources.get(GenieDefaultPropertiesPostProcessor.DEFAULT_PROPERTY_SOURCE_NAME); final PropertySource<?> defaultProdPropertySource = propertySources.get(GenieDefaultPropertiesPostProcessor.DEFAULT_PROD_PROPERTY_SOURCE_NAME); Assertions.assertThat(defaultPropertySource).isNotNull(); Assertions.assertThat(defaultProdPropertySource).isNotNull(); Assertions .assertThat(propertySources.precedenceOf(defaultProdPropertySource)) .isLessThan(propertySources.precedenceOf(defaultPropertySource)); Assertions .assertThat(environment.getProperty("genie.smoke", Boolean.class, true)) .isFalse(); } ); }