SpaceRepository implements Comparable<SpaceRepository> { public static DateTime toDateTime(String repositoryId) { return REPO_ID_FORMATTER.parseDateTime(repositoryId); }  String id(); SpaceRepository withId(String id); String type(); SpaceRepository withType(String type); Map<String, Object> settings(); SpaceRepository withSettings(Map<String, Object> settings); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); @Override // ordered from latest to oldest repository int compareTo(SpaceRepository other); static String currentRepositoryId(); static String toRepositoryId(DateTime date); static DateTime toDateTime(String repositoryId); static String pastRepositoryId(String repositoryId, int weeks);  }
@Test public void testToDateTime() { assertEquals(DateTime.parse("2017-01-02T00:00:00.000Z"), SpaceRepository.toDateTime("2017-01")); assertEquals(DateTime.parse("2017-01-09T00:00:00.000Z"), SpaceRepository.toDateTime("2017-02")); assertEquals(DateTime.parse("2017-12-25T00:00:00.000Z"), SpaceRepository.toDateTime("2017-52")); assertEquals(DateTime.parse("2013-12-30T00:00:00.000Z"), SpaceRepository.toDateTime("2014-01")); assertEquals(DateTime.parse("2013-12-23T00:00:00.000Z"), SpaceRepository.toDateTime("2013-52")); }
@Test public void testToDateTimeFailsIfInvalidRepositoryId() { assertThrow(IllegalArgumentException.class, new Runnable() { @Override public void run() { SpaceRepository.toDateTime("toto"); } }); }