]> source.dussan.org Git - aspectj.git/commitdiff
test cases for TypeVariable implementation -- AMC
authoracolyer <acolyer>
Wed, 22 Jun 2005 15:12:33 +0000 (15:12 +0000)
committeracolyer <acolyer>
Wed, 22 Jun 2005 15:12:33 +0000 (15:12 +0000)
weaver/testsrc/BcweaverModuleTests.java
weaver/testsrc/org/aspectj/weaver/TypeVariableTestCase.java [new file with mode: 0644]

index de2eeceac6ec66400f8ba615aaa49929b738da7d..ae2a3cc5acbbb379cdb728f7b62b65ae19b9a3ae 100644 (file)
 // default package
 
 import org.aspectj.weaver.LocaleTest;
+import org.aspectj.weaver.TypeVariableTestCase;
 import org.aspectj.weaver.tools.ToolsTests;
 
 import junit.framework.*;
-import junit.framework.Test;
 
 public class BcweaverModuleTests extends TestCase {
 
@@ -26,6 +26,7 @@ public class BcweaverModuleTests extends TestCase {
         suite.addTest(org.aspectj.weaver.BcweaverTests.suite()); 
                suite.addTest(org.aspectj.weaver.patterns.PatternsTests.suite()); 
         suite.addTestSuite(LocaleTest.class);
+        suite.addTestSuite(TypeVariableTestCase.class);
         suite.addTest(ToolsTests.suite());
         return suite;
     }
diff --git a/weaver/testsrc/org/aspectj/weaver/TypeVariableTestCase.java b/weaver/testsrc/org/aspectj/weaver/TypeVariableTestCase.java
new file mode 100644 (file)
index 0000000..78419b6
--- /dev/null
@@ -0,0 +1,123 @@
+package org.aspectj.weaver;
+
+import org.aspectj.weaver.bcel.BcelWorld;
+
+import junit.framework.TestCase;
+
+public class TypeVariableTestCase extends TestCase {
+       
+       private TypeX javaLangNumber;
+       private TypeX javaLangDouble;
+       private TypeX javaUtilList;
+       private TypeX javaIoSerializable;
+       private World world;
+       
+       public void testDefaultBounds() {
+               TypeVariable tv = new TypeVariable("T");
+               assertEquals("Object",TypeX.OBJECT,tv.getUpperBound());
+               assertEquals("no additional bounds",0,tv.getAdditionalInterfaceBounds().length);
+               assertNull("no lower bound",tv.getLowerBound());
+       }
+       
+       public void testName() {
+               TypeVariable tv = new TypeVariable("T");
+               assertEquals("T",tv.getName());
+       }
+       
+       public void testUpperBound() {
+               TypeVariable tv = new TypeVariable("N",javaLangNumber);
+               assertEquals("java.lang.Number",javaLangNumber,tv.getUpperBound());
+       }
+       
+       public void testAdditionalUpperBounds() {
+               TypeVariable tv = new TypeVariable("E",TypeX.OBJECT,new TypeX[] {javaUtilList});
+               assertEquals("1 additional bound",1,tv.getAdditionalInterfaceBounds().length);
+               assertEquals("java.util.List",javaUtilList,tv.getAdditionalInterfaceBounds()[0]);
+       }
+       
+       public void testLowerBound() {
+               TypeVariable tv = new TypeVariable("X",TypeX.OBJECT,new TypeX[0],javaLangDouble);
+               assertEquals("java.lang.Double",javaLangDouble,tv.getLowerBound());
+       }
+       
+       public void testResolution() {
+               TypeVariable tv = new TypeVariable(
+                                       "T",
+                                       javaLangNumber,
+                                       new TypeX[] {javaUtilList},
+                                       javaLangDouble
+                               );
+               tv.resolve(world);
+               assertEquals("resolved number",javaLangNumber.resolve(world),tv.getUpperBound());
+               assertEquals("resolved list",javaUtilList.resolve(world),
+                                                                       tv.getAdditionalInterfaceBounds()[0]);
+               assertEquals("resolved double",javaLangDouble.resolve(world),tv.getLowerBound());
+       }
+       
+       public void testDoubleResolve() {
+               TypeVariable tv = new TypeVariable("X");
+               tv.resolve(world);
+               try {
+                       tv.resolve(world);
+                       fail("Should throw illegal state exception");
+               } catch (IllegalStateException ex) {}
+       }
+       
+       public void testBindWithoutResolve() {
+               TypeVariable tv = new TypeVariable("X");
+               try {
+                       tv.canBeBoundTo(null);
+                       fail ("Should throw illegal state exception");
+               } catch (IllegalStateException ex) {}
+       }
+       
+       public void testCanBindToUpperMatch() {
+               TypeVariable tv = new TypeVariable("X",javaLangNumber);
+               tv.resolve(world);
+               assertTrue(tv.canBeBoundTo(javaLangDouble.resolve(world)));
+       }
+       
+       public void testCanBindToUpperFail() {
+               TypeVariable tv = new TypeVariable("X",javaLangNumber);
+               tv.resolve(world);
+               assertFalse(tv.canBeBoundTo(TypeX.OBJECT.resolve(world)));              
+       }
+       
+       public void testCanBindToInterfaceMatch() {
+               TypeVariable tv = new TypeVariable("T",javaLangNumber,new TypeX[] {javaIoSerializable});
+               tv.resolve(world);
+               assertTrue(tv.canBeBoundTo(javaLangDouble.resolve(world)));
+       }
+       
+       public void testCanBindToInterfaceFail() {
+               TypeVariable tv = new TypeVariable("T",javaLangNumber,new TypeX[] {javaUtilList});
+               tv.resolve(world);
+               assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));    
+       }
+       
+       public void testCanBindToLowerMatch() {
+               TypeVariable tv = new TypeVariable("T",javaLangNumber,new TypeX[0],javaLangDouble);
+               tv.resolve(world);
+               assertTrue(tv.canBeBoundTo(javaLangNumber.resolve(world)));
+       }
+       
+       public void testCanBindToLowerFail() {
+               TypeVariable tv = new TypeVariable("T",javaLangNumber,new TypeX[0],javaLangNumber);
+               tv.resolve(world);
+               assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));            
+       }
+       
+       protected void setUp() throws Exception {
+               super.setUp();
+               javaLangNumber = TypeX.forSignature("Ljava/lang/Number;");
+               javaLangDouble = TypeX.forSignature("Ljava/lang/Double;");
+               javaIoSerializable = TypeX.forSignature("Ljava/io/Serializable;");
+               javaUtilList = TypeX.forSignature("Ljava/util/List;");
+               world = new BcelWorld();
+       }
+
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+
+}