BAEL-4069: Add example of using @Value with constructor/setter (#9318)

This commit is contained in:
kwoyke
2020-05-19 21:59:55 +02:00
committed by GitHub
parent 73762873f6
commit 7bc07fdac9
5 changed files with 94 additions and 1 deletions
@@ -0,0 +1,22 @@
package com.baeldung.value;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CollectionProvider.class)
public class CollectionProviderIntegrationTest {
@Autowired
private CollectionProvider collectionProvider;
@Test
public void givenPropertyFileWhenSetterInjectionUsedThenValueInjected() {
assertThat(collectionProvider.getValues()).contains("A", "B", "C");
}
}
@@ -0,0 +1,22 @@
package com.baeldung.value;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = PriorityProvider.class)
public class PriorityProviderIntegrationTest {
@Autowired
private PriorityProvider priorityProvider;
@Test
public void givenPropertyFileWhenConstructorInjectionUsedThenValueInjected() {
assertThat(priorityProvider.getPriority()).isEqualTo("Properties file");
}
}