- Revision
- 1422
- Author
- rfscholte
- Date
- 2011-10-17 13:59:19 -0500 (Mon, 17 Oct 2011)
Log Message
Rename TypeTest to JavaTypeTest
Modified Paths
Added Paths
Removed Paths
Diff
Modified: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultTypeTest.java (1421 => 1422)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultTypeTest.java 2011-10-17 18:34:36 UTC (rev 1421) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultTypeTest.java 2011-10-17 18:59:19 UTC (rev 1422) @@ -1,10 +1,11 @@ package com.thoughtworks.qdox.model; import com.thoughtworks.qdox.library.ClassLibrary; +import com.thoughtworks.qdox.library.ClassLoaderLibrary; import com.thoughtworks.qdox.model.impl.DefaultJavaSource; -public class DefaultTypeTest extends TypeTest +public class DefaultTypeTest extends JavaTypeTest<Type> { public DefaultTypeTest( String s ) @@ -31,10 +32,25 @@ { return new Type(fullname, dimensions, source); } + + public void testArrayType() throws Exception { + Type type = newType("int", 1); + assertTrue(type.isArray()); + } - public void addImport( JavaSource source, String imp ) - { - ((DefaultJavaSource) source).addImport( imp ); + public void testComponentType() throws Exception { + assertNull( newType("int").getComponentType()); + assertEquals("int", newType("int", 1).getComponentType().getFullyQualifiedName()); + assertEquals("long", newType("long", 3).getComponentType().getFullyQualifiedName()); } -} + public void testTypeHasJavaClass() { + ClassLoaderLibrary library = new ClassLoaderLibrary( null ); + library.addDefaultLoader(); + JavaSource javaSource = newJavaSource(library); + JavaClass clazz = newType("java.util.HashSet", 0, javaSource); + JavaClass superClass = clazz.getSuperJavaClass(); + assertEquals("java.util.AbstractSet", superClass.getFullyQualifiedName()); + } + +} \ No newline at end of file
Copied: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/JavaTypeTest.java (from rev 1303, trunk/qdox/src/test/java/com/thoughtworks/qdox/model/TypeTest.java) (0 => 1422)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/JavaTypeTest.java (rev 0) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/JavaTypeTest.java 2011-10-17 18:59:19 UTC (rev 1422) @@ -0,0 +1,92 @@ +package com.thoughtworks.qdox.model; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collections; + +import junit.framework.TestCase; + +public abstract class JavaTypeTest<T extends JavaType> extends TestCase { + + public JavaTypeTest(String s) { + super(s); + } + + public abstract T newType(String fullname); + public abstract T newType(String fullname, int dimensions); + public abstract T newType(String fullname, int dimensions, JavaSource source); + + public void testResolving() throws Exception { + JavaSource src = "" + when(src.getImports()).thenReturn( Collections.singletonList( "foo.*" ) ); + Type type = Type.createUnresolved("Bar", 0, src); + assertEquals(false, type.isResolved()); + + when(src.resolveType( "Bar" )).thenReturn( "foo.Bar" ); + assertEquals(true, type.isResolved()); + assertEquals("Bar", type.getValue()); + assertEquals("foo.Bar", type.getFullyQualifiedName()); + } + + public void testToString() throws Exception { + assertEquals("int", newType("int").toString()); + assertEquals("int[]", newType("int", 1).toString()); + assertEquals("long[][][]", newType("long", 3).toString()); + } + + public void testFullyQualifiedName() throws Exception { + assertEquals("int", newType("int").getFullyQualifiedName()); + assertEquals("int[]", newType("int", 1).getFullyQualifiedName()); + assertEquals("long[][][]", newType("long", 3).getFullyQualifiedName()); + } + + public void testEquals() throws Exception { + assertEquals(newType("string"), + newType("string")); + assertNotEquals(newType("string"), + newType("int")); + assertNotEquals(newType("long", 1), + newType("long")); + assertNotEquals(newType("long"), + newType("long", 2)); + assertFalse(newType("int").equals(null)); + } + + public void testToStringVoid() { + assertEquals("void", Type.VOID.toString()); + } + + public void testToStringBoolean() { + assertEquals("boolean", newType("boolean").toString()); + } + + public void testToStringInt() { + assertEquals("int", newType("int").toString()); + } + + public void testToStringLong() { + assertEquals("long", newType("long").toString()); + } + + public void testToStringFloat() { + assertEquals("float", newType("float").toString()); + } + + public void testToStringDouble() { + assertEquals("double", newType("double").toString()); + } + + public void testToStringChar() { + assertEquals("char", newType("char").toString()); + } + + public void testToStringByte() { + assertEquals("byte", newType("byte").toString()); + } + + private void assertNotEquals(Object o1, Object o2) { + assertTrue(o2.toString() + " should not equal " + o1.toString(), + !o2.equals(o1)); + } +}
Deleted: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/TypeTest.java (1421 => 1422)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/TypeTest.java 2011-10-17 18:34:36 UTC (rev 1421) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/TypeTest.java 2011-10-17 18:59:19 UTC (rev 1422) @@ -1,116 +0,0 @@ -package com.thoughtworks.qdox.model; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Collections; - -import junit.framework.TestCase; - -import com.thoughtworks.qdox.library.ClassLibrary; -import com.thoughtworks.qdox.library.ClassLoaderLibrary; - -public abstract class TypeTest extends TestCase { - - public TypeTest(String s) { - super(s); - } - - public abstract JavaSource newJavaSource( ClassLibrary library ); - public abstract Type newType(String fullname); - public abstract Type newType(String fullname, int dimensions); - public abstract Type newType(String fullname, int dimensions, JavaSource source); - - public void testResolving() throws Exception { - JavaSource src = "" - when(src.getImports()).thenReturn( Collections.singletonList( "foo.*" ) ); - Type type = Type.createUnresolved("Bar", 0, src); - assertEquals(false, type.isResolved()); - - when(src.resolveType( "Bar" )).thenReturn( "foo.Bar" ); - assertEquals(true, type.isResolved()); - assertEquals("Bar", type.getValue()); - assertEquals("foo.Bar", type.getFullyQualifiedName()); - } - - public void testArrayType() throws Exception { - Type type = newType("int", 1); - assertTrue(type.isArray()); - } - - public void testToString() throws Exception { - assertEquals("int", newType("int").toString()); - assertEquals("int[]", newType("int", 1).toString()); - assertEquals("long[][][]", newType("long", 3).toString()); - } - - public void testFullyQualifiedName() throws Exception { - assertEquals("int", newType("int").getFullyQualifiedName()); - assertEquals("int[]", newType("int", 1).getFullyQualifiedName()); - assertEquals("long[][][]", newType("long", 3).getFullyQualifiedName()); - } - - public void testComponentType() throws Exception { - assertNull( newType("int").getComponentType()); - assertEquals("int", newType("int", 1).getComponentType().getFullyQualifiedName()); - assertEquals("long", newType("long", 3).getComponentType().getFullyQualifiedName()); - } - - public void testEquals() throws Exception { - assertEquals(newType("string"), - newType("string")); - assertNotEquals(newType("string"), - newType("int")); - assertNotEquals(newType("long", 1), - newType("long")); - assertNotEquals(newType("long"), - newType("long", 2)); - assertFalse(newType("int").equals(null)); - } - - public void testTypeHasJavaClass() { - ClassLoaderLibrary library = new ClassLoaderLibrary( null ); - library.addDefaultLoader(); - JavaSource javaSource = newJavaSource(library); - JavaClass clazz = newType("java.util.HashSet", 0, javaSource); - JavaClass superClass = clazz.getSuperJavaClass(); - assertEquals("java.util.AbstractSet", superClass.getFullyQualifiedName()); - } - - public void testToStringVoid() { - assertEquals("void", Type.VOID.toString()); - } - - public void testToStringBoolean() { - assertEquals("boolean", newType("boolean").toString()); - } - - public void testToStringInt() { - assertEquals("int", newType("int").toString()); - } - - public void testToStringLong() { - assertEquals("long", newType("long").toString()); - } - - public void testToStringFloat() { - assertEquals("float", newType("float").toString()); - } - - public void testToStringDouble() { - assertEquals("double", newType("double").toString()); - } - - public void testToStringChar() { - assertEquals("char", newType("char").toString()); - } - - public void testToStringByte() { - assertEquals("byte", newType("byte").toString()); - } - - private void assertNotEquals(Object o1, Object o2) { - assertTrue(o2.toString() + " should not equal " + o1.toString(), - !o2.equals(o1)); - } -}
To unsubscribe from this list please visit:
