DomainEventHandlerRegistrar.java

1
package org.sanmibuh.ddd.infrastructure;
2
3
import java.util.Arrays;
4
import java.util.List;
5
import java.util.Optional;
6
import lombok.RequiredArgsConstructor;
7
import org.sanmibuh.ddd.port.DomainEventHandler;
8
import org.springframework.beans.BeansException;
9
import org.springframework.beans.factory.BeanFactory;
10
import org.springframework.beans.factory.config.BeanDefinition;
11
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
12
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
13
import org.springframework.beans.factory.support.RootBeanDefinition;
14
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
15
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
16
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
17
import org.springframework.core.type.filter.AssignableTypeFilter;
18
19
@RequiredArgsConstructor(access = lombok.AccessLevel.PACKAGE)
20
final class DomainEventHandlerRegistrar implements BeanDefinitionRegistryPostProcessor {
21
22
  private static final AnnotationBeanNameGenerator NAME_GENERATOR =
23
      new AnnotationBeanNameGenerator();
24
25
  private final BeanFactory beanFactory;
26
27
  @Override
28
  public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry)
29
      throws BeansException {
30 1 1. postProcessBeanDefinitionRegistry : negated conditional → KILLED
    if (!AutoConfigurationPackages.has(beanFactory)) {
31
      return;
32
    }
33
34
    final var packages = AutoConfigurationPackages.get(beanFactory);
35 1 1. postProcessBeanDefinitionRegistry : removed call to org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::registerHandlers → KILLED
    registerHandlers(registry, packages);
36
  }
37
38
  private void registerHandlers(
39
      final BeanDefinitionRegistry registry, final List<String> packages) {
40
    final var scanner = new ClassPathScanningCandidateComponentProvider(false);
41 1 1. registerHandlers : removed call to org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider::addIncludeFilter → KILLED
    scanner.addIncludeFilter(new AssignableTypeFilter(DomainEventHandler.class));
42
    packages.stream()
43 1 1. lambda$registerHandlers$0 : replaced return value with Stream.empty for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::lambda$registerHandlers$0 → KILLED
        .flatMap(basePackage -> scanner.findCandidateComponents(basePackage).stream())
44 2 1. registerHandlers : removed call to java/util/stream/Stream::forEach → KILLED
2. lambda$registerHandlers$1 : removed call to org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::registerIfAbsent → KILLED
        .forEach(candidate -> registerIfAbsent(registry, candidate));
45
  }
46
47
  private void registerIfAbsent(
48
      final BeanDefinitionRegistry registry, final BeanDefinition candidate) {
49
    Optional.ofNullable(candidate.getBeanClassName())
50 1 1. registerIfAbsent : removed call to java/util/Optional::ifPresent → KILLED
        .ifPresent(
51
            beanClassName -> {
52 1 1. lambda$registerIfAbsent$0 : negated conditional → KILLED
              if (!isClassRegistered(registry, beanClassName)) {
53
                final var beanName = NAME_GENERATOR.generateBeanName(candidate, registry);
54 1 1. lambda$registerIfAbsent$0 : removed call to org/springframework/beans/factory/support/BeanDefinitionRegistry::registerBeanDefinition → KILLED
                registry.registerBeanDefinition(beanName, new RootBeanDefinition(beanClassName));
55
              }
56
            });
57
  }
58
59
  private boolean isClassRegistered(
60
      final BeanDefinitionRegistry registry, final String beanClassName) {
61 2 1. isClassRegistered : replaced boolean return with true for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::isClassRegistered → KILLED
2. isClassRegistered : replaced boolean return with false for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::isClassRegistered → KILLED
    return Arrays.stream(registry.getBeanDefinitionNames())
62 1 1. lambda$isClassRegistered$0 : replaced return value with "" for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::lambda$isClassRegistered$0 → KILLED
        .map(name -> registry.getBeanDefinition(name).getBeanClassName())
63
        .anyMatch(beanClassName::equals);
64
  }
65
}

Mutations

30

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

35

1.1
Location : postProcessBeanDefinitionRegistry
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
removed call to org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::registerHandlers → KILLED

41

1.1
Location : registerHandlers
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
removed call to org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider::addIncludeFilter → KILLED

43

1.1
Location : lambda$registerHandlers$0
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
replaced return value with Stream.empty for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::lambda$registerHandlers$0 → KILLED

44

1.1
Location : registerHandlers
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
removed call to java/util/stream/Stream::forEach → KILLED

2.2
Location : lambda$registerHandlers$1
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
removed call to org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::registerIfAbsent → KILLED

50

1.1
Location : registerIfAbsent
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
removed call to java/util/Optional::ifPresent → KILLED

52

1.1
Location : lambda$registerIfAbsent$0
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_notRegisterHandlerBean_whenAlreadyRegistered()]
negated conditional → KILLED

54

1.1
Location : lambda$registerIfAbsent$0
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
removed call to org/springframework/beans/factory/support/BeanDefinitionRegistry::registerBeanDefinition → KILLED

61

1.1
Location : isClassRegistered
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_registerEventHandlerBean_whenFoundInAutoConfigurationPackage()]
replaced boolean return with true for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::isClassRegistered → KILLED

2.2
Location : isClassRegistered
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_notRegisterHandlerBean_whenAlreadyRegistered()]
replaced boolean return with false for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::isClassRegistered → KILLED

62

1.1
Location : lambda$isClassRegistered$0
Killed by : org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest.[engine:junit-jupiter]/[class:org.sanmibuh.ddd.infrastructure.DomainEventHandlerRegistrarTest]/[method:should_notRegisterHandlerBean_whenAlreadyRegistered()]
replaced return value with "" for org/sanmibuh/ddd/infrastructure/DomainEventHandlerRegistrar::lambda$isClassRegistered$0 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support