EventBusService extends AbstractVerticle { protected final JsonObject getRequestPayload(final JsonObject payload) { return Optional.ofNullable(payload).map(pl -> { final Object obj = pl.getValue(RequestResponseApiConstants.FIELD_ENABLED); if (obj instanceof Boolean) { return pl; } else { log.trace("adding 'enabled=true' property to request payload"); return pl.copy().put(RequestResponseApiConstants.FIELD_ENABLED, Boolean.TRUE); } }).orElseGet(() -> new JsonObject().put(RequestResponseApiConstants.FIELD_ENABLED, Boolean.TRUE)); }  @Autowired(required = false) final void setTracer(final Tracer opentracingTracer); @Override final void start(final Promise<Void> startPromise); @Override final void stop(final Promise<Void> stopPromise);  }
@Test public void getRequestPayloadHandlesNonBooleanEnabledField() { final JsonObject device = new JsonObject().put("device-id", "someValue").put("enabled", "notABoolean"); final JsonObject result = service.getRequestPayload(device); assertThat(result.getBoolean("enabled"), is(Boolean.TRUE)); }
@Test public void getRequestPayloadHandlesMissingEnabledField() { final JsonObject device = new JsonObject().put("device-id", "someValue"); final JsonObject result = service.getRequestPayload(device); assertThat(result.getBoolean("enabled"), is(Boolean.TRUE)); }