ProjectionService implements InitializingBean { public Class<?> getByNameOrDefault(@NonNull String projectionName, @NonNull Class<?> projectionTarget) { return projectionClassMap.getOrDefault(Pair.of(projectionName, projectionTarget), getDefault(projectionTarget)); } @Autowired  ProjectionService(AnnotatedTypeScanner typeScanner, AnnotationUtilsWrapper annotationUtilsWrapper); Class<?> getByNameOrDefault(@NonNull String projectionName, @NonNull Class<?> projectionTarget); Class<?> getDefault(Class<?> projectionTarget); @Override void afterPropertiesSet();  }
@Test public void getByNameOrDefaultReturnsProjectWithMatchingNameAndTarget() { var expectedName = "projection-name"; var expectedTarget = String.class; Pair<String, Class<?>> pair = Pair.of(expectedName, expectedTarget); projectionService.projectionClassMap.put(pair, annotatedClass); var actualProjection = projectionService.getByNameOrDefault(expectedName, expectedTarget); assertThat(actualProjection).isEqualTo(annotatedClass); }
@Test public void getByNameOrDefaultReturnsDefaultWhenNoProjectionWithGivenNameAndTargetNameExists() { var expectedName = "projection-name"; var expectedTarget = String.class; projectionService.defaultProjectionClassMap.put(expectedTarget, annotatedClass); var actualProjection = projectionService.getByNameOrDefault(expectedName, expectedTarget); assertThat(actualProjection).isEqualTo(annotatedClass); }