Skip to content

Commit e6de4dd

Browse files
committed
A test of ReflectionTestUtils
1 parent e07dfc3 commit e6de4dd

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/main/java/me/will/springboot3ut/components/PropertySourceResolver.java

+6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ public class PropertySourceResolver {
1111
@Value("${components.secondProperty}")
1212
private String secondProperty;
1313

14+
private String thirdProperty = "DefaultValue";
15+
1416
public String getFirstProperty() {
1517
return firstProperty;
1618
}
1719

1820
public String getSecondProperty() {
1921
return secondProperty;
2022
}
23+
24+
public String getThirdProperty() {
25+
return thirdProperty;
26+
}
2127
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package me.will.springboot3ut.components;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.util.ReflectionTestUtils;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
@SpringBootTest
11+
public class PropertySourceResolverReflectionUtilTest {
12+
@Autowired
13+
private PropertySourceResolver propertySourceResolver;
14+
15+
@Test
16+
public void testProperties_ShouldInjectedByReflectionUtils() {
17+
ReflectionTestUtils.setField(propertySourceResolver, "thirdProperty", "OverriddenByReflectionUtils");
18+
assertEquals("OverriddenByReflectionUtils", propertySourceResolver.getThirdProperty());
19+
}
20+
}

0 commit comments

Comments
 (0)