InMemoryCommandBus.java

1
package org.sanmibuh.ddd.infrastructure;
2
3
import java.util.List;
4
import lombok.extern.slf4j.Slf4j;
5
import org.sanmibuh.ddd.port.Command;
6
import org.sanmibuh.ddd.port.CommandBus;
7
import org.sanmibuh.ddd.port.CommandHandler;
8
import org.sanmibuh.ddd.port.EventBus;
9
10
@Slf4j
11
public final class InMemoryCommandBus implements CommandBus {
12
13
  private final HandlerLookup<CommandHandler<?, ?>> lookup;
14
  private final EventBus eventBus;
15
16
  public InMemoryCommandBus(final List<CommandHandler<?, ?>> handlers, final EventBus eventBus) {
17
    lookup = new HandlerLookup<>(handlers, CommandHandler.class);
18
    this.eventBus = eventBus;
19
  }
20
21
  @Override
22
  @SuppressWarnings("unchecked")
23
  public void dispatch(final Command command) {
24
    log.info("Dispatching command {}", command);
25
    final CommandHandler<Command, ?> handler =
26
        (CommandHandler<Command, ?>) lookup.find(command.getClass());
27 1 1. dispatch : removed call to java/util/List::forEach → KILLED
    handler.handle(command).forEach(eventBus::publish);
28
  }
29
}

Mutations

27

1.1
Location : dispatch
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryCommandBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryCommandBusTest]/[method:should_publishRecordedEvents_whenHandlerIsRegistered()]
removed call to java/util/List::forEach → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support