InMemoryEventBus.java

1
package org.sanmibuh.ddd.infrastructure;
2
3
import java.util.List;
4
import lombok.extern.slf4j.Slf4j;
5
import org.sanmibuh.ddd.domain.DomainEvent;
6
import org.sanmibuh.ddd.domain.NoSubscribersRequired;
7
import org.sanmibuh.ddd.port.DomainEventHandler;
8
import org.sanmibuh.ddd.port.EventBus;
9
10
@Slf4j
11
public final class InMemoryEventBus implements EventBus {
12
13
  private final EventHandlerRegistry registry;
14
15
  public InMemoryEventBus(final List<DomainEventHandler<?>> handlers) {
16
    registry = new EventHandlerRegistry(handlers);
17
  }
18
19
  @Override
20
  @SuppressWarnings("unchecked")
21
  public void publish(final DomainEvent event) {
22
    final var handlers = registry.handlersFor(event.getClass());
23 1 1. publish : negated conditional → KILLED
    if (isDropped(event, handlers)) {
24
      log.warn(
25
          "No handler registered for domain event {}; the event was dropped and not delivered.",
26
          event.getClass().getName());
27
      return;
28
    }
29
    for (final var handler : handlers) {
30 1 1. publish : removed call to org/sanmibuh/ddd/port/DomainEventHandler::handle → KILLED
      ((DomainEventHandler<DomainEvent>) handler).handle(event);
31
    }
32
  }
33
34
  private static boolean isDropped(
35
      final DomainEvent event, final List<DomainEventHandler<?>> handlers) {
36 3 1. isDropped : replaced boolean return with true for org/sanmibuh/ddd/infrastructure/InMemoryEventBus::isDropped → KILLED
2. isDropped : negated conditional → KILLED
3. isDropped : negated conditional → KILLED
    return handlers.isEmpty() && !event.getClass().isAnnotationPresent(NoSubscribersRequired.class);
37
  }
38
}

Mutations

23

1.1
Location : publish
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_notWarn_whenEventHasNoHandlerButIsOptedOut()]
negated conditional → KILLED

30

1.1
Location : publish
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_deliverEvent_whenSingleHandlerIsRegistered()]
removed call to org/sanmibuh/ddd/port/DomainEventHandler::handle → KILLED

36

1.1
Location : isDropped
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_notWarn_whenEventHasNoHandlerButIsOptedOut()]
replaced boolean return with true for org/sanmibuh/ddd/infrastructure/InMemoryEventBus::isDropped → KILLED

2.2
Location : isDropped
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_notWarn_whenEventHasNoHandlerButIsOptedOut()]
negated conditional → KILLED

3.3
Location : isDropped
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_deliverEvent_whenSingleHandlerIsRegistered()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support