aboutsummaryrefslogtreecommitdiffstats
path: root/weaver/testsrc
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-06-22 15:12:33 +0000
committeracolyer <acolyer>2005-06-22 15:12:33 +0000
commit5e65c6f7defe02f80aa8d30c416eb42e8abb7714 (patch)
tree5ab698bab3468b4c1c89ac90bb8ce180e26d4ee5 /weaver/testsrc
parentd43de06ddbca60615a577533e159a3cba24fcfa9 (diff)
downloadaspectj-5e65c6f7defe02f80aa8d30c416eb42e8abb7714.tar.gz
aspectj-5e65c6f7defe02f80aa8d30c416eb42e8abb7714.zip
test cases for TypeVariable implementation -- AMC
Diffstat (limited to 'weaver/testsrc')
-rw-r--r--weaver/testsrc/BcweaverModuleTests.java3
-rw-r--r--weaver/testsrc/org/aspectj/weaver/TypeVariableTestCase.java123
2 files changed, 125 insertions, 1 deletions
diff --git a/weaver/testsrc/BcweaverModuleTests.java b/weaver/testsrc/BcweaverModuleTests.java
index de2eeceac..ae2a3cc5a 100644
--- a/weaver/testsrc/BcweaverModuleTests.java
+++ b/weaver/testsrc/BcweaverModuleTests.java
@@ -13,10 +13,10 @@
// 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
index 000000000..78419b660
--- /dev/null
+++ b/weaver/testsrc/org/aspectj/weaver/TypeVariableTestCase.java
@@ -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();
+ }
+
+}