TedeeReflectionHints.java

1
package org.sanmibuh.tedee.lock.infrastructure.secondary;
2
3
import java.util.Arrays;
4
import java.util.stream.Stream;
5
import org.jspecify.annotations.Nullable;
6
import org.sanmibuh.framework.resilience.RetryProperties;
7
import org.sanmibuh.tedee.lock.infrastructure.TedeeProperties;
8
import org.springframework.aot.hint.MemberCategory;
9
import org.springframework.aot.hint.RuntimeHints;
10
import org.springframework.aot.hint.RuntimeHintsRegistrar;
11
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
12
import org.springframework.core.io.DefaultResourceLoader;
13
import org.springframework.core.type.filter.AssignableTypeFilter;
14
import org.springframework.util.ClassUtils;
15
16
final class TedeeReflectionHints implements RuntimeHintsRegistrar {
17
18
  private static final String MODEL_PACKAGE = "com.tedee.bridge.client.model";
19
  private static final MemberCategory[] JACKSON_CATEGORIES = {
20
    MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS,
21
    MemberCategory.INVOKE_PUBLIC_METHODS,
22
    MemberCategory.ACCESS_DECLARED_FIELDS
23
  };
24
  private static final MemberCategory[] VALIDATION_CATEGORIES = {
25
    MemberCategory.ACCESS_DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_METHODS
26
  };
27
28
  @Override
29
  public void registerHints(final RuntimeHints hints, final @Nullable ClassLoader classLoader) {
30
    final var scanner =
31
        setResourceLoaderPITEquivalent(
32
            new ClassPathScanningCandidateComponentProvider(false), classLoader);
33 1 1. registerHints : removed call to org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider::addIncludeFilter → KILLED
    scanner.addIncludeFilter(new AssignableTypeFilter(Object.class));
34
    scanner.findCandidateComponents(MODEL_PACKAGE).stream()
35
        .flatMap(
36
            bd -> {
37
              final var className = bd.getBeanClassName();
38 1 1. lambda$registerHints$0 : negated conditional → KILLED
              return className != null
39
                  ? loadWithDeclaredClasses(className, classLoader)
40
                  : Stream.empty();
41
            })
42 1 1. registerHints : removed call to java/util/stream/Stream::forEach → KILLED
        .forEach(type -> hints.reflection().registerType(type, JACKSON_CATEGORIES));
43
    hints
44
        .reflection()
45
        .registerType(TedeeProperties.class, VALIDATION_CATEGORIES)
46
        .registerType(RetryProperties.class, VALIDATION_CATEGORIES);
47
  }
48
49
  private ClassPathScanningCandidateComponentProvider setResourceLoaderPITEquivalent(
50
      final ClassPathScanningCandidateComponentProvider scanner,
51
      final @Nullable ClassLoader classLoader) {
52
    scanner.setResourceLoader(new DefaultResourceLoader(classLoader));
53
    return scanner;
54
  }
55
56
  private Stream<Class<?>> loadWithDeclaredClasses(
57
      final String className, final @Nullable ClassLoader loader) {
58
    final var type = ClassUtils.resolveClassName(className, loader);
59 1 1. loadWithDeclaredClasses : replaced return value with Stream.empty for org/sanmibuh/tedee/lock/infrastructure/secondary/TedeeReflectionHints::loadWithDeclaredClasses → KILLED
    return Stream.concat(Stream.of(type), Arrays.stream(type.getDeclaredClasses()));
60
  }
61
}

Mutations

33

1.1
Location : registerHints
Killed by : org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest]/[test-template:should_registerReflectionHints_whenCalled(java.lang.ClassLoader)]/[test-template-invocation:#2]
removed call to org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider::addIncludeFilter → KILLED

38

1.1
Location : lambda$registerHints$0
Killed by : org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest]/[test-template:should_registerReflectionHints_whenCalled(java.lang.ClassLoader)]/[test-template-invocation:#2]
negated conditional → KILLED

42

1.1
Location : registerHints
Killed by : org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest]/[test-template:should_registerReflectionHints_whenCalled(java.lang.ClassLoader)]/[test-template-invocation:#2]
removed call to java/util/stream/Stream::forEach → KILLED

59

1.1
Location : loadWithDeclaredClasses
Killed by : org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeReflectionHintsTest]/[test-template:should_registerReflectionHints_whenCalled(java.lang.ClassLoader)]/[test-template-invocation:#2]
replaced return value with Stream.empty for org/sanmibuh/tedee/lock/infrastructure/secondary/TedeeReflectionHints::loadWithDeclaredClasses → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support