blob: f355eb6eea248f6adc5989ef1ed0b985972ca38e (
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
77
78
79
80
81
82
83
84
85
86
87
88
|
package mypackage;
import java.util.Collection;
import junit.framework.TestCase;
/**
* A test case depicting the scenario where a parameterized interface includes a method
* that takes a parameterized object. A interface-based pointcut (that does not include
* '+') fails to select such a method.
*
* @author Ramnivas Laddad
*
*/
public class GenericInterfaceWithGenericArgumentPointcutBug extends TestCase {
private GenericInterface<String> testObject = new GenericImpl<String>();
public static void main(String[] args) throws Exception {
GenericInterfaceWithGenericArgumentPointcutBug instance = new GenericInterfaceWithGenericArgumentPointcutBug();
instance.setUp();
instance.testGenericInterfaceGenericArgExecution();
instance.setUp();
instance.testGenericInterfaceNonGenericArgExecution();
instance.setUp();
instance.testgenericInterfaceSubtypeGenericArgExecution();
}
@Override
protected void setUp() throws Exception {
TestAspect.aspectOf().genericInterfaceNonGenericArgExecutionCount = 0;
TestAspect.aspectOf().genericInterfaceGenericArgExecutionCount = 0;
TestAspect.aspectOf().genericInterfaceSubtypeGenericArgExecutionCount = 0;
}
public void testGenericInterfaceNonGenericArgExecution() {
testObject.save("");
assertEquals(1, TestAspect.aspectOf().genericInterfaceNonGenericArgExecutionCount);
}
public void testGenericInterfaceGenericArgExecution() {
testObject.saveAll(null);
assertEquals(1, TestAspect.aspectOf().genericInterfaceGenericArgExecutionCount);
}
public void testgenericInterfaceSubtypeGenericArgExecution() {
testObject.saveAll(null);
assertEquals(1, TestAspect.aspectOf().genericInterfaceSubtypeGenericArgExecutionCount);
}
static interface GenericInterface<T> {
public void save(T bean);
public void saveAll(Collection<T> beans);
}
static class GenericImpl<T> implements GenericInterface<T> {
public void save(T bean) {}
public void saveAll(Collection<T> beans) {}
}
static aspect TestAspect {
int genericInterfaceNonGenericArgExecutionCount;
int genericInterfaceGenericArgExecutionCount;
int genericInterfaceSubtypeGenericArgExecutionCount;
pointcut genericInterfaceNonGenericArgExecution()
: execution(* GenericInterface.save(..));
pointcut genericInterfaceGenericArgExecution()
: execution(* GenericInterface.saveAll(..));
pointcut genericInterfaceSubtypeGenericArgExecution()
: execution(* GenericInterface+.saveAll(..));
before() : genericInterfaceNonGenericArgExecution() {
genericInterfaceNonGenericArgExecutionCount++;
}
before() : genericInterfaceGenericArgExecution() {
genericInterfaceGenericArgExecutionCount++;
}
before() : genericInterfaceSubtypeGenericArgExecution() {
genericInterfaceSubtypeGenericArgExecutionCount++;
}
}
}
|