Reflect grouping in directory structure

This commit is contained in:
Andy Wilkinson
2022-10-28 14:36:50 +01:00
parent 393e1cb6bf
commit 7112a4b6a4
788 changed files with 9 additions and 100 deletions

View File

@@ -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"));
}
}

View File

@@ -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());
};
}
}

View File

@@ -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() {
}
}

View File

@@ -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";
}
}