@Test public void addProjectionInterfaceThrowsExceptionWhenMultipleSimilarlyNamedPresent() { var projectionName = "projection-name"; var projectionTarget = (Class) Integer.class; projectionService.projectionClassMap.put(Pair.of(projectionName, projectionTarget), annotatedClass); given(namedProjectionAnnotationMock.name()).willReturn(projectionName); given(namedProjectionAnnotationMock.target()).willReturn(projectionTarget); given(namedProjectionAnnotationMock.defaultProjection()).willReturn(false); assertThatThrownBy(() -> projectionService.addProjectionInterface(namedProjectionAnnotationMock, annotatedClass)) .isInstanceOf(MultipleSimilarlyNamedProjectionsException.class) .hasMessage(String.format("Multiple interfaces annotated with @NamedInterface " + "have the same name ('%s') for the target class '%s'!", projectionName, projectionTarget.getName())); }
void addProjectionInterface(NamedProjection annotation, Class<?> annotatedInterface) throws MultipleSimilarlyNamedProjectionsException, MultipleDefaultProjectionsException { var projectionName = getProjectionName(annotation, annotatedInterface); var projectionTarget = annotation.target(); var defaultProjection = annotation.defaultProjection(); Pair<String, Class<?>> nameTargetPair = Pair.of(projectionName, projectionTarget); if(projectionClassMap.containsKey(nameTargetPair)) { throw new MultipleSimilarlyNamedProjectionsException(projectionName, projectionTarget); } projectionClassMap.put(nameTargetPair, annotatedInterface); log.debug(String.format("Added projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); if(defaultProjection) { if(defaultProjectionClassMap.containsKey(projectionTarget)) { throw new MultipleDefaultProjectionsException(projectionTarget); } defaultProjectionClassMap.put(projectionTarget, annotatedInterface); log.debug(String.format("Added default projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); } }
ProjectionService implements InitializingBean { void addProjectionInterface(NamedProjection annotation, Class<?> annotatedInterface) throws MultipleSimilarlyNamedProjectionsException, MultipleDefaultProjectionsException { var projectionName = getProjectionName(annotation, annotatedInterface); var projectionTarget = annotation.target(); var defaultProjection = annotation.defaultProjection(); Pair<String, Class<?>> nameTargetPair = Pair.of(projectionName, projectionTarget); if(projectionClassMap.containsKey(nameTargetPair)) { throw new MultipleSimilarlyNamedProjectionsException(projectionName, projectionTarget); } projectionClassMap.put(nameTargetPair, annotatedInterface); log.debug(String.format("Added projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); if(defaultProjection) { if(defaultProjectionClassMap.containsKey(projectionTarget)) { throw new MultipleDefaultProjectionsException(projectionTarget); } defaultProjectionClassMap.put(projectionTarget, annotatedInterface); log.debug(String.format("Added default projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); } } }
ProjectionService implements InitializingBean { void addProjectionInterface(NamedProjection annotation, Class<?> annotatedInterface) throws MultipleSimilarlyNamedProjectionsException, MultipleDefaultProjectionsException { var projectionName = getProjectionName(annotation, annotatedInterface); var projectionTarget = annotation.target(); var defaultProjection = annotation.defaultProjection(); Pair<String, Class<?>> nameTargetPair = Pair.of(projectionName, projectionTarget); if(projectionClassMap.containsKey(nameTargetPair)) { throw new MultipleSimilarlyNamedProjectionsException(projectionName, projectionTarget); } projectionClassMap.put(nameTargetPair, annotatedInterface); log.debug(String.format("Added projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); if(defaultProjection) { if(defaultProjectionClassMap.containsKey(projectionTarget)) { throw new MultipleDefaultProjectionsException(projectionTarget); } defaultProjectionClassMap.put(projectionTarget, annotatedInterface); log.debug(String.format("Added default projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); } } @Autowired  ProjectionService(AnnotatedTypeScanner typeScanner, AnnotationUtilsWrapper annotationUtilsWrapper); }
ProjectionService implements InitializingBean { void addProjectionInterface(NamedProjection annotation, Class<?> annotatedInterface) throws MultipleSimilarlyNamedProjectionsException, MultipleDefaultProjectionsException { var projectionName = getProjectionName(annotation, annotatedInterface); var projectionTarget = annotation.target(); var defaultProjection = annotation.defaultProjection(); Pair<String, Class<?>> nameTargetPair = Pair.of(projectionName, projectionTarget); if(projectionClassMap.containsKey(nameTargetPair)) { throw new MultipleSimilarlyNamedProjectionsException(projectionName, projectionTarget); } projectionClassMap.put(nameTargetPair, annotatedInterface); log.debug(String.format("Added projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); if(defaultProjection) { if(defaultProjectionClassMap.containsKey(projectionTarget)) { throw new MultipleDefaultProjectionsException(projectionTarget); } defaultProjectionClassMap.put(projectionTarget, annotatedInterface); log.debug(String.format("Added default projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); } } @Autowired  ProjectionService(AnnotatedTypeScanner typeScanner, AnnotationUtilsWrapper annotationUtilsWrapper); Class<?> getByNameOrDefault(@NonNull String projectionName, @NonNull Class<?> projectionTarget); Class<?> getDefault(Class<?> projectionTarget); @Override void afterPropertiesSet(); }
ProjectionService implements InitializingBean { void addProjectionInterface(NamedProjection annotation, Class<?> annotatedInterface) throws MultipleSimilarlyNamedProjectionsException, MultipleDefaultProjectionsException { var projectionName = getProjectionName(annotation, annotatedInterface); var projectionTarget = annotation.target(); var defaultProjection = annotation.defaultProjection(); Pair<String, Class<?>> nameTargetPair = Pair.of(projectionName, projectionTarget); if(projectionClassMap.containsKey(nameTargetPair)) { throw new MultipleSimilarlyNamedProjectionsException(projectionName, projectionTarget); } projectionClassMap.put(nameTargetPair, annotatedInterface); log.debug(String.format("Added projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); if(defaultProjection) { if(defaultProjectionClassMap.containsKey(projectionTarget)) { throw new MultipleDefaultProjectionsException(projectionTarget); } defaultProjectionClassMap.put(projectionTarget, annotatedInterface); log.debug(String.format("Added default projection for target '%s' with name '%s'!", projectionTarget.toString(), projectionName)); } } @Autowired  ProjectionService(AnnotatedTypeScanner typeScanner, AnnotationUtilsWrapper annotationUtilsWrapper); Class<?> getByNameOrDefault(@NonNull String projectionName, @NonNull Class<?> projectionTarget); Class<?> getDefault(Class<?> projectionTarget); @Override void afterPropertiesSet();  }