aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/VisitorTestCase.java
blob: d3a5304fe18479faafaade9fcf8432f7f20343a7 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
 * Copyright (c) 2005 Contributors.
 * All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *
 * Contributors:
 *   Alexandre Vasseur         initial implementation
 *******************************************************************************/
package org.aspectj.weaver.patterns;

import junit.framework.TestCase;

import java.util.HashSet;
import java.util.Set;
import java.io.LineNumberReader;
import java.io.FileReader;

import org.aspectj.weaver.patterns.DumpPointcutVisitor;
import org.aspectj.weaver.patterns.PatternParser;
import org.aspectj.weaver.patterns.TypePattern;

/**
 * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
 */
public class VisitorTestCase extends TestCase {

    private Set<String> pointcuts = new HashSet<>();
    private Set<String> typePatterns = new HashSet<>();

    protected void setUp() throws Exception {
        super.setUp();
        LineNumberReader rp = new LineNumberReader(new FileReader("../weaver/testdata/visitor.pointcuts.txt"));
        feed(rp, pointcuts);
        rp.close();
        LineNumberReader rt = new LineNumberReader(new FileReader("../weaver/testdata/visitor.typepatterns.txt"));
        feed(rt, typePatterns);
        rt.close();
    }

    private void feed(LineNumberReader r, Set<String> set) throws Exception {
        for (String line = r.readLine(); line != null; line = r.readLine()) {
            set.add(line);
        }
    }

    public void testPointcuts() {
        if (pointcuts.isEmpty()) {
            fail("Empty pointcuts file!");
        }
        for (String pointcut: pointcuts) {
            try  {
                DumpPointcutVisitor.check(pointcut);
            } catch (Throwable t) {
                t.printStackTrace();
                fail("Failed on '"+pointcut+"': " +t.toString());
            }
        }
    }

    public void testTypePatterns() {
        if (typePatterns.isEmpty()) {
            fail("Empty typePatterns file!");
        }
        for (String tp: typePatterns) {
            try  {
                TypePattern p = new PatternParser(tp).parseTypePattern();
                DumpPointcutVisitor.check(p, true);
            } catch (Throwable t) {
                fail("Failed on '"+tp+"': " +t.toString());
            }
        }
    }
}