### Question:
RecentLogsRetriever { public List<ApplicationLog> getRecentLogs(CloudControllerClient client, String appName, LogsOffset offset) { List<ApplicationLog> appLogs = client.getRecentLogs(appName); if (offset == null) { return appLogs; } return appLogs.stream() .filter(appLog -> isLogNew(appLog, offset)) .collect(Collectors.toList()); }  List<ApplicationLog> getRecentLogsSafely(CloudControllerClient client, String appName, LogsOffset offset); List<ApplicationLog> getRecentLogs(CloudControllerClient client, String appName, LogsOffset offset);  }### Answer:
@Test void testGetRecentLogsWithError() { Mockito.when(client.getRecentLogs(APP_NAME)) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Something fails")); tester.test(() -> recentLogsRetriever.getRecentLogs(client, APP_NAME, null), new Expectation(Expectation.Type.EXCEPTION, "500 Something fails")); }
@Test void testGetRecentLogsWithNoPriorOffset() { Mockito.when(client.getRecentLogs(APP_NAME)) .thenReturn(List.of(createAppLog(1, ""))); assertEquals(List.of(createAppLog(1, "")), recentLogsRetriever.getRecentLogs(client, APP_NAME, null)); }
@Test void testGetRecentLogsWithOffsetReturnsNoLogs() { LogsOffset offset = createLogsOffset(1, ""); Mockito.when(client.getRecentLogs(APP_NAME)) .thenReturn(List.of(createAppLog(0, ""))); assertTrue(recentLogsRetriever.getRecentLogs(client, APP_NAME, offset) .isEmpty()); }
@Test void testGetRecentLogsWithOffsetSameMessageReturnsNoLogs() { LogsOffset offset = createLogsOffset(1, "msg"); Mockito.when(client.getRecentLogs(APP_NAME)) .thenReturn(List.of(createAppLog(1, "msg"))); assertTrue(recentLogsRetriever.getRecentLogs(client, APP_NAME, offset) .isEmpty()); }
@Test void testGetRecentLogsWithOffsetReturnsFilteredLogs() { LogsOffset offset = createLogsOffset(1, ""); Mockito.when(client.getRecentLogs(APP_NAME)) .thenReturn(List.of(createAppLog(1, ""), createAppLog(2, ""))); assertEquals(List.of(createAppLog(2, "")), recentLogsRetriever.getRecentLogs(client, APP_NAME, offset)); }
@Test void testGetRecentLogsWithOffsetSameTimestampReturnsFilteredLogs() { LogsOffset offset = createLogsOffset(1, "msg"); Mockito.when(client.getRecentLogs(APP_NAME)) .thenReturn(List.of(createAppLog(1, "msg"), createAppLog(1, "msg1"))); assertEquals(List.of(createAppLog(1, "msg1")), recentLogsRetriever.getRecentLogs(client, APP_NAME, offset)); }
@Test void testGetRecentLogsWithOffsetSameMessageReturnsFilteredLogs() { LogsOffset offset = createLogsOffset(1, "msg1"); Mockito.when(client.getRecentLogs(APP_NAME)) .thenReturn(List.of(createAppLog(1, "msg"), createAppLog(1, "msg1"))); assertEquals(List.of(createAppLog(1, "msg")), recentLogsRetriever.getRecentLogs(client, APP_NAME, offset)); }