@Test public void cacheAndReset() { Map<String, Integer> stats = service.getSummaryStats(); assertThat(stats.get("approvalCount"), is(4)); assertThat(stats.get("userCount"), is(2)); assertThat(stats.get("clientCount"), is(3)); Mockito.when(approvedSiteService.getAll()) .thenReturn(Sets.newHashSet(ap1, ap2, ap3, ap4, ap5, ap6)); Map<String, Integer> stats2 = service.getSummaryStats(); // cache should remain the same due to memoized functions assertThat(stats2.get("approvalCount"), is(4)); assertThat(stats2.get("userCount"), is(2)); assertThat(stats2.get("clientCount"), is(3)); // reset the cache and make sure the count goes up service.resetCache(); Map<String, Integer> stats3 = service.getSummaryStats(); assertThat(stats3.get("approvalCount"), is(6)); assertThat(stats3.get("userCount"), is(2)); assertThat(stats3.get("clientCount"), is(4)); }
@Test public void calculateSummaryStats_empty() { Mockito.when(approvedSiteService.getAll()).thenReturn(new HashSet<ApprovedSite>()); Map<String, Integer> stats = service.getSummaryStats(); assertThat(stats.get("approvalCount"), is(0)); assertThat(stats.get("userCount"), is(0)); assertThat(stats.get("clientCount"), is(0)); }
@Test public void calculateByClientId_empty() { Mockito.when(approvedSiteService.getAll()).thenReturn(new HashSet<ApprovedSite>()); Map<Long, Integer> stats = service.getByClientId(); assertThat(stats.get(1L), is(0)); assertThat(stats.get(2L), is(0)); assertThat(stats.get(3L), is(0)); assertThat(stats.get(4L), is(0)); }
/** * Prepares a collection of ApprovedSite mocks to be returned from the approvedSiteService and a * collection of ClientDetailEntity mocks to be returned from the clientService. */ @Before public void prepare() { Mockito.reset(approvedSiteService, clientService); Mockito.when(ap1.getUserId()).thenReturn(userId1); Mockito.when(ap1.getClientId()).thenReturn(clientId1); Mockito.when(ap2.getUserId()).thenReturn(userId1); Mockito.when(ap2.getClientId()).thenReturn(clientId1); Mockito.when(ap3.getUserId()).thenReturn(userId2); Mockito.when(ap3.getClientId()).thenReturn(clientId2); Mockito.when(ap4.getUserId()).thenReturn(userId2); Mockito.when(ap4.getClientId()).thenReturn(clientId3); Mockito.when(ap5.getUserId()).thenReturn(userId2); Mockito.when(ap5.getClientId()).thenReturn(clientId1); Mockito.when(ap6.getUserId()).thenReturn(userId1); Mockito.when(ap6.getClientId()).thenReturn(clientId4); Mockito.when(approvedSiteService.getAll()).thenReturn(Sets.newHashSet(ap1, ap2, ap3, ap4)); Mockito.when(client1.getId()).thenReturn(1L); Mockito.when(client2.getId()).thenReturn(2L); Mockito.when(client3.getId()).thenReturn(3L); Mockito.when(client4.getId()).thenReturn(4L); Mockito.when(clientService.getAllClients()) .thenReturn(Sets.newHashSet(client1, client2, client3, client4)); Mockito.when(clientService.loadClientByClientId(clientId1)).thenReturn(client1); Mockito.when(clientService.loadClientByClientId(clientId2)).thenReturn(client2); Mockito.when(clientService.loadClientByClientId(clientId3)).thenReturn(client3); Mockito.when(clientService.loadClientByClientId(clientId4)).thenReturn(client4); }