CapabilityHasNoDuplicatesCondition extends ConditionSupport implements CapabilityContextAware { @Override public CapabilityHasNoDuplicatesCondition setContext(final CapabilityContext context) { checkState(!isActive(), "Cannot contextualize when already bounded"); checkState(this.context == null, "Already contextualized with '" + this.context + "'"); this.context = context; return this; } CapabilityHasNoDuplicatesCondition(final EventManager eventManager); @Override CapabilityHasNoDuplicatesCondition setContext(final CapabilityContext context); @Override void doRelease(); @AllowConcurrentEvents @Subscribe void handle(final CapabilityEvent.Created event); @AllowConcurrentEvents @Subscribe void handle(final CapabilityEvent.AfterUpdate event); @AllowConcurrentEvents @Subscribe void handle(final CapabilityEvent.AfterRemove event); @Override String toString(); @Override String explainSatisfied(); @Override String explainUnsatisfied();  }
@Test public void standardLifecycle() { assertThat(underTest.isSatisfied(), is(false)); underTest.setContext(reference.context()); assertThat(underTest.isSatisfied(), is(false)); underTest.bind(); assertThat(underTest.isSatisfied(), is(true)); underTest.release(); InOrder inOrder = Mockito.inOrder(eventManager); inOrder.verify(eventManager).register(underTest); inOrder.verify(eventManager).unregister(underTest); inOrder.verifyNoMoreInteractions(); }
@Test public void duplicatesDetectedDuringBind() { underTest.setContext(reference.context()); when(descriptor.isDuplicated(context.id(), context.properties())).thenReturn(true); underTest.bind(); assertThat(underTest.isSatisfied(), is(false)); underTest.release(); }
@Test public void contextualizationFailsWhenAlreadyBounded() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Cannot contextualize when already bound"); underTest.setContext(reference.context()); underTest.bind(); underTest.setContext(reference.context()); }
@Test public void contextualizationFailsWhenAlreadyContextualized() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Already contextualized"); underTest.setContext(reference.context()); underTest.setContext(reference.context()); }