GetAsyncOperationPlugin implements IPlugin { @Override public void load() throws PluginException { try { IBootstrapItem<String> item = new BootstrapItem("CreateGetAsyncOperationActor"); item .process(() -> { try { IKey actorKey = Keys.getOrAdd(GetAsyncOperationActor.class.getCanonicalName()); IOC.register(actorKey, new ApplyFunctionToArgumentsStrategy( (args) -> { try { return new GetAsyncOperationActor((IObject) args[0]); } catch (GetAsyncOperationActorException e) { throw new RuntimeException("Can't create GetAsyncOperationActor with params: " + Arrays.toString(args), e); } } )); } catch (ResolutionException e) { throw new ActionExecuteException("GetAsyncOperationActor plugin can't load: can't get GetAsyncOperationActor key", e); } catch (InvalidArgumentException e) { throw new ActionExecuteException("GetAsyncOperationActor plugin can't load: can't create strategy", e); } catch (RegistrationException e) { throw new ActionExecuteException("GetAsyncOperationActor plugin can't load: can't register new strategy", e); } }); bootstrap.add(item); } catch (Exception e) { throw new PluginException("Can't load GetAsyncOperationPlugin", e); } } GetAsyncOperationPlugin(final IBootstrap<IBootstrapItem<String>> bootstrap); @Override void load();  }
@Test public void ShouldCorrectLoadPlugin() throws Exception { IKey actorKey = mock(IKey.class); when(Keys.getOrAdd(eq(GetAsyncOperationActor.class.getCanonicalName()))).thenReturn(actorKey); BootstrapItem bootstrapItem = mock(BootstrapItem.class); whenNew(BootstrapItem.class).withArguments("CreateGetAsyncOperationActor").thenReturn(bootstrapItem); when(bootstrapItem.after(anyString())).thenReturn(bootstrapItem); when(bootstrapItem.before(anyString())).thenReturn(bootstrapItem); plugin.load(); verifyNew(BootstrapItem.class).withArguments("CreateGetAsyncOperationActor"); ArgumentCaptor<IPoorAction> actionArgumentCaptor = ArgumentCaptor.forClass(IPoorAction.class); verify(bootstrapItem).process(actionArgumentCaptor.capture()); ArgumentCaptor<ApplyFunctionToArgumentsStrategy> createNewInstanceStrategyArgumentCaptor = ArgumentCaptor.forClass(ApplyFunctionToArgumentsStrategy.class); actionArgumentCaptor.getValue().execute(); verifyStatic(); IOC.register(eq(actorKey), createNewInstanceStrategyArgumentCaptor.capture()); GetAsyncOperationActor actor = mock(GetAsyncOperationActor.class); whenNew(GetAsyncOperationActor.class).withAnyArguments().thenReturn(actor); verify(bootstrap).add(bootstrapItem); }
@Test(expected = PluginException.class) public void ShouldThrowPluginException_When_BootstrapItemThrowsException() throws Exception { whenNew(BootstrapItem.class).withArguments("GetFormActorPlugin").thenThrow(new InvalidArgumentException("")); plugin.load(); }