ThingCommandEnforcement extends AbstractEnforcement<ThingCommand<?>> { private static ThingCommand transformModifyThingToCreateThing(final ThingCommand receivedCommand) { if (receivedCommand instanceof ModifyThing) { final ModifyThing modifyThing = (ModifyThing) receivedCommand; final JsonObject initialPolicy = modifyThing.getInitialPolicy().orElse(null); final String policyIdOrPlaceholder = modifyThing.getPolicyIdOrPlaceholder().orElse(null); final Thing newThing = modifyThing.getThing().toBuilder() .setId(modifyThing.getThingEntityId()) .build(); return CreateThing.of(newThing, initialPolicy, policyIdOrPlaceholder, modifyThing.getDittoHeaders()); } else { return receivedCommand; } } private  ThingCommandEnforcement(final Contextual<ThingCommand<?>> data,
            final ActorRef thingsShardRegion,
            final ActorRef policiesShardRegion,
            final Cache<EntityIdWithResourceType, Entry<EntityIdWithResourceType>> thingIdCache,
            final Cache<EntityIdWithResourceType, Entry<Enforcer>> policyEnforcerCache,
            final Cache<EntityIdWithResourceType, Entry<Enforcer>> aclEnforcerCache,
            final PreEnforcer preEnforcer,
            final List<SubjectIssuer> subjectIssuersForPolicyMigration); @Override CompletionStage<Contextual<WithDittoHeaders>> enforce();  }
@Test public void transformModifyThingToCreateThing() { final Thing thingInPayload = newThing().setId(THING_ID).build(); new TestKit(system) {{ final ActorRef underTest = TestSetup.newEnforcerActor(system, getRef(), getRef()); final ModifyThing modifyThing = ModifyThing.of(THING_ID, thingInPayload, null, headers(V_1)); underTest.tell(modifyThing, getRef()); fishForMsgClass(this, SudoRetrieveThing.class); reply(ThingNotAccessibleException.newBuilder(THING_ID).build()); fishForMsgClass(this, CreateThing.class); }}; }