|
20 | 20 | import java.util.List;
|
21 | 21 | import java.util.Map;
|
22 | 22 |
|
| 23 | +import org.assertj.core.api.AbstractAssert; |
23 | 24 | import org.assertj.core.api.AbstractBooleanAssert;
|
24 | 25 | import org.assertj.core.api.AbstractMapAssert;
|
25 | 26 | import org.assertj.core.api.AbstractObjectAssert;
|
26 | 27 | import org.assertj.core.api.AbstractStringAssert;
|
| 28 | +import org.assertj.core.api.AssertFactory; |
27 | 29 | import org.assertj.core.api.Assertions;
|
| 30 | +import org.assertj.core.api.InstanceOfAssertFactories; |
28 | 31 | import org.assertj.core.api.ObjectArrayAssert;
|
29 | 32 | import org.assertj.core.error.BasicErrorMessageFactory;
|
30 | 33 | import org.assertj.core.internal.Failures;
|
31 | 34 |
|
32 |
| -import org.springframework.core.ParameterizedTypeReference; |
33 | 35 | import org.springframework.core.ResolvableType;
|
34 | 36 | import org.springframework.http.HttpInputMessage;
|
35 | 37 | import org.springframework.http.MediaType;
|
@@ -152,16 +154,23 @@ public <T> AbstractObjectAssert<?, T> convertTo(Class<T> target) {
|
152 | 154 | }
|
153 | 155 |
|
154 | 156 | /**
|
155 |
| - * Verify that the actual value can be converted to an instance of the |
156 |
| - * given {@code target}, and produce a new {@linkplain AbstractObjectAssert |
157 |
| - * assertion} object narrowed to that type. |
158 |
| - * @param target the {@linkplain ParameterizedTypeReference parameterized |
159 |
| - * type} to convert the actual value to |
| 157 | + * Verify that the actual value can be converted to an instance of the type |
| 158 | + * defined by the given {@link AssertFactory} and return a new Assert narrowed |
| 159 | + * to that type. |
| 160 | + * <p>{@link InstanceOfAssertFactories} provides static factories for all the |
| 161 | + * types supported by {@link Assertions#assertThat}. Additional factories can |
| 162 | + * be created by implementing {@link AssertFactory}. |
| 163 | + * <p>Example: <pre><code class="java"> |
| 164 | + * // Check that the json value is an array of 3 users |
| 165 | + * assertThat(jsonValue).convertTo(InstanceOfAssertFactories.list(User.class)) |
| 166 | + * hasSize(3); // ListAssert of User |
| 167 | + * </code></pre> |
| 168 | + * @param assertFactory the {@link AssertFactory} to use to produce a narrowed |
| 169 | + * Assert for the type that it defines. |
160 | 170 | */
|
161 |
| - public <T> AbstractObjectAssert<?, T> convertTo(ParameterizedTypeReference<T> target) { |
| 171 | + public <ASSERT extends AbstractAssert<?, ?>> ASSERT convertTo(AssertFactory<?, ASSERT> assertFactory) { |
162 | 172 | isNotNull();
|
163 |
| - T value = convertToTargetType(target.getType()); |
164 |
| - return Assertions.assertThat(value); |
| 173 | + return assertFactory.createAssert(this::convertToTargetType); |
165 | 174 | }
|
166 | 175 |
|
167 | 176 | /**
|
|
0 commit comments