DefaultMessageMapperFactory implements MessageMapperFactory { @Override public MessageMapperRegistry registryOf(final MappingContext defaultContext, final PayloadMappingDefinition payloadMappingDefinition) { final MessageMapper defaultMapper = mapperOf("default", defaultContext) .map(WrappingMessageMapper::wrap) .orElseThrow(() -> new IllegalArgumentException("No default mapper found: " + defaultContext)); final Map<String, MessageMapper> mappersFromConnectionConfig = instantiateMappers(payloadMappingDefinition.getDefinitions().entrySet().stream()); final Map<String, MessageMapper> fallbackMappers = instantiateMappers(registeredMappers.entrySet().stream() .filter(requiresNoMandatoryConfiguration()) .map(Map.Entry::getKey) .map(this::getEmptyMappingContextForAlias)); return DefaultMessageMapperRegistry.of(defaultMapper, mappersFromConnectionConfig, fallbackMappers); } private  DefaultMessageMapperFactory(final ConnectionId connectionId,
            final MappingConfig mappingConfig,
            final ExtendedActorSystem actorSystem,
            final List<MessageMapperExtension> messageMapperExtensions,
            final LoggingAdapter log); static DefaultMessageMapperFactory of(final ConnectionId connectionId,
            final ActorSystem actorSystem,
            final MappingConfig mappingConfig,
            final LoggingAdapter log); @Override Optional<MessageMapper> mapperOf(final String mapperId, final MappingContext mappingContext); @Override MessageMapperRegistry registryOf(final MappingContext defaultContext,
            final PayloadMappingDefinition payloadMappingDefinition); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void loadFallbackMappersByAlias() { final MessageMapperRegistry registry = underTest.registryOf(DittoMessageMapper.CONTEXT, ConnectivityModelFactory.emptyPayloadMappingDefinition()); final List<MessageMapper> dittoMappers = registry.getMappers(ConnectivityModelFactory.newPayloadMapping("Ditto")); assertThat(dittoMappers).hasSize(1); final MessageMapper dittoMapper = dittoMappers.get(0); assertThat(dittoMapper).isInstanceOf(WrappingMessageMapper.class); assertThat(dittoMapper.getId()).isEqualTo("Ditto"); assertThat(((WrappingMessageMapper) dittoMapper).getDelegate()).isInstanceOf(DittoMessageMapper.class); }
@Test public void loadRegistry() { final MappingContext fooCtx = MappingContexts.mock(true); final MessageMapperRegistry underTest = this.underTest.registryOf(DittoMessageMapper.CONTEXT, ConnectivityModelFactory.newPayloadMappingDefinition("foo", fooCtx)); final MessageMapper fooMapper = underTest.getMappers(ConnectivityModelFactory.newPayloadMapping("foo")).get(0); final MessageMapper defaultMapper = underTest.getDefaultMapper(); assertThat(fooMapper).isInstanceOf(WrappingMessageMapper.class); assertThat(((WrappingMessageMapper) fooMapper).getDelegate()).isInstanceOf(MockMapper.class); assertThat(defaultMapper).isInstanceOf(WrappingMessageMapper.class); assertThat(((WrappingMessageMapper) defaultMapper).getDelegate()).isInstanceOf(DittoMessageMapper.class); }