summaryrefslogtreecommitdiffstats
path: root/tests/new/AfterThrowingNotWoven.java
blob: 4b583e8905ecc13fb63e12c04db7c4c632db0946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import org.aspectj.testing.*;

public class AfterThrowingNotWoven {
    public static void main(String[] args) {
        try {
            new Server().doSomething();
        } catch (FaultException fe) {
            Tester.event("caught-in-main");
        }
        Tester.checkAllEvents();
    }
    static {
        Tester.expectEvent("caught");
        Tester.expectEvent("caught-in-main");
    }
}

class Server {
    public void doSomething() { 
        System.out.println("Doing something."); 
        throw new FaultException();
    }
} 

class DisabledException extends RuntimeException {}
class FaultException extends RuntimeException {}

aspect FaultHandler {

    private boolean Server.disabled = false;

    private void reportFault() {
        System.out.println("Failure! Please fix it.");
    }

    public static void fixServer(Server s) {
        s.disabled = false;
    }

    pointcut service(Server s): target(s) && call(public * *(..));

    before(Server s): service(s) {
        if (s.disabled) throw new DisabledException();
    }

    after(Server s) throwing (FaultException e): service(s) {
        s.disabled = true;
        Tester.event("caught");
    }
}