Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Johnny Lim <izeye@naver.com>
  • Loading branch information
izeye authored Feb 20, 2025
1 parent 2ad11b3 commit fd55d3e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CountedAspectTest {
// end::resolvers[]

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithText(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
CountedAspect countedAspect = new CountedAspect(registry);
Expand All @@ -63,7 +63,7 @@ void meterTagsWithText(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
CountedAspect countedAspect = new CountedAspect(registry);
Expand All @@ -88,7 +88,7 @@ void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
CountedAspect countedAspect = new CountedAspect(registry);
Expand All @@ -108,7 +108,7 @@ void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void multipleMeterTagsWithExpression(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
CountedAspect countedAspect = new CountedAspect(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void multipleMeterTagsWithExpression(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.lang.annotation.Annotation;

/**
* A container class that holds information about the parameter of the annotated method
* argument.
* A container class that holds information about the parameter or return value of the
* annotated method.
*
* Code ported from Spring Cloud Sleuth.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public void addAnnotatedParameters(T objectToModify, ProceedingJoinPoint pjp) {
try {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
method = tryToTakeMethodFromTargetClass(pjp, method);
List<AnnotatedObject> annotatedParameters = AnnotationUtils.findAnnotatedObjects(annotationClass, method,
List<AnnotatedObject> annotatedParameters = AnnotationUtils.findAnnotatedParameters(annotationClass, method,
pjp.getArgs());
getParametersAnnotationsFromInterfaces(pjp, method, annotatedParameters);
addAnnotatedArguments(objectToModify, annotatedParameters);
addAnnotatedParametersFromInterfaces(pjp, method, annotatedParameters);
addAnnotatedObjects(objectToModify, annotatedParameters);
}
catch (Exception ex) {
log.error("Exception occurred while trying to add annotated parameters", ex);
Expand All @@ -121,7 +121,7 @@ public void addAnnotatedMethodResult(T objectToModify, ProceedingJoinPoint pjp,
.map(annotation -> new AnnotatedObject(annotation, result))
.forEach(annotatedResult::add);

addAnnotatedArguments(objectToModify, annotatedResult);
addAnnotatedObjects(objectToModify, annotatedResult);
}
catch (Exception ex) {
log.error("Exception occurred while trying to add annotated method result", ex);
Expand All @@ -138,11 +138,11 @@ private static Method tryToTakeMethodFromTargetClass(ProceedingJoinPoint pjp, Me
return method;
}

private void getParametersAnnotationsFromInterfaces(ProceedingJoinPoint pjp, Method mostSpecificMethod,
private void addAnnotatedParametersFromInterfaces(ProceedingJoinPoint pjp, Method mostSpecificMethod,
List<AnnotatedObject> annotatedParameters) {
traverseInterfacesHierarchy(pjp, mostSpecificMethod, method -> {
List<AnnotatedObject> annotatedParametersForActualMethod = AnnotationUtils
.findAnnotatedObjects(annotationClass, method, pjp.getArgs());
.findAnnotatedParameters(annotationClass, method, pjp.getArgs());
// annotations for a single parameter can be `duplicated` by the ones
// from parent interface,
// however later on during key-based deduplication the ones from
Expand Down Expand Up @@ -176,7 +176,7 @@ private boolean methodsAreTheSame(Method mostSpecificMethod, Method method) {
&& Arrays.equals(method.getParameterTypes(), mostSpecificMethod.getParameterTypes());
}

private void addAnnotatedArguments(T objectToModify, List<AnnotatedObject> toBeAdded) {
private void addAnnotatedObjects(T objectToModify, List<AnnotatedObject> toBeAdded) {
Set<String> seen = new HashSet<>();
for (AnnotatedObject container : toBeAdded) {
KeyValue keyValue = toKeyValue.apply(container.annotation, container.object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private AnnotationUtils() {

}

static List<AnnotatedObject> findAnnotatedObjects(Class<? extends Annotation> annotationClazz, Method method,
static List<AnnotatedObject> findAnnotatedParameters(Class<? extends Annotation> annotationClazz, Method method,
Object[] args) {
Parameter[] parameters = method.getParameters();
List<AnnotatedObject> result = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
MeterTagClassInterface service = getProxyWithCountedAspect(annotatedClass.newInstance());

service.getReturnValueAnnotationForTagValueExpression("15L");
service.getAnnotationForTagValueExpression("15L");

assertThat(registry.get("method.counted").tag("test", "hello characters").counter().count()).isEqualTo(1);
}
Expand Down Expand Up @@ -677,7 +677,7 @@ interface MeterTagClassInterface {
String getReturnValueAnnotationForTagValueResolver();

@Counted
void getReturnValueAnnotationForTagValueExpression(
void getAnnotationForTagValueExpression(
@MeterTag(key = "test", expression = "'hello' + ' characters'") String test);

@Counted
Expand Down Expand Up @@ -721,7 +721,7 @@ public String getReturnValueAnnotationForTagValueResolver() {

@Counted
@Override
public void getReturnValueAnnotationForTagValueExpression(
public void getAnnotationForTagValueExpression(
@MeterTag(key = "test", expression = "'hello' + ' characters'") String test) {
}

Expand Down Expand Up @@ -786,7 +786,7 @@ public String getReturnValueAnnotationForTagValueResolver() {

@Counted
@Override
public void getReturnValueAnnotationForTagValueExpression(String test) {
public void getAnnotationForTagValueExpression(String test) {
}

@Counted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ void meterTagOnSuperClass() {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsOnReturnValueWithText(AnnotatedTestClass annotatedClass) {
MeterTagClassInterface service = getProxyWithTimedAspect(annotatedClass.newInstance());

Expand All @@ -660,7 +660,7 @@ void meterTagsOnReturnValueWithText(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsOnReturnValueWithResolver(AnnotatedTestClass annotatedClass) {
MeterTagClassInterface service = getProxyWithTimedAspect(annotatedClass.newInstance());

Expand All @@ -673,7 +673,7 @@ void meterTagsOnReturnValueWithResolver(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsOnReturnValueWithExpression(AnnotatedTestClass annotatedClass) {
MeterTagClassInterface service = getProxyWithTimedAspect(annotatedClass.newInstance());

Expand All @@ -684,7 +684,7 @@ void meterTagsOnReturnValueWithExpression(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void multipleMeterTagsOnReturnValueWithExpression(AnnotatedTestClass annotatedClass) {
MeterTagClassInterface service = getProxyWithTimedAspect(annotatedClass.newInstance());

Expand All @@ -698,7 +698,7 @@ void multipleMeterTagsOnReturnValueWithExpression(AnnotatedTestClass annotatedCl
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void multipleMeterTagsOnReturnValueWithinContainerWithExpression(AnnotatedTestClass annotatedClass) {
MeterTagClassInterface service = getProxyWithTimedAspect(annotatedClass.newInstance());

Expand Down

0 comments on commit fd55d3e

Please sign in to comment.