diff options
author | aclement <aclement> | 2009-09-10 03:59:33 +0000 |
---|---|---|
committer | aclement <aclement> | 2009-09-10 03:59:33 +0000 |
commit | f7fd9e7bf37d14fad7cacc6b24221d811e5077fa (patch) | |
tree | b1bbcbea389e61a0f8bbd4ecf64d1cfd0596cbf1 /bcel-builder/testsrc | |
parent | 6b3a690e6657bbf92a73301309983d37e5eceee5 (diff) | |
download | aspectj-f7fd9e7bf37d14fad7cacc6b24221d811e5077fa.tar.gz aspectj-f7fd9e7bf37d14fad7cacc6b24221d811e5077fa.zip |
refactoring
Diffstat (limited to 'bcel-builder/testsrc')
-rw-r--r-- | bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/EnclosingMethodAttributeTest.java | 78 | ||||
-rw-r--r-- | bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java | 2 |
2 files changed, 37 insertions, 43 deletions
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/EnclosingMethodAttributeTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/EnclosingMethodAttributeTest.java index 305179a3c..bcf4403bb 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/EnclosingMethodAttributeTest.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/EnclosingMethodAttributeTest.java @@ -21,82 +21,76 @@ import org.aspectj.apache.bcel.classfile.EnclosingMethod; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.util.SyntheticRepository; - public class EnclosingMethodAttributeTest extends BcelTestCase { - + + @Override protected void setUp() throws Exception { super.setUp(); } - - + /** - * Verify for an inner class declared inside the 'main' method that the enclosing method - * attribute is set correctly. + * Verify for an inner class declared inside the 'main' method that the enclosing method attribute is set correctly. */ public void testCheckMethodLevelNamedInnerClass() throws ClassNotFoundException { SyntheticRepository repos = createRepos("testcode.jar"); JavaClass clazz = repos.loadClass("AttributeTestClassEM01$1S"); ConstantPool pool = clazz.getConstantPool(); - Attribute[] encMethodAttrs = findAttribute("EnclosingMethod",clazz); - assertTrue("Expected 1 EnclosingMethod attribute but found "+encMethodAttrs.length, - encMethodAttrs.length==1); - EnclosingMethod em = (EnclosingMethod)encMethodAttrs[0]; - String enclosingClassName = em.getEnclosingClass().getBytes(pool); - String enclosingMethodName= em.getEnclosingMethod().getName(pool); - assertTrue("Expected class name to be 'AttributeTestClassEM01' but was "+enclosingClassName, - enclosingClassName.equals("AttributeTestClassEM01")); - assertTrue("Expected method name to be 'main' but was "+enclosingMethodName, - enclosingMethodName.equals("main")); + Attribute[] encMethodAttrs = findAttribute("EnclosingMethod", clazz); + assertTrue("Expected 1 EnclosingMethod attribute but found " + encMethodAttrs.length, encMethodAttrs.length == 1); + EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0]; + String enclosingClassName = em.getEnclosingClass().getConstantValue(pool); + String enclosingMethodName = em.getEnclosingMethod().getName(pool); + assertTrue("Expected class name to be 'AttributeTestClassEM01' but was " + enclosingClassName, enclosingClassName + .equals("AttributeTestClassEM01")); + assertTrue("Expected method name to be 'main' but was " + enclosingMethodName, enclosingMethodName.equals("main")); } - + /** - * Verify for an inner class declared at the type level that the EnclosingMethod attribute - * is set correctly (i.e. to a null value) + * Verify for an inner class declared at the type level that the EnclosingMethod attribute is set correctly (i.e. to a null + * value) */ public void testCheckClassLevelNamedInnerClass() throws ClassNotFoundException { SyntheticRepository repos = createRepos("testcode.jar"); JavaClass clazz = repos.loadClass("AttributeTestClassEM02$1"); ConstantPool pool = clazz.getConstantPool(); - Attribute[] encMethodAttrs = findAttribute("EnclosingMethod",clazz); - assertTrue("Expected 1 EnclosingMethod attribute but found "+encMethodAttrs.length, - encMethodAttrs.length==1); - EnclosingMethod em = (EnclosingMethod)encMethodAttrs[0]; - String enclosingClassName = em.getEnclosingClass().getBytes(pool); - assertTrue("The class is not within a method, so method_index should be null, but it is "+ - em.getEnclosingMethodIndex(),em.getEnclosingMethodIndex() == 0); - assertTrue("Expected class name to be 'AttributeTestClassEM02' but was "+enclosingClassName, - enclosingClassName.equals("AttributeTestClassEM02")); + Attribute[] encMethodAttrs = findAttribute("EnclosingMethod", clazz); + assertTrue("Expected 1 EnclosingMethod attribute but found " + encMethodAttrs.length, encMethodAttrs.length == 1); + EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0]; + String enclosingClassName = em.getEnclosingClass().getConstantValue(pool); + assertTrue("The class is not within a method, so method_index should be null, but it is " + em.getEnclosingMethodIndex(), + em.getEnclosingMethodIndex() == 0); + assertTrue("Expected class name to be 'AttributeTestClassEM02' but was " + enclosingClassName, enclosingClassName + .equals("AttributeTestClassEM02")); } - + /** * Check that we can save and load the attribute correctly. */ - public void testAttributeSerializtion() throws ClassNotFoundException,IOException { + public void testAttributeSerializtion() throws ClassNotFoundException, IOException { // Read in the class SyntheticRepository repos = createRepos("testcode.jar"); JavaClass clazz = repos.loadClass("AttributeTestClassEM02$1"); ConstantPool pool = clazz.getConstantPool(); - Attribute[] encMethodAttrs = findAttribute("EnclosingMethod",clazz); - assertTrue("Expected 1 EnclosingMethod attribute but found "+encMethodAttrs.length, - encMethodAttrs.length==1); - + Attribute[] encMethodAttrs = findAttribute("EnclosingMethod", clazz); + assertTrue("Expected 1 EnclosingMethod attribute but found " + encMethodAttrs.length, encMethodAttrs.length == 1); + // Write it out File tfile = createTestdataFile("AttributeTestClassEM02$1.class"); clazz.dump(tfile); - + // Read in the new version and check it is OK SyntheticRepository repos2 = createRepos("."); JavaClass clazz2 = repos2.loadClass("AttributeTestClassEM02$1"); - EnclosingMethod em = (EnclosingMethod)encMethodAttrs[0]; - String enclosingClassName = em.getEnclosingClass().getBytes(pool); - assertTrue("The class is not within a method, so method_index should be null, but it is "+ - em.getEnclosingMethodIndex(),em.getEnclosingMethodIndex() == 0); - assertTrue("Expected class name to be 'AttributeTestClassEM02' but was "+enclosingClassName, - enclosingClassName.equals("AttributeTestClassEM02")); + EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0]; + String enclosingClassName = em.getEnclosingClass().getConstantValue(pool); + assertTrue("The class is not within a method, so method_index should be null, but it is " + em.getEnclosingMethodIndex(), + em.getEnclosingMethodIndex() == 0); + assertTrue("Expected class name to be 'AttributeTestClassEM02' but was " + enclosingClassName, enclosingClassName + .equals("AttributeTestClassEM02")); assertTrue(tfile.delete()); } - + @Override protected void tearDown() throws Exception { super.tearDown(); } diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java index 8c9fb5024..750dbf4f1 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java @@ -40,7 +40,7 @@ public class UtilTests extends TestCase { } public void testTypeUtilMethods1() { - String s = Type.getMethodSignature(Type.DOUBLE,new Type[]{Type.INT,Type.STRING,Type.SHORT}); + String s = Utility.toMethodSignature(Type.DOUBLE,new Type[]{Type.INT,Type.STRING,Type.SHORT}); System.err.println(s); } |