|
6 | 6 | import java.lang.reflect.Type; |
7 | 7 | import java.time.temporal.Temporal; |
8 | 8 | import java.util.ArrayList; |
9 | | -import java.util.Arrays; |
10 | 9 | import java.util.Date; |
11 | 10 | import java.util.List; |
12 | 11 | import java.util.Map; |
13 | 12 | import java.util.TreeMap; |
| 13 | +import java.util.stream.Collectors; |
14 | 14 | import org.apache.commons.lang3.StringUtils; |
15 | 15 | import org.apache.commons.lang3.reflect.FieldUtils; |
16 | 16 | import org.apache.commons.logging.Log; |
@@ -95,7 +95,7 @@ private static MockHttpServletRequestBuilder buildFormFields(Object form, MockHt |
95 | 95 | } |
96 | 96 |
|
97 | 97 | private static Map<String, String> getFormFields(Object form, Map<String, String> formFields, String path) { |
98 | | - final List<Field> fields = form != null ? Arrays.asList(FieldUtils.getAllFields(form.getClass())) : new ArrayList<>(); |
| 98 | + final List<Field> fields = form != null ? getAllNonSyntheticFields(form) : new ArrayList<>(); |
99 | 99 | for (Field field : fields) { |
100 | 100 | final Class<?> fieldType = field.getType(); |
101 | 101 | final Object fieldValue = getFieldValue(form, field); |
@@ -134,6 +134,14 @@ private static Map<String, String> getFormFields(Object form, Map<String, String |
134 | 134 | return formFields; |
135 | 135 | } |
136 | 136 |
|
| 137 | + private static List<Field> getAllNonSyntheticFields(Object form) { |
| 138 | + return FieldUtils.getAllFieldsList(form.getClass()) |
| 139 | + .stream() |
| 140 | + // Only retrieve non synthetic fields to ignore JaCoCo's ones (https://github.com/f-lopes/spring-mvc-test-utils/issues/10) |
| 141 | + .filter(field -> !field.isSynthetic()) |
| 142 | + .collect(Collectors.toList()); |
| 143 | + } |
| 144 | + |
137 | 145 | private static Map<?, ?> getMap(Object fieldValue, Class<?> type) { |
138 | 146 | return Map.class.isAssignableFrom(type) ? (Map) fieldValue : null; |
139 | 147 | } |
|
0 commit comments