@Test public void linkToSubscription_whenNotLinked() { final EntityService entityService = Replicant.context().getEntityService(); final Entity entity = safeAction( () -> entityService.findOrCreateEntity( "MyEntity", String.class, ValueUtil.randomInt() ) ); final Subscription subscription1 = createSubscription( new ChannelAddress( 1, 0, 1 ) ); safeAction( () -> entity.linkToSubscription( subscription1 ) ); final IllegalStateException exception = expectThrows( IllegalStateException.class, () -> safeAction( () -> entity.linkToSubscription( subscription1 ) ) ); assertEquals( exception.getMessage(), "Replicant-0080: Entity.linkToSubscription invoked on Entity MyEntity passing subscription 1.0.1 but entity is already linked to subscription." ); }
void linkToSubscription( @Nonnull final Subscription subscription ) { if ( Replicant.shouldCheckInvariants() ) { invariant( () -> null == subscription.findEntityByTypeAndId( getType(), getId() ), () -> "Replicant-0080: Entity.linkToSubscription invoked on Entity " + this + " passing subscription " + subscription.getAddress() + " but entity is " + "already linked to subscription." ); } linkEntityToSubscription( subscription ); subscription.linkSubscriptionToEntity( this ); }
Entity extends ReplicantService { void linkToSubscription( @Nonnull final Subscription subscription ) { if ( Replicant.shouldCheckInvariants() ) { invariant( () -> null == subscription.findEntityByTypeAndId( getType(), getId() ), () -> "Replicant-0080: Entity.linkToSubscription invoked on Entity " + this + " passing subscription " + subscription.getAddress() + " but entity is " + "already linked to subscription." ); } linkEntityToSubscription( subscription ); subscription.linkSubscriptionToEntity( this ); } }
Entity extends ReplicantService { void linkToSubscription( @Nonnull final Subscription subscription ) { if ( Replicant.shouldCheckInvariants() ) { invariant( () -> null == subscription.findEntityByTypeAndId( getType(), getId() ), () -> "Replicant-0080: Entity.linkToSubscription invoked on Entity " + this + " passing subscription " + subscription.getAddress() + " but entity is " + "already linked to subscription." ); } linkEntityToSubscription( subscription ); subscription.linkSubscriptionToEntity( this ); } Entity( @Nullable final ReplicantContext context,
          @Nullable final String name,
          @Nonnull final Class<?> type,
          final int id ); }
Entity extends ReplicantService { void linkToSubscription( @Nonnull final Subscription subscription ) { if ( Replicant.shouldCheckInvariants() ) { invariant( () -> null == subscription.findEntityByTypeAndId( getType(), getId() ), () -> "Replicant-0080: Entity.linkToSubscription invoked on Entity " + this + " passing subscription " + subscription.getAddress() + " but entity is " + "already linked to subscription." ); } linkEntityToSubscription( subscription ); subscription.linkSubscriptionToEntity( this ); } Entity( @Nullable final ReplicantContext context,
          @Nullable final String name,
          @Nonnull final Class<?> type,
          final int id ); @Nonnull String getName(); @Nonnull Class<?> getType(); int getId(); @Nonnull Object getUserObject(); @Observable( name = "userObject" ) @Nullable Object maybeUserObject(); @Nonnull @Observable( expectSetter = false ) Collection<Subscription> getSubscriptions(); @Override String toString(); }
Entity extends ReplicantService { void linkToSubscription( @Nonnull final Subscription subscription ) { if ( Replicant.shouldCheckInvariants() ) { invariant( () -> null == subscription.findEntityByTypeAndId( getType(), getId() ), () -> "Replicant-0080: Entity.linkToSubscription invoked on Entity " + this + " passing subscription " + subscription.getAddress() + " but entity is " + "already linked to subscription." ); } linkEntityToSubscription( subscription ); subscription.linkSubscriptionToEntity( this ); } Entity( @Nullable final ReplicantContext context,
          @Nullable final String name,
          @Nonnull final Class<?> type,
          final int id ); @Nonnull String getName(); @Nonnull Class<?> getType(); int getId(); @Nonnull Object getUserObject(); @Observable( name = "userObject" ) @Nullable Object maybeUserObject(); @Nonnull @Observable( expectSetter = false ) Collection<Subscription> getSubscriptions(); @Override String toString();  }