SudoRetrieveThingStrategy extends AbstractThingCommandStrategy<SudoRetrieveThing> { @Override public boolean isDefined(final Context<ThingId> context, @Nullable final Thing thing, final SudoRetrieveThing command) { final boolean thingExists = Optional.ofNullable(thing) .map(t -> !t.isDeleted()) .orElse(false); return Objects.equals(context.getState(), command.getEntityId()) && thingExists; } SudoRetrieveThingStrategy(); @Override boolean isDefined(final Context<ThingId> context, @Nullable final Thing thing,
            final SudoRetrieveThing command); @Override Result<ThingEvent> unhandled(final Context<ThingId> context, @Nullable final Thing thing,
            final long nextRevision, final SudoRetrieveThing command); @Override Optional<EntityTag> previousEntityTag(final SudoRetrieveThing command,
            @Nullable final Thing previousEntity); @Override Optional<EntityTag> nextEntityTag(final SudoRetrieveThing command, @Nullable final Thing newEntity);  }
@Test public void isNotDefinedForDeviantThingIds() { final CommandStrategy.Context<ThingId> context = getDefaultContext(); final SudoRetrieveThing command = SudoRetrieveThing.of(ThingId.of("org.example", "myThing"), DittoHeaders.empty()); final boolean defined = underTest.isDefined(context, THING_V2, command); assertThat(defined).isFalse(); }
@Test public void isNotDefinedIfContextHasNoThing() { final CommandStrategy.Context<ThingId> context = getDefaultContext(); final SudoRetrieveThing command = SudoRetrieveThing.of(THING_ID, DittoHeaders.empty()); final boolean defined = underTest.isDefined(context, null, command); assertThat(defined).isFalse(); }
@Test public void isDefinedIfContextHasThingAndThingIdsAreEqual() { final CommandStrategy.Context<ThingId> context = getDefaultContext(); final SudoRetrieveThing command = SudoRetrieveThing.of(context.getState(), DittoHeaders.empty()); final boolean defined = underTest.isDefined(context, THING_V2, command); assertThat(defined).isTrue(); }