HandlerLookup.java

1
package org.sanmibuh.ddd.infrastructure;
2
3
import java.util.HashMap;
4
import java.util.List;
5
import java.util.Map;
6
import org.springframework.aop.support.AopUtils;
7
import org.springframework.core.GenericTypeResolver;
8
9
public final class HandlerLookup<H> {
10
11
  private final Map<Class<?>, H> index;
12
13
  public HandlerLookup(final List<H> handlers, final Class<?> handlerInterface) {
14
    final var map = new HashMap<Class<?>, H>();
15
    for (final var handler : handlers) {
16
      final var messageType =
17
          resolveMessageType(AopUtils.getTargetClass(handler), handlerInterface);
18
      final var existing = map.put(messageType, handler);
19 1 1. <init> : negated conditional → KILLED
      if (existing != null) {
20
        throw new IllegalArgumentException(
21
            "Duplicate handlers for message type: " + messageType.getName());
22
      }
23
    }
24
    index = Map.copyOf(map);
25
  }
26
27
  private static Class<?> resolveMessageType(
28
      final Class<?> handlerClass, final Class<?> handlerInterface) {
29
    final var typeArgs = GenericTypeResolver.resolveTypeArguments(handlerClass, handlerInterface);
30 2 1. resolveMessageType : negated conditional → KILLED
2. resolveMessageType : negated conditional → KILLED
    if (typeArgs == null || typeArgs.length == 0) {
31
      throw new IllegalArgumentException(
32
          "Cannot resolve message type for: " + handlerClass.getName());
33
    }
34 1 1. resolveMessageType : replaced return value with null for org/sanmibuh/ddd/infrastructure/HandlerLookup::resolveMessageType → KILLED
    return typeArgs[0];
35
  }
36
37
  public H find(final Class<?> messageType) {
38
    final var handler = index.get(messageType);
39 1 1. find : negated conditional → KILLED
    if (handler == null) {
40
      throw new HandlerNotFoundException(messageType);
41
    }
42 1 1. find : replaced return value with null for org/sanmibuh/ddd/infrastructure/HandlerLookup::find → KILLED
    return handler;
43
  }
44
}

Mutations

19

1.1
Location : <init>
Killed by : org.sanmibuh.ddd.infrastructure.HandlerLookupTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.HandlerLookupTest]/[method:should_returnHandler_whenMessageTypeIsRegistered()]
negated conditional → KILLED

30

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

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

34

1.1
Location : resolveMessageType
Killed by : org.sanmibuh.ddd.infrastructure.HandlerLookupTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.HandlerLookupTest]/[method:should_throwIllegalArgumentException_whenDuplicateHandlersForSameMessageType()]
replaced return value with null for org/sanmibuh/ddd/infrastructure/HandlerLookup::resolveMessageType → KILLED

39

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

42

1.1
Location : find
Killed by : org.sanmibuh.ddd.infrastructure.HandlerLookupTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.HandlerLookupTest]/[method:should_returnHandler_whenMessageTypeIsRegistered()]
replaced return value with null for org/sanmibuh/ddd/infrastructure/HandlerLookup::find → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support