CacheBasedDeviceConnectionService extends AbstractVerticle implements DeviceConnectionService, HealthCheckProvider { @Override public Future<DeviceConnectionResult> getLastKnownGatewayForDevice( final String tenantId, final String deviceId, final Span span) { return cache.getLastKnownGatewayForDevice(tenantId, deviceId, span) .map(json -> DeviceConnectionResult.from(HttpURLConnection.HTTP_OK, json)) .otherwise(t -> DeviceConnectionResult.from(ServiceInvocationException.extractStatusCode(t))); } CacheBasedDeviceConnectionService(final DeviceConnectionInfo cache); @Override Future<DeviceConnectionResult> setLastKnownGatewayForDevice(
            final String tenantId,
            final String deviceId,
            final String gatewayId,
            final Span span); @Override Future<DeviceConnectionResult> getLastKnownGatewayForDevice(
            final String tenantId,
            final String deviceId,
            final Span span); @Override Future<DeviceConnectionResult> setCommandHandlingAdapterInstance(final String tenantId,
            final String deviceId, final String adapterInstanceId, final Duration lifespan,
            final Span span); @Override Future<DeviceConnectionResult> removeCommandHandlingAdapterInstance(final String tenantId, final String deviceId,
            final String adapterInstanceId, final Span span); @Override Future<DeviceConnectionResult> getCommandHandlingAdapterInstances(final String tenantId, final String deviceId,
            final List<String> viaGateways, final Span span); @Override void registerReadinessChecks(final HealthCheckHandler readinessHandler); @Override void registerLivenessChecks(final HealthCheckHandler livenessHandler);  }
@Test public void testGetLastKnownGatewayForDeviceNotFound(final VertxTestContext ctx) { final String deviceId = "testDevice"; when(cache.getLastKnownGatewayForDevice(anyString(), anyString(), any(Span.class))) .thenReturn(Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_NOT_FOUND))); givenAStartedService() .compose(ok -> svc.getLastKnownGatewayForDevice(Constants.DEFAULT_TENANT, deviceId, span)) .onComplete(ctx.succeeding(deviceConnectionResult -> { ctx.verify(() -> { assertThat(deviceConnectionResult.getStatus()).isEqualTo(HttpURLConnection.HTTP_NOT_FOUND); assertThat(deviceConnectionResult.getPayload()).isNull(); }); ctx.completeNow(); })); }