### Question:
Response implements ServerResponse { @Override public Response registerWriter(MessageBodyWriter<?> writer) { writerContext.registerWriter(writer); return this; } Response(WebServer webServer, BareResponse bareResponse, List<MediaType> acceptedTypes);   Response(Response response); @Override WebServer webServer(); @Override Http.ResponseStatus status(); @Override Response status(Http.ResponseStatus status); @Override ResponseHeaders headers(); @Override MessageBodyWriterContext writerContext(); @Override Void send(Throwable content); @Override Single<ServerResponse> send(T content); @Override Single<ServerResponse> send(Publisher<DataChunk> content); @Override Single<ServerResponse> send(Publisher<DataChunk> content, boolean applyFilters); @Override Single<ServerResponse> send(); @Override Single<ServerResponse> send(Publisher<T> content, Class<T> itemClass); @Override Single<ServerResponse> send(Function<MessageBodyWriterContext, Publisher<DataChunk>> function); @Override Response registerWriter(MessageBodyWriter<?> writer); @Override Response registerWriter(MessageBodyStreamWriter<?> writer); @Override Response registerFilter(MessageBodyFilter filter); @Override Response registerFilter(Function<Publisher<DataChunk>, Publisher<DataChunk>> function); @Override Response registerWriter(Class<T> type, Function<T, Publisher<DataChunk>> function); @Override Response registerWriter(Predicate<?> accept, Function<T, Publisher<DataChunk>> function); @Override Response registerWriter(Class<T> type, MediaType contentType,
            Function<? extends T, Publisher<DataChunk>> function); @Override Response registerWriter(Predicate<?> accept, MediaType contentType,
            Function<T, Publisher<DataChunk>> function); @Override Single<ServerResponse> whenSent(); @Override long requestId();  }### Answer:
@Test public void classRelatedWriters() throws Exception { StringBuilder sb = new StringBuilder(); Response response = new ResponseImpl(new NoOpBareResponse(null)); marshall(response, "foo".getBytes()); IllegalStateException e = assertThrows(IllegalStateException.class, () -> marshall(response, "foo")); assertThat(e.getCause(), allOf(instanceOf(IllegalStateException.class), hasProperty("message", containsString("No writer found for type")))); e = assertThrows(IllegalStateException.class, () -> marshall(response, Duration.of(1, ChronoUnit.MINUTES))); assertThat(e.getCause(), allOf(instanceOf(IllegalStateException.class), hasProperty("message", containsString("No writer found for type")))); response.registerWriter(CharSequence.class, o -> { sb.append("1"); return Single.empty(); }); marshall(response, "foo"); assertThat(sb.toString(), is("1")); sb.setLength(0); marshall(response, Single.empty(),String.class); assertThat(sb.toString(), is("")); sb.setLength(0); response.registerWriter(String.class, o -> { sb.append("2"); return Single.empty(); }); marshall(response, "foo"); assertThat(sb.toString(), is("2")); sb.setLength(0); marshall(response, new StringBuilder()); assertThat(sb.toString(), is("1")); sb.setLength(0); response.registerWriter(Object.class, o -> { sb.append("3"); return Single.empty(); }); marshall(response, 1); assertThat(sb.toString(), is("3")); }
@Test public void writerByPredicate() throws Exception { StringBuilder sb = new StringBuilder(); Response response = new ResponseImpl(new NoOpBareResponse(null)); response.registerWriter(o -> Integer.class.isAssignableFrom((Class<?>)o), o -> { sb.append("1"); return Single.empty(); }); response.registerWriter(o -> Long.class.isAssignableFrom((Class<?>)o), o -> { sb.append("2"); return Single.empty(); }); marshall(response, 1); assertThat(sb.toString(), is("1")); sb.setLength(0); marshall(response, 2L); assertThat(sb.toString(), is("2")); sb.setLength(0); marshall(response, "3".getBytes()); assertThat(sb.toString(), is("")); }