ManifestProvider implements Function<Object, String> { @Override public String apply(final Object o) { checkNotNull(o, "object"); final Class<?> oClass = o.getClass(); if (WithManifest.class.isAssignableFrom(oClass)) { final WithManifest withManifest = (WithManifest) o; return withManifest.getManifest(); } return oClass.getSimpleName(); } private  ManifestProvider(); static ManifestProvider getInstance(); @Override String apply(final Object o);  }
@Test public void tryToGetManifestForNull() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> underTest.apply(null)) .withFailMessage("The %s must not be null!", "object") .withNoCause(); }
@Test public void getManifestFromCommandNotSupportedException() { final DittoRuntimeException exception = CommandNotSupportedException.newBuilder(1).build(); final String manifest = underTest.apply(exception); assertThat(manifest).isEqualTo(exception.getErrorCode()); }
@Test public void getManifestFromThingCommand() { final ThingId thingId = THING_ID; final Command<RetrieveThing> retrieveThing = RetrieveThing.of(thingId, DittoHeaders.empty()); final String manifest = underTest.apply(retrieveThing); assertThat(manifest).isEqualTo(retrieveThing.getType()); }
@Test public void getManifestFromThingCommandResponse() { final CommandResponse<CreateThingResponse> commandResponse = CreateThingResponse.of(THING, DittoHeaders.empty()); final String manifest = underTest.apply(commandResponse); assertThat(manifest).isEqualTo(commandResponse.getType()); }