* ******************************************************************/
package org.aspectj.weaver;
-import org.aspectj.weaver.bcel.BcelWorld;
-
import junit.framework.TestCase;
+import org.aspectj.weaver.bcel.BcelWorld;
+
public class BoundedReferenceTypeTestCase extends TestCase {
ReferenceType javaLangClass;
BoundedReferenceType extendsClass;
BoundedReferenceType superClass;
BoundedReferenceType extendsWithExtras;
-
+
public void testSignature() {
String extendsSig = extendsClass.getSignature();
- assertEquals("+Ljava/lang/Class;",extendsSig);
- assertEquals("-Ljava/lang/Class;",superClass.getSignature());
+ assertEquals("+Ljava/lang/Class;", extendsSig);
+ assertEquals("-Ljava/lang/Class;", superClass.getSignature());
}
-
+
public void testExtendsBounds() {
- assertFalse("has no lower bound",extendsClass.hasLowerBound());
- assertNull("no lower bound",extendsClass.getLowerBound());
- assertEquals(javaLangClass,extendsClass.getUpperBound());
- assertEquals("no interface bounds",0,extendsClass.getInterfaceBounds().length);
+ assertFalse("has no lower bound", extendsClass.hasLowerBound());
+ assertNull("no lower bound", extendsClass.getLowerBound());
+ assertEquals(javaLangClass, extendsClass.getUpperBound());
+ assertEquals("no interface bounds", 0, extendsClass.getAdditionalBounds().length);
}
-
+
public void testSuperBounds() {
- assertTrue("has lower bound",superClass.hasLowerBound());
- assertEquals(javaLangClass,superClass.getLowerBound());
- assertEquals("Ljava/lang/Object;",superClass.getUpperBound().getSignature());
- assertEquals("no interface bounds",0,superClass.getInterfaceBounds().length);
+ assertTrue("has lower bound", superClass.hasLowerBound());
+ assertEquals(javaLangClass, superClass.getLowerBound());
+ assertEquals("Ljava/lang/Object;", superClass.getUpperBound().getSignature());
+ assertEquals("no interface bounds", 0, superClass.getAdditionalBounds().length);
}
-
+
public void testIsExtends() {
- assertTrue(extendsClass.isExtends);
- assertFalse(superClass.isExtends);
+ assertTrue(extendsClass.kind == BoundedReferenceType.EXTENDS);
+ assertFalse(superClass.kind == BoundedReferenceType.EXTENDS);
}
-
+
public void testIsSuper() {
- assertTrue(superClass.isSuper);
- assertFalse(extendsClass.isSuper);
+ assertTrue(superClass.kind == BoundedReferenceType.SUPER);
+ assertFalse(extendsClass.kind == BoundedReferenceType.SUPER);
}
-
+
public void testGetDeclaredInterfacesNoAdditions() {
ResolvedType[] rt1 = extendsClass.getDeclaredInterfaces();
ResolvedType[] rt2 = javaLangClass.getDeclaredInterfaces();
- assertEquals("same length",rt1.length,rt2.length);
+ assertEquals("same length", rt1.length, rt2.length);
for (int i = 0; i < rt2.length; i++) {
- assertEquals("same methods",rt1[i],rt2[i]);
+ assertEquals("same methods", rt1[i], rt2[i]);
}
}
-
+
public void testGetDeclaredInterfacesWithInterfaceBounds() {
ResolvedType[] rt1 = extendsWithExtras.getDeclaredInterfaces();
ResolvedType[] rt2 = javaLangClass.getDeclaredInterfaces();
- assertEquals("one extra interface",rt1.length,rt2.length + 1);
+ assertEquals("one extra interface", rt1.length, rt2.length + 1);
for (int i = 0; i < rt2.length; i++) {
- assertEquals("same methods",rt1[i],rt2[i]);
+ assertEquals("same methods", rt1[i], rt2[i]);
}
- assertEquals("Ljava/util/List;",rt1[rt1.length-1].getSignature());
+ assertEquals("Ljava/util/List;", rt1[rt1.length - 1].getSignature());
}
-
- // all other methods in signature are delegated to upper bound...
+
+ // all other methods in signature are delegated to upper bound...
// representative test
public void testGetDeclaredMethodsExtends() {
ResolvedMember[] rm1 = extendsClass.getDeclaredMethods();
ResolvedMember[] rm2 = javaLangClass.getDeclaredMethods();
- assertEquals("same length",rm1.length,rm2.length);
+ assertEquals("same length", rm1.length, rm2.length);
for (int i = 0; i < rm2.length; i++) {
- assertEquals("same methods",rm1[i],rm2[i]);
+ assertEquals("same methods", rm1[i], rm2[i]);
}
}
public void testGetDeclaredMethodsSuper() {
ResolvedMember[] rm1 = superClass.getDeclaredMethods();
ResolvedMember[] rm2 = javaLangObject.getDeclaredMethods();
- assertEquals("same length",rm1.length,rm2.length);
+ assertEquals("same length", rm1.length, rm2.length);
for (int i = 0; i < rm2.length; i++) {
- assertEquals("same methods",rm1[i],rm2[i]);
+ assertEquals("same methods", rm1[i], rm2[i]);
}
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
BcelWorld world = new BcelWorld();
javaLangClass = (ReferenceType) world.resolve(UnresolvedType.forName("java/lang/Class"));
javaLangObject = (ReferenceType) world.resolve(UnresolvedType.OBJECT);
- extendsClass = new BoundedReferenceType(javaLangClass,true,world);
- superClass = new BoundedReferenceType(javaLangClass,false,world);
- extendsWithExtras = new BoundedReferenceType(javaLangClass,true,world,
- new ReferenceType[] {(ReferenceType)world.resolve(UnresolvedType.forName("java/util/List"))});
+ extendsClass = new BoundedReferenceType(javaLangClass, true, world);
+ superClass = new BoundedReferenceType(javaLangClass, false, world);
+ extendsWithExtras = new BoundedReferenceType(javaLangClass, true, world, new ReferenceType[] { (ReferenceType) world
+ .resolve(UnresolvedType.forName("java/util/List")) });
}
}
* ******************************************************************/
package org.aspectj.weaver;
-import org.aspectj.weaver.bcel.BcelWorld;
-
import junit.framework.TestCase;
+import org.aspectj.weaver.bcel.BcelWorld;
+
/**
* @author colyer
- *
+ *
*/
public class TypeVariableReferenceTypeTestCase extends TestCase {
BoundedReferenceType superClass;
BoundedReferenceType extendsWithExtras;
BcelWorld world;
-
+
public void testConstructionByNameAndVariable() {
- TypeVariable tv = new TypeVariable("T",javaLangClass);
- TypeVariableReferenceType tvrt = new TypeVariableReferenceType(tv,world);
- assertEquals("T",tvrt.getTypeVariable().getName());
- assertEquals(javaLangClass,tvrt.getUpperBound());
+ TypeVariable tv = new TypeVariable("T", javaLangClass);
+ TypeVariableReferenceType tvrt = new TypeVariableReferenceType(tv, world);
+ assertEquals("T", tvrt.getTypeVariable().getName());
+ assertEquals(javaLangClass, tvrt.getTypeVariable().getUpperBound());
}
-
+
+ @Override
protected void setUp() throws Exception {
super.setUp();
world = new BcelWorld();
javaLangClass = (ReferenceType) world.resolve(UnresolvedType.forName("java/lang/Class"));
javaLangObject = (ReferenceType) world.resolve(UnresolvedType.OBJECT);
- extendsClass = new BoundedReferenceType(javaLangClass,true,world);
- superClass = new BoundedReferenceType(javaLangClass,false,world);
- extendsWithExtras = new BoundedReferenceType(javaLangClass,true,world,
- new ReferenceType[] {(ReferenceType)world.resolve(UnresolvedType.forName("java/util/List"))});
+ extendsClass = new BoundedReferenceType(javaLangClass, true, world);
+ superClass = new BoundedReferenceType(javaLangClass, false, world);
+ extendsWithExtras = new BoundedReferenceType(javaLangClass, true, world, new ReferenceType[] { (ReferenceType) world
+ .resolve(UnresolvedType.forName("java/util/List")) });
}
}
* ******************************************************************/
package org.aspectj.weaver;
-import org.aspectj.weaver.bcel.BcelWorld;
-
import junit.framework.TestCase;
+import org.aspectj.weaver.bcel.BcelWorld;
+
public class TypeVariableTestCase extends TestCase {
-
+
private UnresolvedType javaLangNumber;
private UnresolvedType javaLangDouble;
private UnresolvedType javaUtilList;
private UnresolvedType javaIoSerializable;
private World world;
-
+
public void testDefaultBounds() {
- TypeVariable tv = new TypeVariable("T");
- assertEquals("Object",UnresolvedType.OBJECT,tv.getUpperBound());
- assertEquals("no additional bounds",0,tv.getAdditionalInterfaceBounds().length);
- assertNull("no lower bound",tv.getLowerBound());
+ TypeVariable typevariable = new TypeVariable("T");
+ assertNull(typevariable.getUpperBound());
+ assertEquals("Object", UnresolvedType.OBJECT, typevariable.getFirstBound());
+ assertEquals("no additional bounds", 0, typevariable.getSuperInterfaces().length);
}
-
+
public void testName() {
TypeVariable tv = new TypeVariable("T");
- assertEquals("T",tv.getName());
+ assertEquals("T", tv.getName());
}
-
+
public void testUpperBound() {
- TypeVariable tv = new TypeVariable("N",javaLangNumber);
- assertEquals("java.lang.Number",javaLangNumber,tv.getUpperBound());
+ TypeVariable tv = new TypeVariable("N", javaLangNumber);
+ assertEquals("java.lang.Number", javaLangNumber, tv.getUpperBound());
}
-
+
public void testAdditionalUpperBounds() {
- TypeVariable tv = new TypeVariable("E",UnresolvedType.OBJECT,new UnresolvedType[] {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",UnresolvedType.OBJECT,new UnresolvedType[0],javaLangDouble);
- assertEquals("java.lang.Double",javaLangDouble,tv.getLowerBound());
+ TypeVariable tv = new TypeVariable("E", UnresolvedType.OBJECT, new UnresolvedType[] { javaUtilList });
+ assertEquals("1 additional bound", 1, tv.getSuperInterfaces().length);
+ assertEquals("java.util.List", javaUtilList, tv.getSuperInterfaces()[0]);
}
-
+
public void testResolution() {
- TypeVariable tv = new TypeVariable(
- "T",
- javaLangNumber,
- new UnresolvedType[] {javaUtilList},
- javaLangDouble
- );
+ TypeVariable tv = new TypeVariable("T", javaLangNumber, new UnresolvedType[] { javaUtilList });
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());
+ assertEquals("resolved number", javaLangNumber.resolve(world), tv.getUpperBound());
+ assertEquals("resolved list", javaUtilList.resolve(world), tv.getSuperInterfaces()[0]);
}
-
+
public void testBindWithoutResolve() {
TypeVariable tv = new TypeVariable("X");
try {
tv.canBeBoundTo(null);
- fail ("Should throw illegal state exception");
- } catch (IllegalStateException ex) {}
+ fail("Should throw illegal state exception");
+ } catch (IllegalStateException ex) {
+ }
}
-
+
public void testCanBindToUpperMatch() {
- TypeVariable tv = new TypeVariable("X",javaLangNumber);
+ TypeVariable tv = new TypeVariable("X", javaLangNumber);
tv.resolve(world);
assertTrue(tv.canBeBoundTo(javaLangDouble.resolve(world)));
}
-
+
public void testCanBindToUpperFail() {
- TypeVariable tv = new TypeVariable("X",javaLangNumber);
+ TypeVariable tv = new TypeVariable("X", javaLangNumber);
tv.resolve(world);
- assertFalse(tv.canBeBoundTo(UnresolvedType.OBJECT.resolve(world)));
+ assertFalse(tv.canBeBoundTo(UnresolvedType.OBJECT.resolve(world)));
}
-
+
public void testCanBindToInterfaceMatch() {
- TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[] {javaIoSerializable});
+ TypeVariable tv = new TypeVariable("T", javaLangNumber, new UnresolvedType[] { javaIoSerializable });
tv.resolve(world);
assertTrue(tv.canBeBoundTo(javaLangDouble.resolve(world)));
}
-
+
public void testCanBindToInterfaceFail() {
- TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[] {javaUtilList});
+ TypeVariable tv = new TypeVariable("T", javaLangNumber, new UnresolvedType[] { javaUtilList });
tv.resolve(world);
- assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));
+ assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));
}
-
- public void testCanBindToLowerMatch() {
- TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[0],javaLangDouble);
- tv.resolve(world);
- assertTrue(tv.canBeBoundTo(javaLangNumber.resolve(world)));
- }
-
- public void testCanBindToLowerFail() {
- TypeVariable tv = new TypeVariable("T",javaLangNumber,new UnresolvedType[0],javaLangNumber);
- tv.resolve(world);
- assertFalse(tv.canBeBoundTo(javaLangDouble.resolve(world)));
- }
-
+
+ @Override
protected void setUp() throws Exception {
super.setUp();
javaLangNumber = UnresolvedType.forSignature("Ljava/lang/Number;");
world = new BcelWorld();
}
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
}