Skip to content

Commit bf7737f

Browse files
committed
WW-5352 Add unit test coverage for generics
1 parent f106b20 commit bf7737f

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

core/src/test/java/org/apache/struts2/interceptor/parameter/StrutsParameterAnnotationTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.HashMap;
3131
import java.util.HashSet;
32+
import java.util.List;
3233
import java.util.Map;
3334

3435
import static org.assertj.core.api.Assertions.assertThat;
@@ -199,6 +200,41 @@ public void publicNestedPojoDepthTwoMethod() {
199200
assertThat(threadAllowlist.getAllowlist()).containsExactly(Pojo.class);
200201
}
201202

203+
@Test
204+
public void publicPojoListDepthOne() {
205+
testParameter(new FieldAction(), "publicPojoListDepthOne[0].key", false);
206+
}
207+
208+
@Test
209+
public void publicPojoListDepthTwo() {
210+
testParameter(new FieldAction(), "publicPojoListDepthTwo[0].key", true);
211+
assertThat(threadAllowlist.getAllowlist()).containsExactlyInAnyOrder(List.class, Pojo.class);
212+
}
213+
214+
@Test
215+
public void publicPojoMapDepthTwo() {
216+
testParameter(new FieldAction(), "publicPojoMapDepthTwo['a'].key", true);
217+
assertThat(threadAllowlist.getAllowlist()).containsExactlyInAnyOrder(Map.class, String.class, Pojo.class);
218+
}
219+
220+
@Test
221+
public void publicPojoListDepthOneMethod() {
222+
testParameter(new MethodAction(), "publicPojoListDepthOne[0].key", false);
223+
}
224+
225+
@Test
226+
public void publicPojoListDepthTwoMethod() {
227+
testParameter(new MethodAction(), "publicPojoListDepthTwo[0].key", true);
228+
assertThat(threadAllowlist.getAllowlist()).containsExactlyInAnyOrder(List.class, Pojo.class);
229+
}
230+
231+
@Test
232+
public void publicPojoMapDepthTwoMethod() {
233+
testParameter(new MethodAction(), "publicPojoMapDepthTwo['a'].key", true);
234+
assertThat(threadAllowlist.getAllowlist()).containsExactlyInAnyOrder(Map.class, String.class, Pojo.class);
235+
}
236+
237+
202238
class FieldAction {
203239
@StrutsParameter
204240
private String privateStr;
@@ -219,6 +255,15 @@ class FieldAction {
219255

220256
@StrutsParameter(depth = 2)
221257
public Pojo publicPojoDepthTwo;
258+
259+
@StrutsParameter(depth = 1)
260+
public List<Pojo> publicPojoListDepthOne;
261+
262+
@StrutsParameter(depth = 2)
263+
public List<Pojo> publicPojoListDepthTwo;
264+
265+
@StrutsParameter(depth = 2)
266+
public Map<String, Pojo> publicPojoMapDepthTwo;
222267
}
223268

224269
class MethodAction {
@@ -257,6 +302,21 @@ public Pojo getPublicPojoDepthOne() {
257302
public Pojo getPublicPojoDepthTwo() {
258303
return null;
259304
}
305+
306+
@StrutsParameter(depth = 1)
307+
public List<Pojo> getPublicPojoListDepthOne() {
308+
return null;
309+
}
310+
311+
@StrutsParameter(depth = 2)
312+
public List<Pojo> getPublicPojoListDepthTwo() {
313+
return null;
314+
}
315+
316+
@StrutsParameter(depth = 2)
317+
public Map<String, Pojo> getPublicPojoMapDepthTwo() {
318+
return null;
319+
}
260320
}
261321

262322
class Pojo {

0 commit comments

Comments
 (0)