MessageTranscriber { public <U> void registerClassSpecificTranscribers (Class<U> targetClass, Function<U, T> outgoingMessageTranscriber, Function<T, U> incomingMessageTranscriber) { if (targetClass.equals(Object.class)) { throw new IllegalArgumentException("unmarshaller for class java.lang.Object is not supported"); } if (incomingMessageTranscriber == null) { specificIncomingTranscribers.remove(targetClass); } else { specificIncomingTranscribers.put(targetClass, incomingMessageTranscriber); } if (outgoingMessageTranscriber == null) { specificOutgoingTranscribers.remove(targetClass); } else { specificOutgoingTranscribers.put(targetClass, outgoingMessageTranscriber); } } MessageTranscriber(OutgoingMessageTranscriber<T> defaultOutgoingMessageTranscriber,
                              IncomingMessageTranscriber<T> defaultIncomingMessageTranscriber); Function<U, T> getOutgoingMessageTranscriber(U anObject); Function<U, T> getOutgoingMessageTranscriber(Class<U> typeToMarshal); Function<T, U> getIncomingMessageTranscriber(Class<U> typeToUnmarshalTo); void registerClassSpecificTranscribers(Class<U> targetClass,
                                                       Function<U, T> outgoingMessageTranscriber,
                                                       Function<T, U> incomingMessageTranscriber);  }
@Test void typeSpecificHandlersCanBeNull() throws Exception { assertDoesNotThrow( () -> sut.registerClassSpecificTranscribers(String.class, null, null) ); }
@Test void typeSpecificTranscribersCannotBeRegisteredWithNullClass() throws Exception { assertThrows(NullPointerException.class, () -> sut.registerClassSpecificTranscribers(null, s -> "Outgoing", s -> "Incoming")); }
@Test void typeSpecificTranscribersCannotBeRegisteredForObjectClass() { IllegalArgumentException ex = assertThrows( IllegalArgumentException.class, () -> sut.registerClassSpecificTranscribers(Object.class, Object::toString, s -> new Object())); assertThat(ex.getMessage(), Matchers.endsWith("not supported")); }