Reflect grouping in directory structure
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.example.aspect;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.smoketest.support.assertj.AssertableOutput;
|
||||
import org.springframework.aot.smoketest.support.junit.ApplicationTest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ApplicationTest
|
||||
class AspectApplicationAotTests {
|
||||
|
||||
@Test
|
||||
void shouldInterceptMethodA(AssertableOutput output) {
|
||||
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> assertThat(output)
|
||||
.hasSingleLineContaining("methodA: A-from-aspect").hasSingleLineContaining("methodB: B"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.aspect;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class AspectApplication {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
SpringApplication.run(AspectApplication.class, args);
|
||||
Thread.currentThread().join(); // To be able to measure memory consumption
|
||||
}
|
||||
|
||||
@Bean
|
||||
CommandLineRunner commandLineRunner(TestComponent testComponent) {
|
||||
return args -> {
|
||||
System.out.println("methodA: " + testComponent.methodA());
|
||||
System.out.println("methodB: " + testComponent.methodB());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.aspect;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class TestAspect {
|
||||
|
||||
@Around("pointcut()")
|
||||
public Object alterReturnValue(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
joinPoint.proceed();
|
||||
return "A-from-aspect";
|
||||
}
|
||||
|
||||
@Pointcut("execution(* com.example.aspect.Test*.methodA(..))")
|
||||
private void pointcut() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.example.aspect;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestComponent {
|
||||
|
||||
public String methodA() {
|
||||
return "A";
|
||||
}
|
||||
|
||||
public String methodB() {
|
||||
return "B";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user