Skip to content

Commit

Permalink
Nullability refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Feb 16, 2021
1 parent ed9ec58 commit 9417975
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ protected Set<String> doGetActiveProfiles() {
* @since 5.3.4
* @see #ACTIVE_PROFILES_PROPERTY_NAME
*/
@Nullable
protected String doGetActiveProfilesProperty() {
return getProperty(ACTIVE_PROFILES_PROPERTY_NAME);
}
Expand Down Expand Up @@ -350,6 +351,7 @@ protected Set<String> doGetDefaultProfiles() {
* @since 5.3.4
* @see #DEFAULT_PROFILES_PROPERTY_NAME
*/
@Nullable
protected String doGetDefaultProfilesProperty() {
return getProperty(DEFAULT_PROFILES_PROPERTY_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import org.junit.jupiter.api.Test;

import org.springframework.lang.Nullable;

import static org.assertj.core.api.Assertions.assertThat;

/**
Expand All @@ -34,8 +36,6 @@
*/
class CustomEnvironmentTests {

// -- tests relating to customizing reserved default profiles ----------------------

@Test
void control() {
Environment env = new AbstractEnvironment() { };
Expand Down Expand Up @@ -111,11 +111,12 @@ protected Set<String> getReservedDefaultProfiles() {
public void withNoProfileProperties() {
ConfigurableEnvironment env = new AbstractEnvironment() {
@Override
@Nullable
protected String doGetActiveProfilesProperty() {
return null;
}

@Override
@Nullable
protected String doGetDefaultProfilesProperty() {
return null;
}
Expand All @@ -140,23 +141,23 @@ class CustomMutablePropertySources extends MutablePropertySources {}
@Test
void withCustomPropertyResolver() {
class CustomPropertySourcesPropertyResolver extends PropertySourcesPropertyResolver {
public CustomPropertySourcesPropertyResolver(
PropertySources propertySources) {
public CustomPropertySourcesPropertyResolver(PropertySources propertySources) {
super(propertySources);
}

@Override
@Nullable
public String getProperty(String key) {
return super.getProperty(key)+"-test";
}
}

ConfigurableEnvironment env = new AbstractEnvironment() {
@Override
protected ConfigurablePropertyResolver createPropertyResolver(
MutablePropertySources propertySources) {
protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources) {
return new CustomPropertySourcesPropertyResolver(propertySources);
}
};

Map<String, Object> values = new LinkedHashMap<>();
values.put("spring", "framework");
PropertySource<?> propertySource = new MapPropertySource("test", values);
Expand All @@ -168,6 +169,4 @@ private Profiles defaultProfile() {
return Profiles.of(AbstractEnvironment.RESERVED_DEFAULT_PROFILE_NAME);
}


// -- tests relating to customizing property sources -------------------------------
}

0 comments on commit 9417975

Please sign in to comment.