MapBasedDeviceConnectionService implements DeviceConnectionService { @Override public final Future<DeviceConnectionResult> removeCommandHandlingAdapterInstance( final String tenantId, final String deviceId, final String adapterInstanceId, final Span span) { Objects.requireNonNull(tenantId); Objects.requireNonNull(deviceId); Objects.requireNonNull(adapterInstanceId); final Map<String, ExpiringValue<JsonObject>> adapterInstancesForTenantMap = commandHandlingAdapterInstancesMap.computeIfAbsent(tenantId, k -> buildAdapterInstancesForTenantMap()); final ExpiringValue<JsonObject> adapterInstanceIdJsonHolder = adapterInstancesForTenantMap.get(deviceId); final Promise<DeviceConnectionResult> result = Promise.promise(); if (adapterInstanceIdJsonHolder == null) { result.complete(DeviceConnectionResult.from(HttpURLConnection.HTTP_PRECON_FAILED)); } else { final boolean removed = adapterInstanceId.equals(getAdapterInstanceIdFromJson(adapterInstanceIdJsonHolder.getValue())) && adapterInstancesForTenantMap.remove(deviceId, adapterInstanceIdJsonHolder); if (removed) { result.complete(DeviceConnectionResult.from(HttpURLConnection.HTTP_NO_CONTENT)); } else { log.debug("cannot remove command handling adapter instance for device [{}], tenant [{}] - given value does not match current", deviceId, tenantId); result.complete(DeviceConnectionResult.from(HttpURLConnection.HTTP_PRECON_FAILED)); } } return result.future(); }  @Autowired void setConfig(final MapBasedDeviceConnectionsConfigProperties configuration); MapBasedDeviceConnectionsConfigProperties getConfig(); @Override final Future<DeviceConnectionResult> setLastKnownGatewayForDevice(final String tenantId, final String deviceId,
            final String gatewayId, final Span span); @Override final Future<DeviceConnectionResult> getLastKnownGatewayForDevice(final String tenantId, final String deviceId,
            final Span span); @Override final Future<DeviceConnectionResult> setCommandHandlingAdapterInstance(final String tenantId,
            final String deviceId, final String protocolAdapterInstanceId, final Duration lifespan, final Span span); @Override final Future<DeviceConnectionResult> removeCommandHandlingAdapterInstance(
            final String tenantId,
            final String deviceId,
            final String adapterInstanceId,
            final Span span); @Override final Future<DeviceConnectionResult> getCommandHandlingAdapterInstances(final String tenantId,
            final String deviceId, final List<String> viaGateways, final Span span);  }
@Test public void testRemoveCommandHandlingAdapterInstanceFailsForNonExistingEntry(final VertxTestContext ctx) { svc.removeCommandHandlingAdapterInstance(Constants.DEFAULT_TENANT, "non-existing", "adapterInstance", span) .onComplete(ctx.succeeding(result -> { ctx.verify(() -> { assertEquals(HttpURLConnection.HTTP_PRECON_FAILED, result.getStatus()); assertNull(result.getPayload()); }); ctx.completeNow(); })); }