BootstrapPlugin implements IPlugin { @Override public final void load() throws PluginException { try { for (Method method : this.getClass().getMethods()) { if (null == method.getAnnotation(Item.class)) { continue; } bootstrap.add(new MethodBootstrapItem(this, method)); } } catch (InvalidArgumentException e) { throw new PluginException(e); } } protected  BootstrapPlugin(final IBootstrap bootstrap); @Override final void load();  }
@Test(expected = PluginException.class) public void Should_throwWhenPluginContainsInvalidMethods() throws Exception { IPlugin plugin = new BootstrapPlugin(bootstrapMock) { @BootstrapPlugin.Item("wrongItem") public void wrongItemMethod(int x) {} }; plugin.load(); }
@Test public void Should_createItemsForAnnotatedMethods() throws Exception { IPlugin plugin = new BootstrapPlugin(bootstrapMock) { @BootstrapPlugin.Item("item1") public void item1Method() { } @BootstrapPlugin.Item("item2") public void item2Method() { } public void notItemMethod() {} }; plugin.load(); verify(bootstrapMock, times(2)).add(itemArgumentCaptor.capture()); for (IBootstrapItem item : itemArgumentCaptor.getAllValues()) { assertTrue(item instanceof MethodBootstrapItem); } }