Skip to content

Commit b8a6c5e

Browse files
committed
Release 2.2.1: ignore synthetic fields (fixes #10)
2 parents 2c2e96d + 30c68d1 commit b8a6c5e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Spring MVC Test utils
22

33
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1e521e339dc446328b7ccc52faaa7648)](https://www.codacy.com/app/f-lopes/spring-mvc-test-utils?utm_source=github.com&utm_medium=referral&utm_content=f-lopes/spring-mvc-test-utils&utm_campaign=badger)
4-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.florianlopes/spring-mvc-test-utils/badge.svg)](https://search.maven.org/#artifactdetails%7Cio.florianlopes%7Cspring-mvc-test-utils%7C2.2.0%7Cjar)
4+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.florianlopes/spring-mvc-test-utils/badge.svg)](https://search.maven.org/#artifactdetails%7Cio.florianlopes%7Cspring-mvc-test-utils%7C2.2.1%7Cjar)
55
[![CircleCI](https://circleci.com/gh/f-lopes/spring-mvc-test-utils/tree/master.svg?style=svg&circle-token=b34b191c4f183c701aee405ba6dca66c9f277d49)](https://circleci.com/gh/f-lopes/spring-mvc-test-utils/tree/master)
66
[![codecov](https://codecov.io/gh/f-lopes/spring-mvc-test-utils/branch/master/graph/badge.svg?token=2yY70RB1tw)](https://codecov.io/gh/f-lopes/spring-mvc-test-utils)
77
[![Dependency Status](https://www.versioneye.com/user/projects/57e036e36dfcd0003e7f55c3/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/57e036e36dfcd0003e7f55c3)
@@ -19,7 +19,7 @@ Add this dependency to your pom.xml file:
1919
<dependency>
2020
<groupId>io.florianlopes</groupId>
2121
<artifactId>spring-mvc-test-utils</artifactId>
22-
<version>2.2.0</version>
22+
<version>2.2.1</version>
2323
<scope>test</scope>
2424
</dependency>
2525
```

src/main/java/io/florianlopes/spring/test/web/servlet/request/MockMvcRequestBuilderUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import java.lang.reflect.Type;
77
import java.time.temporal.Temporal;
88
import java.util.ArrayList;
9-
import java.util.Arrays;
109
import java.util.Date;
1110
import java.util.List;
1211
import java.util.Map;
1312
import java.util.TreeMap;
13+
import java.util.stream.Collectors;
1414
import org.apache.commons.lang3.StringUtils;
1515
import org.apache.commons.lang3.reflect.FieldUtils;
1616
import org.apache.commons.logging.Log;
@@ -95,7 +95,7 @@ private static MockHttpServletRequestBuilder buildFormFields(Object form, MockHt
9595
}
9696

9797
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<>();
9999
for (Field field : fields) {
100100
final Class<?> fieldType = field.getType();
101101
final Object fieldValue = getFieldValue(form, field);
@@ -134,6 +134,14 @@ private static Map<String, String> getFormFields(Object form, Map<String, String
134134
return formFields;
135135
}
136136

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+
137145
private static Map<?, ?> getMap(Object fieldValue, Class<?> type) {
138146
return Map.class.isAssignableFrom(type) ? (Map) fieldValue : null;
139147
}

0 commit comments

Comments
 (0)