OaiPmhRepository { public static Date granulate(Granularity g, Date d) { switch (g) { case SECOND: { Calendar c = Calendar.getInstance(); c.setTimeZone(OaiPmhUtil.newDateFormat().getTimeZone()); c.setTime(d); c.set(Calendar.MILLISECOND, 0); return c.getTime(); } case DAY: { final Calendar c = Calendar.getInstance(); c.setTimeZone(OaiPmhUtil.newDateFormat().getTimeZone()); c.setTime(d); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); } default: return unexhaustiveMatch(); } }  abstract Granularity getRepositoryTimeGranularity(); abstract String getRepositoryName(); abstract String getRepositoryId(); abstract OaiPmhDatabase getPersistence(); abstract String getAdminEmail(); abstract String saveQuery(ResumableQuery query); abstract Option<ResumableQuery> getSavedQuery(String resumptionToken); abstract int getResultLimit(); abstract List<MetadataProvider> getRepositoryMetadataProviders(); Date currentDate(); final List<MetadataProvider> getMetadataProviders(); void addItem(MediaPackage mp); XmlGen selectVerb(Params p); Option<MetadataProvider> getMetadataProvider(final String metadataPrefix); static Date granulate(Granularity g, Date d);  }
@Test public void testDateAdaption() { final Date d = utcDate(2012, 5, 24, 13, 24, 0); final Date expect = utcDate(2012, 5, 24, 0, 0, 0); assertEquals(expect, OaiPmhRepository.granulate(Granularity.DAY, d)); }