### Question:
HistoryController implements HistoryEndpoint { @Override @CheckPermissionByResourceCrn(action = AuthorizationResourceAction.SCALE_DATAHUB) public List<AutoscaleClusterHistoryResponse> getHistoryByCrn(@ResourceCrn String stackCrn, Integer historyCount) { return clusterService.findOneByStackCrnAndTenant(stackCrn, restRequestThreadLocalService.getCloudbreakTenant()) .map(cluster -> historyConverter.convertAllToJson(historyService.getHistory(cluster.getId(), historyCount))) .orElseThrow(NotFoundException.notFound("cluster", stackCrn)); }  @Override @CheckPermissionByResourceCrn(action = AuthorizationResourceAction.SCALE_DATAHUB) List<AutoscaleClusterHistoryResponse> getHistoryByCrn(@ResourceCrn String stackCrn, Integer historyCount); @Override @CheckPermissionByResourceName(action = AuthorizationResourceAction.SCALE_DATAHUB) List<AutoscaleClusterHistoryResponse> getHistoryByName(@ResourceName String stackName, Integer historyCount);  }### Answer:
@Test public void testGetHistoryWhenClusterNotFound() { when(clusterService.findOneByStackCrnAndTenant(testClusterCrn, tenant)).thenReturn(Optional.empty()); expectedException.expect(NotFoundException.class); expectedException.expectMessage("cluster 'crn:cdp:iam:us-west-1:%s:cluster:mockuser@cloudera.com' not found."); underTest.getHistoryByCrn(testClusterCrn, 10); }
@Test public void testGetHistoryWhenNoHistory() { when(clusterService.findOneByStackCrnAndTenant(testClusterCrn, tenant)).thenReturn(Optional.of(cluster)); when(historyService.getHistory(clusterId, 10)).thenReturn(List.of()); List<AutoscaleClusterHistoryResponse> historyResponses = underTest.getHistoryByCrn(testClusterCrn, 10); assertEquals("History Response size is 0", 0, historyResponses.size()); }
@Test public void testGetHistoryByCrnWhenHistoryFound() { List<History> mockHistoryResponses = List.of(new History(), new History()); when(clusterService.findOneByStackCrnAndTenant(testClusterCrn, tenant)).thenReturn(Optional.of(cluster)); when(historyService.getHistory(clusterId, 10)).thenReturn(mockHistoryResponses); when(historyConverter.convertAllToJson(any(List.class))).thenCallRealMethod(); List<AutoscaleClusterHistoryResponse> historyResponses = underTest.getHistoryByCrn(testClusterCrn, 10); assertEquals("History Response size is 2", 2, historyResponses.size()); }