AmiPlugin extends AbstractEC2InstancePlugin { @Override protected void process(final EC2InstanceContext context) { if (!context.isTaupageAmi().orElse(false)) { violationSink.put( context.violation() .withType(WRONG_AMI) .withPluginFullyQualifiedClassName(AmiPlugin.class) .withMetaInfo(ImmutableMap.of( "ami_owner_id", context.getAmi().map(Image::getOwnerId).orElse(""), "ami_id", context.getAmiId().orElse(""), "ami_name", context.getAmi().map(Image::getName).orElse(""))) .build()); } } @Autowired  AmiPlugin(final EC2InstanceContextProvider contextProvider,
                     final ViolationSink violationSink);   }
@Test public void testIsTaupageAmi() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.of(true)); amiPlugin.process(mockContext); verify(mockContext).isTaupageAmi(); }
@Test public void testUnknownTaupageAmi() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.empty()); amiPlugin.process(mockContext); verify(mockContext).isTaupageAmi(); verify(mockContext).getAmiId(); verify(mockContext).violation(); verify(mockContext, times(2)).getAmi(); verify(mockViolationSink).put(argThat(hasType(WRONG_AMI))); }
@Test public void testIsNotTaupageAmi() throws Exception { when(mockContext.isTaupageAmi()).thenReturn(Optional.of(false)); amiPlugin.process(mockContext); verify(mockContext).isTaupageAmi(); verify(mockContext).getAmiId(); verify(mockContext).violation(); verify(mockContext, times(2)).getAmi(); verify(mockViolationSink).put(argThat(hasType(WRONG_AMI))); }