@Override public Object getSource() { return super.getSource(); } }
/** * Convenience method that returns the * {@link InteractionEvent#getAdvisorClass() advisor class} of the wrapped * {@link #getInteractionEvent() interaction event}. * * @return */ public Class<?> getAdvisorClass() { return interactionEvent.getAdvisorClass(); }
/** * The reason message, if any, that this interaction may have been vetoed or * otherwise disallowed. * * <p> * This message should be overridden by subclasses for containing the Reason, the Identifier and any other relevant context information. * * @return */ public String getReasonMessage() { if (this.getIdentifier() != null) { return String.format("Reason: %s. Identifier: %s", this.getReason(), this.getIdentifier()); } else { return String.format("Reason: %s", this.getReason()); } }
@Test public void afterAdvisedShouldReturnAdvisorClass() { interactionEvent = new InteractionEvent(source, identifier) { private static final long serialVersionUID = 1L; }; interactionEvent.advised("some reason", advisorClass); assertEquals(interactionEvent.getAdvisorClass(), advisorClass); }
/** * Wraps a {@link InteractionEvent#isVeto() vetoing} * {@link InteractionEvent} in a corresponding {@link InteractionException}, * and returns it. */ private InteractionException toException(final InteractionEvent interactionEvent) { if (!interactionEvent.isVeto()) { throw new IllegalArgumentException("Provided interactionEvent must be a veto"); } if (interactionEvent instanceof ValidityEvent) { final ValidityEvent validityEvent = (ValidityEvent) interactionEvent; return new InvalidException(validityEvent); } if (interactionEvent instanceof VisibilityEvent) { final VisibilityEvent visibilityEvent = (VisibilityEvent) interactionEvent; return new HiddenException(visibilityEvent); } if (interactionEvent instanceof UsabilityEvent) { final UsabilityEvent usabilityEvent = (UsabilityEvent) interactionEvent; return new DisabledException(usabilityEvent); } throw new IllegalArgumentException("Provided interactionEvent must be a VisibilityEvent, UsabilityEvent or a ValidityEvent"); }
/** * Convenience method that returns the * {@link InteractionEvent#getIdentifier() identifier} of the wrapped * {@link #getInteractionEvent() interaction event}. * * @return */ public Identifier getIdentifier() { return interactionEvent.getIdentifier(); }
/** * Whether this interaction has been vetoed (meaning that * {@link #getReason()} and {@link #getAdvisorClass()} will both be non- * <tt>null</tt> and the {@link #getReason() reason} non-empty.) * * <p> * The interpretation of this depends on the subclass: * <ul> * <li>for {@link VisibilityEvent}, a veto means that the feature (property, * collection, action) is hidden</li> * <li>for {@link UsabilityEvent}, a veto means that the feature is disabled * </li> * <li>for {@link ValidityEvent}, a veto means that the proposed * modification (property value, object added/removed, action argument) is * invalid</li> * </ul> */ public boolean isVeto() { return getReason() != null && getReason().length() > 0; }
/** * Returns the contained {@link InteractionEvent}, if necessary updated with * the {@link #advise(String, InteractionAdvisor) advice} of the * interactions. * * <p> * That is, if still {@link State#ADVISING advising}, then copies over the * details from this result into the contained {@link InteractionEvent}, and * flips into {@link State#ADVISED advised (done)}. * * @return */ public InteractionEvent getInteractionEvent() { if (state == State.ADVISING) { interactionEvent.advised(getReason(), getAdvisorClass()); state = State.ADVISED; } return interactionEvent; }
@Test public void getClassName() { interactionEvent = new InteractionEvent(source, identifier) { private static final long serialVersionUID = 1L; }; assertThat(interactionEvent.getClassName(), equalTo("CustomerOrder")); }
@Test public void getClassNaturalName() { interactionEvent = new InteractionEvent(source, identifier) { private static final long serialVersionUID = 1L; }; assertThat(interactionEvent.getClassNaturalName(), equalTo("Customer Order")); }
@Test public void getMember() { interactionEvent = new InteractionEvent(source, identifier) { private static final long serialVersionUID = 1L; }; assertThat(interactionEvent.getMemberName(), equalTo("cancelOrder")); }
private void notifyListenersAndVetoIfRequired(final InteractionResult interactionResult) { final InteractionEvent interactionEvent = interactionResult.getInteractionEvent(); notifyListeners(interactionEvent); if (interactionEvent.isVeto()) { throw toException(interactionEvent); } }
@Test public void getIdentifier() { interactionEvent = new InteractionEvent(source, identifier) { private static final long serialVersionUID = 1L; }; assertThat(interactionEvent.getIdentifier(), is(identifier)); }
/** * Whether this interaction has been vetoed (meaning that * {@link #getReason()} and {@link #getAdvisorClass()} will both be non- * <tt>null</tt> and the {@link #getReason() reason} non-empty.) * * <p> * The interpretation of this depends on the subclass: * <ul> * <li>for {@link VisibilityEvent}, a veto means that the feature (property, * collection, action) is hidden</li> * <li>for {@link UsabilityEvent}, a veto means that the feature is disabled * </li> * <li>for {@link ValidityEvent}, a veto means that the proposed * modification (property value, object added/removed, action argument) is * invalid</li> * </ul> */ public boolean isVeto() { return getReason() != null && getReason().length() > 0; }
@Override public Object getSource() { return super.getSource(); }
@Test public void shouldInitiallyNotVeto() { interactionEvent = new InteractionEvent(source, identifier) { private static final long serialVersionUID = 1L; }; assertThat(interactionEvent.isVeto(), is(false)); }
@Test public void getSource() { interactionEvent = new InteractionEvent(source, identifier) { private static final long serialVersionUID = 1L; }; assertThat(interactionEvent.getSource(), is(source)); }