ImageStreamService { public TagEvent newerTag(TagEvent tag1, TagEvent tag2) { Date tag1Date = extractDate(tag1); Date tag2Date = extractDate(tag2); if(tag1Date == null) { return tag2; } if(tag2Date == null) { return tag1; } return tag1Date.compareTo(tag2Date) > 0 ? tag1 : tag2; } ImageStreamService(OpenShiftClient client, Logger log); void appendImageStreamResource(ImageName imageName, File target); TagEvent newerTag(TagEvent tag1, TagEvent tag2); static final String DATE_FORMAT; }
@Test public void should_return_newer_tag() throws Exception { ImageStreamService service = new ImageStreamService(client, log); TagEvent oldTag = new TagEvent("2018-03-09T03:27:05Z\n", null, null, null); TagEvent latestTag = new TagEvent("2018-03-09T03:28:05Z\n", null, null, null); TagEvent resultedTag = service.newerTag(oldTag, latestTag); Assert.assertEquals(latestTag, resultedTag); }
@Test public void should_return_first_tag() throws Exception { ImageStreamService service = new ImageStreamService(client, log); TagEvent first = new TagEvent("2018-03-09T03:27:05Z\n", null, null, null); TagEvent latestTag = null; TagEvent resultedTag = service.newerTag(first, latestTag); Assert.assertEquals(first, resultedTag); }