[BAEL-1626] testing-modules | A Quick Guide to @TestPropertySource - move to existing submodule (#5292)

* *added tests using testpropertysource

* fix: using property for version in pom file

* fix, added dependency with compile scope to build successfully on mvn clean install

* * moved testpropertysource tests from spring-context-tests to spring-tests submodule

* deleted  submodule created for this article, since it was moved
This commit is contained in:
rozagerardo
2018-09-19 11:16:10 -03:00
committed by maibin
parent ca1f5f6bfd
commit a5acc10bac
7 changed files with 0 additions and 25 deletions
@@ -0,0 +1,26 @@
package com.baeldung.testpropertysource;
import static org.assertj.core.api.Assertions.assertThat;
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;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = ClassUsingProperty.class)
@TestPropertySource
public class DefaultTestPropertySourceIntegrationTest {
@Autowired
ClassUsingProperty classUsingProperty;
@Test
public void givenDefaultTestPropertySource_whenVariableOneRetrieved_thenValueInDefaultFileReturned() {
String output = classUsingProperty.retrievePropertyOne();
assertThat(output).isEqualTo("default-value");
}
}
@@ -0,0 +1,26 @@
package com.baeldung.testpropertysource;
import static org.assertj.core.api.Assertions.assertThat;
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;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = ClassUsingProperty.class)
@TestPropertySource(locations = "/other-location.properties")
public class LocationTestPropertySourceIntegrationTest {
@Autowired
ClassUsingProperty classUsingProperty;
@Test
public void givenDefaultTestPropertySource_whenVariableOneRetrieved_thenValueInDefaultFileReturned() {
String output = classUsingProperty.retrievePropertyOne();
assertThat(output).isEqualTo("other-location-value");
}
}
@@ -0,0 +1,26 @@
package com.baeldung.testpropertysource;
import static org.assertj.core.api.Assertions.assertThat;
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;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = ClassUsingProperty.class)
@TestPropertySource(locations = "/other-location.properties", properties = "baeldung.testpropertysource.one=other-properties-value")
public class PropertiesTestPropertySourceIntegrationTest {
@Autowired
ClassUsingProperty classUsingProperty;
@Test
public void givenDefaultTestPropertySource_whenVariableOneRetrieved_thenValueInDefaultFileReturned() {
String output = classUsingProperty.retrievePropertyOne();
assertThat(output).isEqualTo("other-properties-value");
}
}
@@ -0,0 +1 @@
baeldung.testpropertysource.one=other-location-value