### Question:
MockUtils { public static <T> T generateMockResponse(Class<T> responseClass, RequestContext ctx, Object... params ) { try { Generator generator = new Generator(); T responseObject = generateObject(responseClass, generator); return responseObject; } catch (Exception e) { throw new RuntimeException("Failed to generate response object: "+e.getMessage(), e); } }  static T generateMockResponse(Class<T> responseClass, RequestContext ctx, Object... params );  }### Answer:
@Test public void testMockSimple() { MyResult result = MockUtils.generateMockResponse(MyResult.class, mock(RequestContext.class)); checkResult(result); }
@Test public void testMockCollections() { MyResultWithCollections resultList = MockUtils.generateMockResponse(MyResultWithCollections.class, mock(RequestContext.class)); assertEquals("String", resultList.foo.substring(0, 6)); for (MyResult r: resultList.list) { checkResult(r); } for (String s: resultList.set) { assertEquals("String", s.substring(0, 6)); } for (Map.Entry<String, MyResult> me: resultList.map.entrySet()) { assertEquals("String", me.getKey().substring(0, 6)); checkResult(me.getValue()); } }
@Test public void testMockBadField() { String foo = MockUtils.generateMockResponse(String.class, mock(RequestContext.class)); assertEquals("String-1", foo); }