PolicyIdReferencePlaceholderResolver implements ReferencePlaceholderResolver<String> { @Override public CompletionStage<String> resolve(final ReferencePlaceholder referencePlaceholder, final DittoHeaders dittoHeaders) { final ResolveEntityReferenceStrategy resolveEntityReferenceStrategy = supportedEntityTypesToActionMap.get(referencePlaceholder.getReferencedEntityType()); try (final AutoCloseableSlf4jLogger logger = LOGGER.setCorrelationId(dittoHeaders)) { if (null == resolveEntityReferenceStrategy) { final String referencedEntityType = referencePlaceholder.getReferencedEntityType().name(); logger.info("Could not find a placeholder replacement strategy for entity type <{}> in supported" + " entity types: {}", referencedEntityType, supportedEntityTypeNames); throw notSupportedException(referencedEntityType, dittoHeaders); } logger.debug("Will resolve entity reference for placeholder: <{}>", referencePlaceholder); } return resolveEntityReferenceStrategy.handleEntityPolicyIdReference(referencePlaceholder, dittoHeaders); } private  PolicyIdReferencePlaceholderResolver(final ActorRef conciergeForwarderActor,
            final Duration retrieveEntityTimeoutDuration); @Override CompletionStage<String> resolve(final ReferencePlaceholder referencePlaceholder,
            final DittoHeaders dittoHeaders); static PolicyIdReferencePlaceholderResolver of(final ActorRef conciergeForwarderActor,
            final Duration retrieveEntityTimeoutDuration);  }
@Test public void resolvePolicyIdFromThingThrowsExceptionIfResponseIsNotExpected() { final ReferencePlaceholder referencePlaceholder = ReferencePlaceholder.fromCharSequence("{{ ref:things/" + THING_ID + "/policyId }}") .orElseThrow(IllegalStateException::new); final CompletionStage<String> policyIdCS = sut.resolve(referencePlaceholder, DittoHeaders.empty()); final RetrieveThing retrieveThing = conciergeForwarderActorProbe.expectMsgClass(RetrieveThing.class); assertThat((CharSequence) retrieveThing.getThingEntityId()).isEqualTo(THING_ID); assertThat(retrieveThing.getSelectedFields()).contains(JsonFieldSelector.newInstance("policyId")); conciergeForwarderActorProbe.reply("someThingUnexpected"); Awaitility.await() .atMost(org.awaitility.Duration.ONE_SECOND) .until(() -> policyIdCS.toCompletableFuture().isDone()); assertThat(policyIdCS.toCompletableFuture()) .hasFailedWithThrowableThat() .isInstanceOf(GatewayInternalErrorException.class); }