ScopeCreationEventHandler implements IAction<IScope> { @Override public void execute(final IScope createdScope) throws ActionExecuteException, InvalidArgumentException { if (null == createdScope) { throw new InvalidArgumentException("Argument should not be null."); } try { IStrategyContainer container = new StrategyContainer(); createdScope.setValue(this.id, container); } catch (Exception e) { throw new ActionExecuteException("Execution error.", e); } } ScopeCreationEventHandler(final IKey id); @Override void execute(final IScope createdScope);  }
@Test public void checkHandlerExecution() throws Exception { IKey key = mock(IKey.class); IScope scope = mock(IScope.class); IAction handler = new ScopeCreationEventHandler(key); doNothing().when(scope).setValue(any(IKey.class), any(IStrategyContainer.class)); handler.execute(scope); verify(scope, times(1)).setValue(any(IKey.class), any(IStrategyContainer.class)); }
@Test (expected = InvalidArgumentException.class) public void checkInvalidArgumentExceptionOnHandlerExecution() throws Exception { IKey key = mock(IKey.class); IAction handler = new ScopeCreationEventHandler(key); handler.execute(null); fail(); }
@Test (expected = ActionExecuteException.class) public void checkObserverExecuteExceptionOnHandlerExecution() throws Exception { IKey key = mock(IKey.class); IScope scope = mock(IScope.class); IAction handler = new ScopeCreationEventHandler(key); doThrow(ActionExecuteException.class).when(scope).setValue(any(IKey.class), any(IStrategyContainer.class)); handler.execute(scope); fail(); }