package io.qameta.allure.junit4;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.junit.runner.notification.RunNotifier;

/**
 * @author Egor Borisov ehborisov@gmail.com
 */
@Aspect
public class AllureJunit4ListenerAspect {

    private final AllureJunit4 allureJunit4 = new AllureJunit4();

    @Pointcut("execution(org.junit.runner.notification.RunNotifier.new())")
    public void run() {
        //empty pointcut body
    }

    @After("run()")
    public void run(final JoinPoint point) {
        final RunNotifier notifier = (RunNotifier) point.getThis();
        notifier.addListener(allureJunit4);
    }
}

@@ -55,102 +55,33 @@
 ang.
-JoinPoint;%0Aimport org.aspectj.lang.annotation.After;%0Aimport org.aspectj.lang.annotation.Aspect
+annotation.AfterReturning
 ;%0Aim
@@ -113,23 +113,21 @@
 otation.
-Pointcu
+Aspec
 t;%0Aimpor
@@ -312,22 +312,16 @@
 4 allure
-Junit4
  = new A
@@ -345,27 +345,39 @@
    @
-Pointcut(%22execution
+AfterReturning(pointcut = %22call
 (org
@@ -418,209 +418,141 @@
 fier
++
 .new(
+..
 ))%22
-)%0A    public void run() %7B%0A        //empty pointcut body%0A    %7D%0A%0A    @After(%22run()%22)%0A    public void run(final JoinPoint point) %7B%0A        final RunNotifier notifier = (RunNotifier) point.getThis(
+, returning = %22notifier%22)%0A    public void addListener(final RunNotifier notifier) %7B%0A        notifier.removeListener(allure
 );%0A 
@@ -585,22 +585,16 @@
 r(allure
-Junit4
 );%0A    %7D
@@ -594,10 +594,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

fix junit4 aspect (via #90)