@Test public void shouldGiveSpecifiedFieldsInformationOfVideo() throws Exception { String[] fields = new String[]{"id", "title", "length"}; String expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178}"; when(fieldJsonMapper.toJson(any(Video.class), eq(fields))).thenReturn(expectedDetails); String actualFieldsDetails = resource.getDetails(2, fields); assertEquals(expectedDetails, actualFieldsDetails); }
public String getDetails(Integer id, String... fields) throws Exception { if (fields.length == 0) { return videos.get(id).toString(); } return fieldJsonMapper.toJson(videos.get(id), fields); }
VideoResource { public String getDetails(Integer id, String... fields) throws Exception { if (fields.length == 0) { return videos.get(id).toString(); } return fieldJsonMapper.toJson(videos.get(id), fields); } }
VideoResource { public String getDetails(Integer id, String... fields) throws Exception { if (fields.length == 0) { return videos.get(id).toString(); } return fieldJsonMapper.toJson(videos.get(id), fields); } VideoResource(FieldJsonMapper fieldJsonMapper, Map<Integer, Video> videos); }
VideoResource { public String getDetails(Integer id, String... fields) throws Exception { if (fields.length == 0) { return videos.get(id).toString(); } return fieldJsonMapper.toJson(videos.get(id), fields); } VideoResource(FieldJsonMapper fieldJsonMapper, Map<Integer, Video> videos); String getDetails(Integer id, String... fields); }
VideoResource { public String getDetails(Integer id, String... fields) throws Exception { if (fields.length == 0) { return videos.get(id).toString(); } return fieldJsonMapper.toJson(videos.get(id), fields); } VideoResource(FieldJsonMapper fieldJsonMapper, Map<Integer, Video> videos); String getDetails(Integer id, String... fields);  }