Merge pull request #10399 from rozagerardo/rozagerardo/JAVA-3716_Update-articles-for-2.4.0--spring-boot-properties2
[JAVA-3716] Update articles for 2.4.0 - spring-boot-modules/spring-boot-properties2
This commit is contained in:
commit
f2f12b21b8
|
@ -51,21 +51,21 @@ public class ValuesWithDefaultsApp {
|
|||
@PostConstruct
|
||||
public void afterInitialize() {
|
||||
// strings
|
||||
Assert.isTrue(stringWithDefaultValue.equals("my default value"));
|
||||
Assert.isTrue(stringWithBlankDefaultValue.equals(""));
|
||||
Assert.isTrue(stringWithDefaultValue.equals("my default value"), "unexpected value for stringWithDefaultValue");
|
||||
Assert.isTrue(stringWithBlankDefaultValue.equals(""), "unexpected value for stringWithBlankDefaultValue");
|
||||
|
||||
// other primitives
|
||||
Assert.isTrue(booleanWithDefaultValue);
|
||||
Assert.isTrue(intWithDefaultValue == 42);
|
||||
Assert.isTrue(booleanWithDefaultValue, "unexpected value for booleanWithDefaultValue");
|
||||
Assert.isTrue(intWithDefaultValue == 42, "unexpected value for intWithDefaultValue");
|
||||
|
||||
// arrays
|
||||
List<String> stringListValues = Arrays.asList("one", "two", "three");
|
||||
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues));
|
||||
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues), "unexpected value for stringArrayWithDefaults");
|
||||
|
||||
List<Integer> intListValues = Arrays.asList(1, 2, 3);
|
||||
Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues));
|
||||
Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues), "unexpected value for intArrayWithDefaults");
|
||||
|
||||
// SpEL
|
||||
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"));
|
||||
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"), "unexpected value for spelWithDefaultValue");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = SpringListPropertiesApplication.class)
|
||||
|
@ -47,7 +48,7 @@ public class ListsPropertiesUnitTest {
|
|||
|
||||
@Test
|
||||
public void whenContextIsInitialized_thenInjectedArrayContainsExpectedValues() {
|
||||
assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings);
|
||||
assertArrayEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -82,7 +83,7 @@ public class ListsPropertiesUnitTest {
|
|||
String[] arrayOfStrings = environment.getProperty("arrayOfStrings", String[].class);
|
||||
List<String> listOfStrings = (List<String>)environment.getProperty("arrayOfStrings", List.class);
|
||||
|
||||
assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings);
|
||||
assertArrayEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings);
|
||||
assertEquals(Arrays.asList("Baeldung", "dot", "com"), listOfStrings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
|
||||
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.baeldung.properties.yamllist.pojo.ApplicationProps;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
|
||||
@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class)
|
||||
@EnableConfigurationProperties(value = ApplicationProps.class)
|
||||
class YamlComplexListsUnitTest {
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
|
||||
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.baeldung.properties.yamllist.pojo.ApplicationProps;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
|
||||
@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class)
|
||||
@EnableConfigurationProperties(value = ApplicationProps.class)
|
||||
class YamlSimpleListUnitTest {
|
||||
|
||||
|
|
Loading…
Reference in New Issue