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.impl; |
34 | |
|
35 | |
import com.jeantessier.classreader.ClassfileLoader; |
36 | |
import org.jmock.Expectations; |
37 | |
import org.jmock.Mockery; |
38 | |
import org.jmock.integration.junit4.JMock; |
39 | |
import org.jmock.lib.legacy.ClassImposteriser; |
40 | |
import org.junit.Before; |
41 | |
import org.junit.Test; |
42 | |
import org.junit.runner.RunWith; |
43 | |
|
44 | |
import java.util.Collection; |
45 | |
import java.util.Collections; |
46 | |
|
47 | |
import static org.hamcrest.Matchers.is; |
48 | |
import static org.hamcrest.Matchers.nullValue; |
49 | |
import static org.junit.Assert.assertThat; |
50 | |
|
51 | |
@RunWith(JMock.class) |
52 | 43 | public class TestClassfile { |
53 | |
private static final String TEST_PACKAGE_NAME = "foo"; |
54 | |
private static final String TEST_CLASS_NAME = TEST_PACKAGE_NAME + ".Foo"; |
55 | |
private static final String TEST_FIELD_NAME = TEST_CLASS_NAME + ".foo"; |
56 | |
private static final String TEST_METHOD_SIGNATURE = TEST_CLASS_NAME + ".foo()"; |
57 | |
|
58 | |
private Mockery context; |
59 | |
|
60 | |
private ClassfileLoader loader; |
61 | |
private ConstantPool constantPool; |
62 | |
|
63 | |
@Before |
64 | |
public void setUp() throws Exception { |
65 | 16 | context = new Mockery(); |
66 | 16 | context.setImposteriser(ClassImposteriser.INSTANCE); |
67 | |
|
68 | 16 | loader = context.mock(ClassfileLoader.class); |
69 | 16 | constantPool = context.mock(ConstantPool.class); |
70 | 16 | } |
71 | |
|
72 | |
@Test |
73 | |
public void testGetPackageName() { |
74 | 1 | final Class_info classInfo = context.mock(Class_info.class); |
75 | |
|
76 | 1 | context.checking(new Expectations() {{ |
77 | 1 | one (constantPool).get(1); |
78 | 1 | will(returnValue(classInfo)); |
79 | 1 | one (classInfo).getPackageName(); |
80 | 1 | will(returnValue(TEST_PACKAGE_NAME)); |
81 | 1 | }}); |
82 | |
|
83 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
84 | |
|
85 | 1 | String actualValue = sut.getPackageName(); |
86 | 1 | assertThat("package name", actualValue, is(TEST_PACKAGE_NAME)); |
87 | 1 | } |
88 | |
|
89 | |
@Test |
90 | |
public void testLocateField_localField_succeed() throws Exception { |
91 | 1 | final Field_info expectedField = context.mock(Field_info.class, "located field"); |
92 | |
|
93 | 1 | Collection<Field_info> fields = Collections.singletonList(expectedField); |
94 | |
|
95 | 1 | context.checking(new Expectations() {{ |
96 | 1 | one (expectedField).getName(); |
97 | 1 | will(returnValue(TEST_FIELD_NAME)); |
98 | 1 | }}); |
99 | |
|
100 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), fields, Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
101 | |
|
102 | 1 | Field_info actualField = (Field_info) sut.locateField(TEST_FIELD_NAME); |
103 | 1 | assertThat("local field", actualField, is(expectedField)); |
104 | 1 | } |
105 | |
|
106 | |
@Test |
107 | |
public void testLocateField_publicInheritedField_succeed() throws Exception { |
108 | 1 | final String superclassName = "superclass"; |
109 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
110 | 1 | final Field_info expectedField = context.mock(Field_info.class, "located field"); |
111 | |
|
112 | 1 | expectClassNameLookup(2, superclassName); |
113 | |
|
114 | 1 | context.checking(new Expectations() {{ |
115 | 1 | one (loader).getClassfile(superclassName); |
116 | 1 | will(returnValue(superclass)); |
117 | 1 | one (superclass).locateField(TEST_FIELD_NAME); |
118 | 1 | will(returnValue(expectedField)); |
119 | 1 | one (expectedField).isPublic(); |
120 | 1 | will(returnValue(true)); |
121 | 1 | }}); |
122 | |
|
123 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
124 | |
|
125 | 1 | Field_info actualField = (Field_info) sut.locateField(TEST_FIELD_NAME); |
126 | 1 | assertThat("public field", actualField, is(expectedField)); |
127 | 1 | } |
128 | |
|
129 | |
@Test |
130 | |
public void testLocateField_protectedInheritedField_succeed() throws Exception { |
131 | 1 | final String superclassName = "superclass"; |
132 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
133 | 1 | final Field_info expectedField = context.mock(Field_info.class, "located field"); |
134 | |
|
135 | 1 | expectClassNameLookup(2, superclassName); |
136 | |
|
137 | 1 | context.checking(new Expectations() {{ |
138 | 1 | one (loader).getClassfile(superclassName); |
139 | 1 | will(returnValue(superclass)); |
140 | 1 | one (superclass).locateField(TEST_FIELD_NAME); |
141 | 1 | will(returnValue(expectedField)); |
142 | 1 | one (expectedField).isPublic(); |
143 | 1 | will(returnValue(false)); |
144 | 1 | one (expectedField).isProtected(); |
145 | 1 | will(returnValue(true)); |
146 | 1 | }}); |
147 | |
|
148 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
149 | |
|
150 | 1 | Field_info actualField = (Field_info) sut.locateField(TEST_FIELD_NAME); |
151 | 1 | assertThat("protected field", actualField, is(expectedField)); |
152 | 1 | } |
153 | |
|
154 | |
@Test |
155 | |
public void testLocateField_packageInheritedField_succeed() throws Exception { |
156 | 1 | final Class_info classInfo = context.mock(Class_info.class, "class info"); |
157 | 1 | final String superclassName = "superclass"; |
158 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
159 | 1 | final Field_info expectedField = context.mock(Field_info.class, "located field"); |
160 | |
|
161 | 1 | final Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
162 | |
|
163 | 1 | expectClassNameLookup(2, superclassName); |
164 | |
|
165 | 1 | context.checking(new Expectations() {{ |
166 | 1 | one (constantPool).get(1); |
167 | 1 | will(returnValue(classInfo)); |
168 | 1 | one (classInfo).getPackageName(); |
169 | 1 | will(returnValue(TEST_PACKAGE_NAME)); |
170 | 1 | one (loader).getClassfile(superclassName); |
171 | 1 | will(returnValue(superclass)); |
172 | 1 | one (superclass).getPackageName(); |
173 | 1 | will(returnValue(TEST_PACKAGE_NAME)); |
174 | 1 | one (superclass).locateField(TEST_FIELD_NAME); |
175 | 1 | will(returnValue(expectedField)); |
176 | 1 | one (expectedField).isPublic(); |
177 | 1 | will(returnValue(false)); |
178 | 1 | one (expectedField).isProtected(); |
179 | 1 | will(returnValue(false)); |
180 | 1 | one (expectedField).isPackage(); |
181 | 1 | will(returnValue(true)); |
182 | 1 | one (expectedField).getClassfile(); |
183 | 1 | will(returnValue(sut)); |
184 | 1 | }}); |
185 | |
|
186 | 1 | Field_info actualField = (Field_info) sut.locateField(TEST_FIELD_NAME); |
187 | 1 | assertThat("package field", actualField, is(expectedField)); |
188 | 1 | } |
189 | |
|
190 | |
@Test |
191 | |
public void testLocateField_packageInheritedField_fail() throws Exception { |
192 | 1 | final Class_info classInfo = context.mock(Class_info.class, "class info"); |
193 | 1 | final String superclassName = "superclass"; |
194 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
195 | 1 | final Field_info expectedField = context.mock(Field_info.class, "located field"); |
196 | |
|
197 | 1 | final Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
198 | |
|
199 | 1 | expectClassNameLookup(2, superclassName); |
200 | |
|
201 | 1 | context.checking(new Expectations() {{ |
202 | 1 | one (constantPool).get(1); |
203 | 1 | will(returnValue(classInfo)); |
204 | 1 | one (classInfo).getPackageName(); |
205 | 1 | will(returnValue(TEST_PACKAGE_NAME)); |
206 | 1 | one (loader).getClassfile(superclassName); |
207 | 1 | will(returnValue(superclass)); |
208 | 1 | one (superclass).getPackageName(); |
209 | 1 | will(returnValue("")); |
210 | 1 | one (superclass).locateField(TEST_FIELD_NAME); |
211 | 1 | will(returnValue(expectedField)); |
212 | 1 | one (expectedField).isPublic(); |
213 | 1 | will(returnValue(false)); |
214 | 1 | one (expectedField).isProtected(); |
215 | 1 | will(returnValue(false)); |
216 | 1 | one (expectedField).isPackage(); |
217 | 1 | will(returnValue(true)); |
218 | 1 | one (expectedField).getClassfile(); |
219 | 1 | will(returnValue(sut)); |
220 | 1 | }}); |
221 | |
|
222 | 1 | Field_info actualField = (Field_info) sut.locateField(TEST_FIELD_NAME); |
223 | 1 | assertThat("package field", actualField, is(nullValue())); |
224 | 1 | } |
225 | |
|
226 | |
@Test |
227 | |
public void testLocateField_privateInheritedField_fail() throws Exception { |
228 | 1 | final String superclassName = "superclass"; |
229 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
230 | 1 | final Field_info expectedField = context.mock(Field_info.class, "located field"); |
231 | |
|
232 | 1 | expectClassNameLookup(2, superclassName); |
233 | |
|
234 | 1 | context.checking(new Expectations() {{ |
235 | 1 | one (loader).getClassfile(superclassName); |
236 | 1 | will(returnValue(superclass)); |
237 | 1 | one (superclass).locateField(TEST_FIELD_NAME); |
238 | 1 | will(returnValue(expectedField)); |
239 | 1 | one (expectedField).isPublic(); |
240 | 1 | will(returnValue(false)); |
241 | 1 | one (expectedField).isProtected(); |
242 | 1 | will(returnValue(false)); |
243 | 1 | one (expectedField).isPackage(); |
244 | 1 | will(returnValue(false)); |
245 | 1 | }}); |
246 | |
|
247 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
248 | |
|
249 | 1 | Field_info actualField = (Field_info) sut.locateField(TEST_FIELD_NAME); |
250 | 1 | assertThat("local field", actualField, is(nullValue())); |
251 | 1 | } |
252 | |
|
253 | |
@Test |
254 | |
public void testLocateMethod_localMethod_succeed() throws Exception { |
255 | 1 | final Method_info expectedMethod = context.mock(Method_info.class, "located method"); |
256 | |
|
257 | 1 | Collection<Method_info> methods = Collections.singletonList(expectedMethod); |
258 | |
|
259 | 1 | context.checking(new Expectations() {{ |
260 | 1 | one (expectedMethod).getSignature(); |
261 | 1 | will(returnValue(TEST_METHOD_SIGNATURE)); |
262 | 1 | }}); |
263 | |
|
264 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), methods, Collections.<Attribute_info>emptyList()); |
265 | |
|
266 | 1 | Method_info actualMethod = (Method_info) sut.locateMethod(TEST_METHOD_SIGNATURE); |
267 | 1 | assertThat("local method", actualMethod, is(expectedMethod)); |
268 | 1 | } |
269 | |
|
270 | |
@Test |
271 | |
public void testLocateMethod_publicInheritedMethod_succeed() throws Exception { |
272 | 1 | final String superclassName = "superclass"; |
273 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
274 | 1 | final Method_info expectedMethod = context.mock(Method_info.class, "located method"); |
275 | |
|
276 | 1 | expectClassNameLookup(2, superclassName); |
277 | |
|
278 | 1 | context.checking(new Expectations() {{ |
279 | 1 | one (loader).getClassfile(superclassName); |
280 | 1 | will(returnValue(superclass)); |
281 | 1 | one (superclass).locateMethod(TEST_METHOD_SIGNATURE); |
282 | 1 | will(returnValue(expectedMethod)); |
283 | 1 | one (expectedMethod).isPublic(); |
284 | 1 | will(returnValue(true)); |
285 | 1 | }}); |
286 | |
|
287 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
288 | |
|
289 | 1 | Method_info actualMethod = (Method_info) sut.locateMethod(TEST_METHOD_SIGNATURE); |
290 | 1 | assertThat("public method", actualMethod, is(expectedMethod)); |
291 | 1 | } |
292 | |
|
293 | |
@Test |
294 | |
public void testLocateMethod_protectedInheritedMethod_succeed() throws Exception { |
295 | 1 | final String superclassName = "superclass"; |
296 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
297 | 1 | final Method_info expectedMethod = context.mock(Method_info.class, "located method"); |
298 | |
|
299 | 1 | expectClassNameLookup(2, superclassName); |
300 | |
|
301 | 1 | context.checking(new Expectations() {{ |
302 | 1 | one (loader).getClassfile(superclassName); |
303 | 1 | will(returnValue(superclass)); |
304 | 1 | one (superclass).locateMethod(TEST_METHOD_SIGNATURE); |
305 | 1 | will(returnValue(expectedMethod)); |
306 | 1 | one (expectedMethod).isPublic(); |
307 | 1 | will(returnValue(false)); |
308 | 1 | one (expectedMethod).isProtected(); |
309 | 1 | will(returnValue(true)); |
310 | 1 | }}); |
311 | |
|
312 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
313 | |
|
314 | 1 | Method_info actualMethod = (Method_info) sut.locateMethod(TEST_METHOD_SIGNATURE); |
315 | 1 | assertThat("protected method", actualMethod, is(expectedMethod)); |
316 | 1 | } |
317 | |
|
318 | |
@Test |
319 | |
public void testLocateMethod_packageInheritedMethod_succeed() throws Exception { |
320 | 1 | final Class_info classInfo = context.mock(Class_info.class, "class info"); |
321 | 1 | final String superclassName = "superclass"; |
322 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
323 | 1 | final Method_info expectedMethod = context.mock(Method_info.class, "located method"); |
324 | |
|
325 | 1 | final Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
326 | |
|
327 | 1 | expectClassNameLookup(2, superclassName); |
328 | |
|
329 | 1 | context.checking(new Expectations() {{ |
330 | 1 | one (constantPool).get(1); |
331 | 1 | will(returnValue(classInfo)); |
332 | 1 | one (classInfo).getPackageName(); |
333 | 1 | will(returnValue(TEST_PACKAGE_NAME)); |
334 | 1 | one (loader).getClassfile(superclassName); |
335 | 1 | will(returnValue(superclass)); |
336 | 1 | one (superclass).getPackageName(); |
337 | 1 | will(returnValue(TEST_PACKAGE_NAME)); |
338 | 1 | one (superclass).locateMethod(TEST_METHOD_SIGNATURE); |
339 | 1 | will(returnValue(expectedMethod)); |
340 | 1 | one (expectedMethod).isPublic(); |
341 | 1 | will(returnValue(false)); |
342 | 1 | one (expectedMethod).isProtected(); |
343 | 1 | will(returnValue(false)); |
344 | 1 | one (expectedMethod).isPackage(); |
345 | 1 | will(returnValue(true)); |
346 | 1 | one (expectedMethod).getClassfile(); |
347 | 1 | will(returnValue(sut)); |
348 | 1 | }}); |
349 | |
|
350 | 1 | Method_info actualMethod = (Method_info) sut.locateMethod(TEST_METHOD_SIGNATURE); |
351 | 1 | assertThat("package method", actualMethod, is(expectedMethod)); |
352 | 1 | } |
353 | |
|
354 | |
@Test |
355 | |
public void testLocateMethod_packageInheritedMethod_fail() throws Exception { |
356 | 1 | final Class_info classInfo = context.mock(Class_info.class, "class info"); |
357 | 1 | final String superclassName = "superclass"; |
358 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
359 | 1 | final Method_info expectedMethod = context.mock(Method_info.class, "located method"); |
360 | |
|
361 | 1 | final Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
362 | |
|
363 | 1 | expectClassNameLookup(2, superclassName); |
364 | |
|
365 | 1 | context.checking(new Expectations() {{ |
366 | 1 | one (constantPool).get(1); |
367 | 1 | will(returnValue(classInfo)); |
368 | 1 | one (classInfo).getPackageName(); |
369 | 1 | will(returnValue(TEST_PACKAGE_NAME)); |
370 | 1 | one (loader).getClassfile(superclassName); |
371 | 1 | will(returnValue(superclass)); |
372 | 1 | one (superclass).getPackageName(); |
373 | 1 | will(returnValue("")); |
374 | 1 | one (superclass).locateMethod(TEST_METHOD_SIGNATURE); |
375 | 1 | will(returnValue(expectedMethod)); |
376 | 1 | one (expectedMethod).isPublic(); |
377 | 1 | will(returnValue(false)); |
378 | 1 | one (expectedMethod).isProtected(); |
379 | 1 | will(returnValue(false)); |
380 | 1 | one (expectedMethod).isPackage(); |
381 | 1 | will(returnValue(true)); |
382 | 1 | one (expectedMethod).getClassfile(); |
383 | 1 | will(returnValue(sut)); |
384 | 1 | }}); |
385 | |
|
386 | 1 | Method_info actualMethod = (Method_info) sut.locateMethod(TEST_METHOD_SIGNATURE); |
387 | 1 | assertThat("package method", actualMethod, is(nullValue())); |
388 | 1 | } |
389 | |
|
390 | |
@Test |
391 | |
public void testLocateMethod_privateInheritedMethod_fail() throws Exception { |
392 | 1 | final String superclassName = "superclass"; |
393 | 1 | final Classfile superclass = context.mock(Classfile.class, "superclass"); |
394 | 1 | final Method_info expectedMethod = context.mock(Method_info.class, "located method"); |
395 | |
|
396 | 1 | expectClassNameLookup(2, superclassName); |
397 | |
|
398 | 1 | context.checking(new Expectations() {{ |
399 | 1 | one (loader).getClassfile(superclassName); |
400 | 1 | will(returnValue(superclass)); |
401 | 1 | one (superclass).locateMethod(TEST_METHOD_SIGNATURE); |
402 | 1 | will(returnValue(expectedMethod)); |
403 | 1 | one (expectedMethod).isPublic(); |
404 | 1 | will(returnValue(false)); |
405 | 1 | one (expectedMethod).isProtected(); |
406 | 1 | will(returnValue(false)); |
407 | 1 | one (expectedMethod).isPackage(); |
408 | 1 | will(returnValue(false)); |
409 | 1 | }}); |
410 | |
|
411 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
412 | |
|
413 | 1 | Method_info actualMethod = (Method_info) sut.locateMethod(TEST_METHOD_SIGNATURE); |
414 | 1 | assertThat("private method", actualMethod, is(nullValue())); |
415 | 1 | } |
416 | |
|
417 | |
@Test |
418 | |
public void testIsInnerClass_matchingInnerClassInfo_returnsTrue() throws Exception { |
419 | 1 | final InnerClasses_attribute innerClasses_attribute = context.mock(InnerClasses_attribute.class); |
420 | 1 | final InnerClass innerClass = context.mock(InnerClass.class); |
421 | |
|
422 | 1 | expectClassNameLookup(1, TEST_CLASS_NAME); |
423 | |
|
424 | 1 | context.checking(new Expectations() {{ |
425 | 1 | one (innerClasses_attribute).getInnerClasses(); |
426 | 1 | will(returnValue(Collections.<InnerClass>singleton(innerClass))); |
427 | 1 | one (innerClass).getInnerClassInfo(); |
428 | 1 | will(returnValue(TEST_CLASS_NAME)); |
429 | 1 | }}); |
430 | |
|
431 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>singleton(innerClasses_attribute)); |
432 | |
|
433 | 1 | assertThat("inner class", sut.isInnerClass(), is(true)); |
434 | 1 | } |
435 | |
|
436 | |
@Test |
437 | |
public void testIsInnerClass_emptyInnerClassInfo_returnsFalse() throws Exception { |
438 | 1 | final InnerClasses_attribute innerClasses_attribute = context.mock(InnerClasses_attribute.class); |
439 | 1 | final InnerClass innerClass = context.mock(InnerClass.class); |
440 | |
|
441 | 1 | expectClassNameLookup(1, TEST_CLASS_NAME); |
442 | |
|
443 | 1 | context.checking(new Expectations() {{ |
444 | 1 | one (innerClasses_attribute).getInnerClasses(); |
445 | 1 | will(returnValue(Collections.<InnerClass>singleton(innerClass))); |
446 | 1 | one (innerClass).getInnerClassInfo(); |
447 | 1 | will(returnValue("")); |
448 | 1 | }}); |
449 | |
|
450 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>singleton(innerClasses_attribute)); |
451 | |
|
452 | 1 | assertThat("inner class", sut.isInnerClass(), is(false)); |
453 | 1 | } |
454 | |
|
455 | |
@Test |
456 | |
public void testIsInnerClass_noInnerClassInfo_returnsFalse() throws Exception { |
457 | 1 | Classfile sut = new Classfile(loader, constantPool, 0x0, 1, 2, Collections.<Class_info>emptyList(), Collections.<Field_info>emptyList(), Collections.<Method_info>emptyList(), Collections.<Attribute_info>emptyList()); |
458 | |
|
459 | 1 | assertThat("inner class", sut.isInnerClass(), is(false)); |
460 | 1 | } |
461 | |
|
462 | |
private void expectClassNameLookup(final int index, final String value) { |
463 | 12 | final Class_info class_info = context.mock(Class_info.class); |
464 | |
|
465 | 12 | context.checking(new Expectations() {{ |
466 | 12 | one (constantPool).get(index); |
467 | 12 | will(returnValue(class_info)); |
468 | 12 | one (class_info).getName(); |
469 | 12 | will(returnValue(value)); |
470 | 12 | }}); |
471 | 12 | } |
472 | |
} |