aboutsummaryrefslogtreecommitdiffstats
path: root/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/AnonymousClassTest.java
blob: b5ce1c8aaaf4d2c7b2d947362be8b1a81e4dc198 (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
/**
 * 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:
 *     Adrian Colyer -     initial implementation
 */
package org.aspectj.apache.bcel.classfile.tests;

import java.io.File;

import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.util.ClassPath;
import org.aspectj.apache.bcel.util.SyntheticRepository;

import junit.framework.TestCase;

/**
 * @author adrian colyer
 *
 */
public class AnonymousClassTest extends TestCase {

	private SyntheticRepository repos;

	public void testRegularClassIsNotAnonymous() throws ClassNotFoundException {
		JavaClass clazz = repos.loadClass("AnonymousClassTest");
		assertFalse("regular outer classes are not anonymous",clazz.isAnonymous());
		assertFalse("regular outer classes are not nested",clazz.isNested());
	}

	public void testNamedInnerClassIsNotAnonymous() throws ClassNotFoundException {
		JavaClass clazz = repos.loadClass("AnonymousClassTest$X");
		assertFalse("regular inner classes are not anonymous",clazz.isAnonymous());
		assertTrue("regular inner classes are nested",clazz.isNested());
	}

	public void testStaticInnerClassIsNotAnonymous() throws ClassNotFoundException {
		JavaClass clazz = repos.loadClass("AnonymousClassTest$Y");
		assertFalse("regular static inner classes are not anonymous",clazz.isAnonymous());
		assertTrue("regular static inner classes are nested",clazz.isNested());
	}

	public void testAnonymousInnerClassIsAnonymous() throws ClassNotFoundException {
		JavaClass clazz = repos.loadClass("AnonymousClassTest$1");
		assertTrue("anonymous inner classes are anonymous",clazz.isAnonymous());
		assertTrue("anonymous inner classes are anonymous",clazz.isNested());
	}

	protected void setUp() throws Exception {
		ClassPath cp =
			new ClassPath("testdata"+File.separator+"testcode.jar"+File.pathSeparator+System.getProperty("java.class.path"));
		repos = SyntheticRepository.getInstance(cp);
	}

}