@Test public void getUserObject_whenNull() { final EntityService entityService = Replicant.context().getEntityService(); final Entity entity = safeAction( () -> entityService.findOrCreateEntity( ValueUtil.randomString(), A.class, ValueUtil.randomInt() ) ); final IllegalStateException exception = expectThrows( IllegalStateException.class, () -> safeAction( () -> assertNull( entity.getUserObject() ) ) ); assertEquals( exception.getMessage(), "Replicant-0071: Entity.getUserObject() invoked when no userObject present" ); }
@Nonnull public Object getUserObject() { final Object userObject = maybeUserObject(); if ( Replicant.shouldCheckApiInvariants() ) { apiInvariant( () -> null != userObject, () -> "Replicant-0071: Entity.getUserObject() invoked when no userObject present" ); } assert null != userObject; return userObject; }
Entity extends ReplicantService { @Nonnull public Object getUserObject() { final Object userObject = maybeUserObject(); if ( Replicant.shouldCheckApiInvariants() ) { apiInvariant( () -> null != userObject, () -> "Replicant-0071: Entity.getUserObject() invoked when no userObject present" ); } assert null != userObject; return userObject; } }
Entity extends ReplicantService { @Nonnull public Object getUserObject() { final Object userObject = maybeUserObject(); if ( Replicant.shouldCheckApiInvariants() ) { apiInvariant( () -> null != userObject, () -> "Replicant-0071: Entity.getUserObject() invoked when no userObject present" ); } assert null != userObject; return userObject; } Entity( @Nullable final ReplicantContext context,
          @Nullable final String name,
          @Nonnull final Class<?> type,
          final int id ); }
Entity extends ReplicantService { @Nonnull public Object getUserObject() { final Object userObject = maybeUserObject(); if ( Replicant.shouldCheckApiInvariants() ) { apiInvariant( () -> null != userObject, () -> "Replicant-0071: Entity.getUserObject() invoked when no userObject present" ); } assert null != userObject; return userObject; } 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 { @Nonnull public Object getUserObject() { final Object userObject = maybeUserObject(); if ( Replicant.shouldCheckApiInvariants() ) { apiInvariant( () -> null != userObject, () -> "Replicant-0071: Entity.getUserObject() invoked when no userObject present" ); } assert null != userObject; return userObject; } 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();  }