EventHandlerRegistry.java

1
package org.sanmibuh.ddd.infrastructure;
2
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7
import org.sanmibuh.ddd.port.DomainEventHandler;
8
import org.springframework.aop.support.AopUtils;
9
import org.springframework.core.GenericTypeResolver;
10
11
final class EventHandlerRegistry {
12
13
  private final Map<Class<?>, List<DomainEventHandler<?>>> index;
14
15
  EventHandlerRegistry(final List<DomainEventHandler<?>> handlers) {
16
    final var map = new HashMap<Class<?>, List<DomainEventHandler<?>>>();
17
    for (final var handler : handlers) {
18
      final var eventType = resolveEventType(AopUtils.getTargetClass(handler));
19 1 1. lambda$new$0 : replaced return value with Collections.emptyList for org/sanmibuh/ddd/infrastructure/EventHandlerRegistry::lambda$new$0 → KILLED
      map.computeIfAbsent(eventType, k -> new ArrayList<>()).add(handler);
20
    }
21
    index = Map.copyOf(map);
22
  }
23
24
  private static Class<?> resolveEventType(final Class<?> handlerClass) {
25
    final var typeArgs =
26
        GenericTypeResolver.resolveTypeArguments(handlerClass, DomainEventHandler.class);
27 2 1. resolveEventType : negated conditional → KILLED
2. resolveEventType : negated conditional → KILLED
    if (typeArgs == null || typeArgs.length == 0) {
28
      throw new IllegalArgumentException(
29
          "Cannot resolve event type for: " + handlerClass.getName());
30
    }
31 1 1. resolveEventType : replaced return value with null for org/sanmibuh/ddd/infrastructure/EventHandlerRegistry::resolveEventType → KILLED
    return typeArgs[0];
32
  }
33
34
  List<DomainEventHandler<?>> handlersFor(final Class<?> eventType) {
35 1 1. handlersFor : replaced return value with Collections.emptyList for org/sanmibuh/ddd/infrastructure/EventHandlerRegistry::handlersFor → KILLED
    return index.getOrDefault(eventType, List.of());
36
  }
37
}

Mutations

19

1.1
Location : lambda$new$0
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_deliverEvent_whenSingleHandlerIsRegistered()]
replaced return value with Collections.emptyList for org/sanmibuh/ddd/infrastructure/EventHandlerRegistry::lambda$new$0 → KILLED

27

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

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

31

1.1
Location : resolveEventType
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_deliverEvent_whenSingleHandlerIsRegistered()]
replaced return value with null for org/sanmibuh/ddd/infrastructure/EventHandlerRegistry::resolveEventType → KILLED

35

1.1
Location : handlersFor
Killed by : org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.InMemoryEventBusTest]/[method:should_deliverEvent_whenSingleHandlerIsRegistered()]
replaced return value with Collections.emptyList for org/sanmibuh/ddd/infrastructure/EventHandlerRegistry::handlersFor → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support