### Question:
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);  }### Answer:
@Test void shouldGiveVideoDetailsById() throws Exception { var actualDetails = resource.getDetails(1); var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178,\"description\": " + "\"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\",}"; Assertions.assertEquals(expectedDetails, actualDetails); }
@Test void shouldGiveSpecifiedFieldsInformationOfVideo() throws Exception { var fields = new String[]{"id", "title", "length"}; var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178}"; Mockito.when(fieldJsonMapper.toJson(Matchers.any(Video.class), Matchers.eq(fields))).thenReturn(expectedDetails); var actualFieldsDetails = resource.getDetails(2, fields); Assertions.assertEquals(expectedDetails, actualFieldsDetails); }
@Test public void shouldGiveVideoDetailsById() throws Exception { String actualDetails = resource.getDetails(1); String expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178,\"description\": " + "\"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\",}"; assertEquals(expectedDetails, actualDetails); }
@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); }