Title: [1423] trunk/qdox/src/test/java/com/thoughtworks/qdox/model: Refactor tests to use assertThat() instead of assertNotEquals()
Revision
1423
Author
rfscholte
Date
2011-10-17 15:25:36 -0500 (Mon, 17 Oct 2011)

Log Message

Refactor tests to use assertThat() instead of assertNotEquals()

Modified Paths


Diff

Modified: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultTypeTest.java (1422 => 1423)

--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultTypeTest.java	2011-10-17 18:59:19 UTC (rev 1422)
+++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultTypeTest.java	2011-10-17 20:25:36 UTC (rev 1423)
@@ -1,5 +1,15 @@
 package com.thoughtworks.qdox.model;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+
+import org.junit.Test;
+
 import com.thoughtworks.qdox.library.ClassLibrary;
 import com.thoughtworks.qdox.library.ClassLoaderLibrary;
 import com.thoughtworks.qdox.model.impl.DefaultJavaSource;
@@ -8,11 +18,6 @@
 public class DefaultTypeTest extends JavaTypeTest<Type>
 {
 
-    public DefaultTypeTest( String s )
-    {
-        super( s );
-    }
-
     public JavaSource newJavaSource( ClassLibrary library )
     {
         return new DefaultJavaSource(library);
@@ -33,18 +38,21 @@
         return new Type(fullname, dimensions, source);
     }
     
+    @Test
     public void testArrayType() throws Exception {
         Type type = newType("int", 1);
         assertTrue(type.isArray());
     }
 
+    @Test
     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() {
+   @Test
+   public void testTypeHasJavaClass() {
         ClassLoaderLibrary library = new ClassLoaderLibrary( null );
         library.addDefaultLoader();
         JavaSource javaSource = newJavaSource(library);
@@ -52,5 +60,18 @@
         JavaClass superClass = clazz.getSuperJavaClass();
         assertEquals("java.util.AbstractSet", superClass.getFullyQualifiedName());
     }
+    
+    @Test
+    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());
+    }
 
 }
\ No newline at end of file

Modified: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/JavaTypeTest.java (1422 => 1423)

--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/JavaTypeTest.java	2011-10-17 18:59:19 UTC (rev 1422)
+++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/JavaTypeTest.java	2011-10-17 20:25:36 UTC (rev 1423)
@@ -1,92 +1,91 @@
 package com.thoughtworks.qdox.model;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+import static org.hamcrest.core.IsNot.*;
+import org.junit.Test;
 
-import java.util.Collections;
+public abstract class JavaTypeTest<T extends JavaType>
+{
 
-import junit.framework.TestCase;
+    public abstract T newType( String fullname );
 
-public abstract class JavaTypeTest<T extends JavaType> extends TestCase {
+    public abstract T newType( String fullname, int dimensions );
 
-    public JavaTypeTest(String s) {
-        super(s);
+    @Test
+    public void testToString()
+        throws Exception
+    {
+        assertEquals( "int", newType( "int" ).toString() );
+        assertEquals( "int[]", newType( "int", 1 ).toString() );
+        assertEquals( "long[][][]", newType( "long", 3 ).toString() );
     }
-    
-    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());
+
+    @Test
+    public void testFullyQualifiedName()
+        throws Exception
+    {
+        assertEquals( "int", newType( "int" ).getFullyQualifiedName() );
+        assertEquals( "int[]", newType( "int", 1 ).getFullyQualifiedName() );
+        assertEquals( "long[][][]", newType( "long", 3 ).getFullyQualifiedName() );
     }
 
-    public void testToString() throws Exception {
-        assertEquals("int", newType("int").toString());
-        assertEquals("int[]", newType("int", 1).toString());
-        assertEquals("long[][][]", newType("long", 3).toString());
+    @Test
+    public void testEquals()
+        throws Exception
+    {
+        assertEquals( newType( "string" ), newType( "string" ) );
+        assertThat( newType( "string" ), not( newType( "int" ) ) );
+        assertThat( newType( "long", 1 ), not( newType( "long" ) ) );
+        assertThat( newType( "long" ), not( newType( "long", 2 ) ) );
+        assertFalse( newType( "int" ).equals( null ) );
     }
-    
-    public void testFullyQualifiedName() throws Exception {
-        assertEquals("int", newType("int").getFullyQualifiedName());
-        assertEquals("int[]", newType("int", 1).getFullyQualifiedName());
-        assertEquals("long[][][]", newType("long", 3).getFullyQualifiedName());
+
+    @Test
+    public void testToStringVoid()
+    {
+        assertEquals( "void", Type.VOID.toString() );
     }
 
-    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));
+    @Test
+    public void testToStringBoolean()
+    {
+        assertEquals( "boolean", newType( "boolean" ).toString() );
     }
 
-    public void testToStringVoid() {
-        assertEquals("void", Type.VOID.toString());
+    @Test
+    public void testToStringInt()
+    {
+        assertEquals( "int", newType( "int" ).toString() );
     }
 
-    public void testToStringBoolean() {
-        assertEquals("boolean", newType("boolean").toString());
+    @Test
+    public void testToStringLong()
+    {
+        assertEquals( "long", newType( "long" ).toString() );
     }
-    
-    public void testToStringInt() {
-        assertEquals("int", newType("int").toString());
-    }
 
-    public void testToStringLong() {
-        assertEquals("long", newType("long").toString());
+    @Test
+    public void testToStringFloat()
+    {
+        assertEquals( "float", newType( "float" ).toString() );
     }
 
-    public void testToStringFloat() {
-        assertEquals("float", newType("float").toString());
+    @Test
+    public void testToStringDouble()
+    {
+        assertEquals( "double", newType( "double" ).toString() );
     }
 
-    public void testToStringDouble() {
-        assertEquals("double", newType("double").toString());
+    @Test
+    public void testToStringChar()
+    {
+        assertEquals( "char", newType( "char" ).toString() );
     }
-    
-    public void testToStringChar() {
-        assertEquals("char", newType("char").toString());
-    }
 
-    public void testToStringByte() {
-        assertEquals("byte", newType("byte").toString());
+    @Test
+    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));
-    }
-}
+
+}
\ No newline at end of file


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to