diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml index b2ef0a59ad..c4c929b7aa 100644 --- a/testing-modules/spring-testing/pom.xml +++ b/testing-modules/spring-testing/pom.xml @@ -75,6 +75,16 @@ spring-testing + + + org.apache.maven.plugins + maven-compiler-plugin + + 15 + 15 + + + src/main/resources @@ -87,7 +97,7 @@ 2.0.0.0 3.1.6 - 5.3.4 + 6.1.3 2.1.1 diff --git a/testing-modules/spring-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java b/testing-modules/spring-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java index d545daf0df..88f2f89b4c 100644 --- a/testing-modules/spring-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java +++ b/testing-modules/spring-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java @@ -8,8 +8,15 @@ public class ClassUsingProperty { @Value("${baeldung.testpropertysource.one}") private String propertyOne; - + + @Value("${baeldung.testpropertysource.two}") + private String propertyTwo; + public String retrievePropertyOne() { return propertyOne; } + + public String retrievePropertyTwo() { + return propertyTwo; + } } diff --git a/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/MultiplePropertiesInPropertySourceListIntegrationTest.java b/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/MultiplePropertiesInPropertySourceListIntegrationTest.java new file mode 100644 index 0000000000..e882d5c7cd --- /dev/null +++ b/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/MultiplePropertiesInPropertySourceListIntegrationTest.java @@ -0,0 +1,38 @@ +package com.baeldung.testpropertysource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = ClassUsingProperty.class) +@TestPropertySource( + locations = "/other-location.properties", + properties = { + "baeldung.testpropertysource.one=one", + "baeldung.testpropertysource.two=two", + }) +public class MultiplePropertiesInPropertySourceListIntegrationTest { + + @Autowired + ClassUsingProperty classUsingProperty; + + @Test + public void givenAMultilinePropertySource_whenVariableOneRetrieved_thenValueInPropertyAnnotationIsReturned() { + String output = classUsingProperty.retrievePropertyOne(); + + assertThat(output).isEqualTo("one"); + } + + @Test + public void givenAMultilinePropertySource_whenVariableTwoRetrieved_thenValueInPropertyAnnotationIsReturned() { + String output = classUsingProperty.retrievePropertyTwo(); + + assertThat(output).isEqualTo("two"); + } +} diff --git a/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/MultiplePropertiesInPropertySourceTextBlockIntegrationTest.java b/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/MultiplePropertiesInPropertySourceTextBlockIntegrationTest.java new file mode 100644 index 0000000000..e31055a4c6 --- /dev/null +++ b/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/MultiplePropertiesInPropertySourceTextBlockIntegrationTest.java @@ -0,0 +1,38 @@ +package com.baeldung.testpropertysource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = ClassUsingProperty.class) +@TestPropertySource( + locations = "/other-location.properties", + properties = """ + baeldung.testpropertysource.one=one + baeldung.testpropertysource.two=two + """) +public class MultiplePropertiesInPropertySourceTextBlockIntegrationTest { + + @Autowired + ClassUsingProperty classUsingProperty; + + @Test + public void givenAMultilinePropertySource_whenVariableOneRetrieved_thenValueInPropertyAnnotationIsReturned() { + String output = classUsingProperty.retrievePropertyOne(); + + assertThat(output).isEqualTo("one"); + } + + @Test + public void givenAMultilinePropertySource_whenVariableTwoRetrieved_thenValueInPropertyAnnotationIsReturned() { + String output = classUsingProperty.retrievePropertyTwo(); + + assertThat(output).isEqualTo("two"); + } +} diff --git a/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java b/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java index d98e2b9f98..5100d3a3bb 100644 --- a/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java +++ b/testing-modules/spring-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java @@ -18,7 +18,7 @@ public class PropertiesTestPropertySourceIntegrationTest { ClassUsingProperty classUsingProperty; @Test - public void givenDefaultTestPropertySource_whenVariableOneRetrieved_thenValueInDefaultFileReturned() { + public void givenACustomPropertySource_whenVariableOneRetrieved_thenValueInPropertyAnnotationIsReturned() { String output = classUsingProperty.retrievePropertyOne(); assertThat(output).isEqualTo("other-properties-value");