Allow JSON Testers to be @Autowired

Switch `@AutoConfigureJsonTesters` to use regular `@Autowired` injection
for JSON testers. Prior to this commit JSON Tester fields were
initialized directly which caused IDE issues and was also a little
confusing.

Fixes gh-6451
This commit is contained in:
Phillip Webb
2016-07-26 19:44:47 -07:00
parent a44cc196de
commit 296dc7132b
13 changed files with 289 additions and 377 deletions

View File

@@ -5011,12 +5011,13 @@ annotation.
Spring Boot includes AssertJ based helpers that work with the JSONassert and JsonPath
libraries to check that JSON is as expected. The `JacksonHelper`, `GsonHelper` and
`BasicJsonTester` classes can be used for Jackson, Gson and Strings respectively. Any
helper fields on the test class will be automatically initialized when using `@JsonTest`.
helper fields on the test class can be `@Autowired` when using `@JsonTest`.
[source,java,indent=0]
----
import org.junit.*;
import org.junit.runner.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.boot.test.autoconfigure.json.*;
import org.springframework.boot.test.context.*;
import org.springframework.boot.test.json.*;
@@ -5028,6 +5029,7 @@ helper fields on the test class will be automatically initialized when using `@J
@JsonTest
public class MyJsonTests {
@Autowired
private JacksonTester<VehicleDetails> json;
@Test