StorageStatsResource { public List<SpaceStatsDTO> getStorageProviderByDay(final String account, final String storeId, final Date date) { final long time = date.getTime(); final long msSoFarToday = time % ONE_DAY_IN_MS; final long msLeftToday = ONE_DAY_IN_MS - msSoFarToday; final Date start = new Date(time - msSoFarToday); final Date end = new Date(time + msLeftToday); final List<Object[]> list = this.spaceStatsRepo.getByAccountIdAndStoreIdAndDay(account, storeId, start, end); final List<SpaceStatsDTO> dtos = new ArrayList<>(list.size()); for (final Object[] s : list) { dtos.add(new SpaceStatsDTO(start, s[1].toString(), s[2].toString(), s[3].toString(), ((BigDecimal) s[4]).longValue(), ((BigDecimal) s[5]).longValue())); } return dtos; } @Autowired  StorageStatsResource(JpaSpaceStatsRepo spaceStatsRepo); List<SpaceStatsDTO> getSpaceStats(String accountId,
                                             String storeId,
                                             String spaceId,
                                             Date start,
                                             Date end,
                                             GroupBy groupBy); List<StoreStatsDTO> getStorageProviderStats(String account,
                                                       String storeId,
                                                       Date start,
                                                       Date end,
                                                       GroupBy groupBy); List<SpaceStatsDTO> getStorageProviderByDay(final String account,
                                                       final String storeId,
                                                       final Date date);  }
@Test public void testGetStorageStats() throws Exception { spaceStatsRepo = mock(JpaSpaceStatsRepo.class); final String accountId = "account-id"; final String storeId = "id"; DateTimeFormatter format = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss z").withZoneUTC(); final Date date = format.parseDateTime("2019-12-31 12:00:00 UTC").toDate(); final Capture<Date> captureStart = Capture.newInstance(); final Capture<Date> captureEnd = Capture.newInstance(); expect(spaceStatsRepo.getByAccountIdAndStoreIdAndDay(eq(accountId), eq(storeId), capture(captureStart), capture(captureEnd))).andReturn(new ArrayList<>()); replay(spaceStatsRepo); final StorageStatsResource resource = new StorageStatsResource(spaceStatsRepo); resource.getStorageProviderByDay(accountId, storeId, date); verify(spaceStatsRepo); final Date start = captureStart.getValue(); final Date end = captureEnd.getValue(); assertEquals("Start date should be 00:00:00 GMT of the next day as input date", "2019-12-31 00:00:00 UTC", format.print(start.getTime())); assertEquals("End date should be 00:00:00 GMT of the next day as input date", "2020-01-01 00:00:00 UTC", format.print(end.getTime())); }