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 |
| package com.jeantessier.classreader; |
34 |
| |
35 |
| import org.jmock.*; |
36 |
| import org.jmock.integration.junit3.*; |
37 |
| |
38 |
| public class TestSymbolGathererWithStrategy extends MockObjectTestCase { |
39 |
| private SymbolGathererStrategy mockStrategy; |
40 |
| |
41 |
| private SymbolGatherer sut; |
42 |
| |
43 |
8
| protected void setUp() throws Exception {
|
44 |
8
| super.setUp();
|
45 |
| |
46 |
8
| mockStrategy = mock(SymbolGathererStrategy.class);
|
47 |
| |
48 |
8
| sut = new SymbolGatherer(mockStrategy);
|
49 |
| } |
50 |
| |
51 |
1
| public void testVisitClassfile_NotMatching() {
|
52 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
53 |
| |
54 |
1
| checking(new Expectations() {{
|
55 |
1
| one (mockStrategy).isMatching(mockClassfile); will(returnValue(false));
|
56 |
| |
57 |
1
| one (mockClassfile).getAttributes();
|
58 |
1
| one (mockClassfile).getAllFields();
|
59 |
1
| one (mockClassfile).getAllMethods();
|
60 |
| }}); |
61 |
| |
62 |
1
| sut.visitClassfile(mockClassfile);
|
63 |
| |
64 |
1
| assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
|
65 |
| } |
66 |
| |
67 |
1
| public void testVisitClassfile_Matching() {
|
68 |
1
| final String expectedName = "Foobar";
|
69 |
| |
70 |
1
| final Classfile mockClassfile = mock(Classfile.class);
|
71 |
| |
72 |
1
| checking(new Expectations() {{
|
73 |
1
| one (mockStrategy).isMatching(mockClassfile); will(returnValue(true));
|
74 |
1
| one (mockClassfile).getClassName(); will(returnValue(expectedName));
|
75 |
| |
76 |
1
| one (mockClassfile).getAttributes();
|
77 |
1
| one (mockClassfile).getAllFields();
|
78 |
1
| one (mockClassfile).getAllMethods();
|
79 |
| }}); |
80 |
| |
81 |
1
| sut.visitClassfile(mockClassfile);
|
82 |
| |
83 |
1
| assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
|
84 |
1
| assertTrue("Missing class name " + sut.getCollection(), sut.getCollection().contains(expectedName));
|
85 |
| } |
86 |
| |
87 |
1
| public void testVisitField_info_NotMatching() {
|
88 |
1
| final Field_info mockField = mock(Field_info.class);
|
89 |
| |
90 |
1
| checking(new Expectations() {{
|
91 |
1
| one (mockStrategy).isMatching(mockField); will(returnValue(false));
|
92 |
| |
93 |
1
| one (mockField).getAttributes();
|
94 |
| }}); |
95 |
| |
96 |
1
| sut.visitField_info(mockField);
|
97 |
| |
98 |
1
| assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
|
99 |
| } |
100 |
| |
101 |
1
| public void testVisitField_info_Matching() {
|
102 |
1
| final String expectedName = "Foobar.foobar";
|
103 |
| |
104 |
1
| final Field_info mockField = mock(Field_info.class);
|
105 |
| |
106 |
1
| checking(new Expectations() {{
|
107 |
1
| one (mockStrategy).isMatching(mockField); will(returnValue(true));
|
108 |
1
| one (mockField).getFullSignature(); will(returnValue(expectedName));
|
109 |
| |
110 |
1
| one (mockField).getAttributes();
|
111 |
| }}); |
112 |
| |
113 |
1
| sut.visitField_info(mockField);
|
114 |
| |
115 |
1
| assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
|
116 |
1
| assertTrue("Missing class name " + sut.getCollection(), sut.getCollection().contains(expectedName));
|
117 |
| } |
118 |
| |
119 |
1
| public void testVisitMethod_info_NotMatching() {
|
120 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
121 |
| |
122 |
1
| checking(new Expectations() {{
|
123 |
1
| one (mockStrategy).isMatching(mockMethod); will(returnValue(false));
|
124 |
| |
125 |
1
| one (mockMethod).getAttributes();
|
126 |
| }}); |
127 |
| |
128 |
1
| sut.visitMethod_info(mockMethod);
|
129 |
| |
130 |
1
| assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
|
131 |
| } |
132 |
| |
133 |
1
| public void testVisitMethod_info_Matching() {
|
134 |
1
| final String expectedName = "Foobar.foobar";
|
135 |
| |
136 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
137 |
| |
138 |
1
| checking(new Expectations() {{
|
139 |
1
| one (mockStrategy).isMatching(mockMethod); will(returnValue(true));
|
140 |
1
| one (mockMethod).getFullSignature(); will(returnValue(expectedName));
|
141 |
| |
142 |
1
| one (mockMethod).getAttributes();
|
143 |
| }}); |
144 |
| |
145 |
1
| sut.visitMethod_info(mockMethod);
|
146 |
| |
147 |
1
| assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
|
148 |
1
| assertTrue("Missing class name " + sut.getCollection(), sut.getCollection().contains(expectedName));
|
149 |
| } |
150 |
| |
151 |
| |
152 |
1
| public void testVisitLocalVariable_NotMatching() {
|
153 |
1
| final LocalVariable mockLocalVariable = mock(LocalVariable.class);
|
154 |
| |
155 |
1
| checking(new Expectations() {{
|
156 |
1
| one (mockStrategy).isMatching(mockLocalVariable); will(returnValue(false));
|
157 |
| }}); |
158 |
| |
159 |
1
| sut.visitLocalVariable(mockLocalVariable);
|
160 |
| |
161 |
1
| assertTrue("Added non-matching class " + sut.getCollection(), sut.getCollection().isEmpty());
|
162 |
| } |
163 |
| |
164 |
1
| public void testVisitLocalVariable_Matching() {
|
165 |
1
| final String expectedName = "Foobar.foobar";
|
166 |
| |
167 |
1
| final Method_info mockMethod = mock(Method_info.class);
|
168 |
1
| final LocalVariable mockLocalVariable = mock(LocalVariable.class);
|
169 |
| |
170 |
1
| checking(new Expectations() {{
|
171 |
1
| one (mockStrategy).isMatching(mockLocalVariable); will(returnValue(true));
|
172 |
1
| one (mockMethod).getFullSignature(); will(returnValue(expectedName));
|
173 |
1
| one (mockLocalVariable).getName(); will(returnValue(expectedName));
|
174 |
| }}); |
175 |
| |
176 |
1
| sut.setCurrentMethodForTesting(mockMethod);
|
177 |
1
| sut.visitLocalVariable(mockLocalVariable);
|
178 |
| |
179 |
1
| assertEquals("Wrong size for " + sut.getCollection(), 1, sut.getCollection().size());
|
180 |
| } |
181 |
| } |