GetFirstNotNullRulePlugin implements IPlugin { @Override public void load() throws PluginException { try { IBootstrapItem<String> item = new BootstrapItem("GetFirstNotNullRulePlugin"); item .after("IOC") .after("wds_object") .before("starter") .process(() -> { try { IOC.resolve( Keys.getOrAdd(IResolveDependencyStrategy.class.getCanonicalName()), "getFirstNotNullRule", new GetFirstNotNullRule() ); } catch (ResolutionException e) { throw new ActionExecuteException( "GetFirstNotNullRule plugin can't load: can't get GetFirstNotNullRule key", e ); } }); bootstrap.add(item); } catch (InvalidArgumentException e) { throw new PluginException("Can't create BootstrapItem", e); } } GetFirstNotNullRulePlugin(IBootstrap<IBootstrapItem<String>> bootstrap); @Override void load();  }
@Test public void MustCorrectLoadPlugin() throws Exception { BootstrapItem bootstrapItem = mock(BootstrapItem.class); whenNew(BootstrapItem.class).withArguments("GetFirstNotNullRulePlugin").thenReturn(bootstrapItem); when(bootstrapItem.after(anyString())).thenReturn(bootstrapItem); when(bootstrapItem.before(anyString())).thenReturn(bootstrapItem); targetPlugin.load(); verifyNew(BootstrapItem.class).withArguments("GetFirstNotNullRulePlugin"); ArgumentCaptor<IPoorAction> actionArgumentCaptor = ArgumentCaptor.forClass(IPoorAction.class); verify(bootstrapItem).after("IOC"); verify(bootstrapItem).after("wds_object"); verify(bootstrapItem).before("starter"); verify(bootstrapItem).process(actionArgumentCaptor.capture()); verify(bootstrap).add(bootstrapItem); IKey strategyKey = mock(IKey.class); when(Keys.getOrAdd(IResolveDependencyStrategy.class.getCanonicalName())).thenReturn(strategyKey); GetFirstNotNullRule targetObject = mock(GetFirstNotNullRule.class); whenNew(GetFirstNotNullRule.class).withNoArguments().thenReturn(targetObject); actionArgumentCaptor.getValue().execute(); verifyStatic(); Keys.getOrAdd(IResolveDependencyStrategy.class.getCanonicalName()); verifyNew(GetFirstNotNullRule.class).withNoArguments(); verifyStatic(); IOC.resolve(strategyKey, "getFirstNotNullRule", targetObject); }
@Test(expected = PluginException.class) public void ShouldThrowPluginException_When_BootstrapItemThrowsException() throws Exception { whenNew(BootstrapItem.class).withArguments("GetFirstNotNullRulePlugin").thenThrow(new InvalidArgumentException("")); targetPlugin.load(); }