PieroneTagProviderImpl implements PieroneTagProvider { @Override public Optional<TagSummary> apply(final EC2InstanceContext context) { return context.getSource().flatMap(cache::getUnchecked); } PieroneTagProviderImpl(final Function<String, PieroneOperations> pieroneOperationsProvider); @Override Optional<TagSummary> apply(final EC2InstanceContext context);  }
@Test public void testPieroneTagFound() throws Exception { when(ec2InstanceContextMock.getSource()).thenReturn(Optional.of("pierone.example.org/team/artifact:tag")); final Map<String, TagSummary> tagsMap = newHashMap(); final TagSummary tagSummary = new TagSummary("name", ZonedDateTime.now(), "me"); tagsMap.put("tag", tagSummary); when(pieroneOperationsMock.listTags(eq("team"), eq("artifact"))).thenReturn(tagsMap); final Optional<TagSummary> result = pieroneTagProvider.apply(ec2InstanceContextMock); assertThat(result).isPresent(); verify(ec2InstanceContextMock).getSource(); verify(pieroneOperationsMock).listTags(eq("team"), eq("artifact")); }
@Test public void testPieroneTagNotFound() throws Exception { when(ec2InstanceContextMock.getSource()).thenReturn(Optional.of("opensource.example.org/team/artifact:tag")); final Optional<TagSummary> result = pieroneTagProvider.apply(ec2InstanceContextMock); assertThat(result).isEmpty(); verify(ec2InstanceContextMock).getSource(); }