0
私はクラスBigManPlay
は、インタフェースPerformance
を実装しています。だから私は、次のアスペクトクラスを記述します。ポイントカット「や」春AOPの組成物が
@Aspect
public class Audience {
@Pointcut("execution(* Chapter_4_2_1.concert.Performance.perform(..)) or within(Chapter_4_2_1.concert.Performance+)")
public void performance() {}
@Before("performance()")
public void silenceCellPhones() {
System.out.println("Silencing cell phones");
}
@Before("performance()")
public void takeSeats() {
System.out.println("Taking seats");
}
@AfterReturning("performance()")
public void applause() {
System.out.println("CLAP CLAP CLAP!!!");
}
}
次にJavaの設定クラス豆を配線する:次に
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = {"Chapter_4_2_1.concert"})
public class ConcertConfig {
@Bean
public Audience audience() {
return new Audience();
}
}
UTクラス:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=ConcertConfig.class)
public class PerformanceTest {
@Autowired
Performance bigManPlay;
@Rule
public final SystemOutRule log = new SystemOutRule().enableLog();
@Test
public void testWithPerformance() {
log.clearLog();
bigManPlay.perform();
assertEquals("Silencing cell phones" + System.lineSeparator()
+ "Taking seats" + System.lineSeparator()
+ "Performing 111!" + System.lineSeparator()
+ "CLAP CLAP CLAP!!!" + System.lineSeparator(), log.getLog());
}
@Test
public void testWithPerformance2() {
log.clearLog();
bigManPlay.perform2();
assertEquals("Silencing cell phones" + System.lineSeparator()
+ "Taking seats" + System.lineSeparator()
+ "Performing 222!" + System.lineSeparator()
+ "CLAP CLAP CLAP!!!" + System.lineSeparator(), log.getLog());
}
}
UTが失敗しています。
Performing 222!
testWithPerformance2()
出力のみwithin(Chapter_4_2_1.concert.Performance+)
はなぜ、有効になりませんか?