- Revision
- 1419
- Author
- rfscholte
- Date
- 2011-10-16 15:29:52 -0500 (Sun, 16 Oct 2011)
Log Message
Remove Type references from EvaluatingVisitorTest
Modified Paths
- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/EvaluatingVisitor.java
- trunk/qdox/src/test/java/com/thoughtworks/qdox/builder/EvaluatingVisitorTest.java
Diff
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/EvaluatingVisitor.java (1418 => 1419)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/EvaluatingVisitor.java 2011-10-15 20:39:36 UTC (rev 1418) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/EvaluatingVisitor.java 2011-10-16 20:29:52 UTC (rev 1419) @@ -897,7 +897,7 @@ if ( type instanceof JavaClass && ( (JavaClass) type ).isPrimitive() && value instanceof Number ) { Number n = (Number) value; - String typeName = type.getCanonicalName(); + String typeName = type.getFullyQualifiedName(); if ( typeName.equals( "byte" ) ) {
Modified: trunk/qdox/src/test/java/com/thoughtworks/qdox/builder/EvaluatingVisitorTest.java (1418 => 1419)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/builder/EvaluatingVisitorTest.java 2011-10-15 20:39:36 UTC (rev 1418) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/builder/EvaluatingVisitorTest.java 2011-10-16 20:29:52 UTC (rev 1419) @@ -13,9 +13,10 @@ import org.junit.Ignore; import org.junit.Test; +import com.thoughtworks.qdox.model.JavaAnnotation; +import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaType; -import com.thoughtworks.qdox.model.Type; import com.thoughtworks.qdox.model._expression_.Add; import com.thoughtworks.qdox.model._expression_.And; import com.thoughtworks.qdox.model._expression_.AnnotationValue; @@ -305,7 +306,8 @@ public void testVisitAnnotation() { try{ - visitor.visit( new DefaultJavaAnnotation( new Type("Ignore"), -1 ) ); + JavaAnnotation annotation = mock(JavaAnnotation.class); + visitor.visit( annotation ); fail( "Visiting an annotation is not supported and should throw an UnsupportedOperationException" ); } catch (UnsupportedOperationException e) { @@ -331,35 +333,50 @@ } @Test - public void testVisitCast() + public void testVisitCast() throws Exception { AnnotationValue value = mock( AnnotationValue.class ); when( value.accept( visitor ) ).thenReturn( 7 ); - assertEquals( (byte) 7, visitor.visit( new Cast( new Type( "byte" ), value ) ) ); - assertEquals( (char) 7, visitor.visit( new Cast( new Type( "char" ), value ) ) ); - assertEquals( (short) 7, visitor.visit( new Cast( new Type( "short" ), value ) ) ); - assertEquals( (int) 7, visitor.visit( new Cast( new Type( "int" ), value ) ) ); - assertEquals( (long) 7, visitor.visit( new Cast( new Type( "long" ), value ) ) ); - assertEquals( (float) 7, visitor.visit( new Cast( new Type( "float" ), value ) ) ); - assertEquals( (double) 7, visitor.visit( new Cast( new Type( "double" ), value ) ) ); + JavaClass primitiveClass = mock( JavaClass.class ); + when( primitiveClass.isPrimitive() ).thenReturn( true ); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "byte" ); + assertEquals( (byte) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "char" ); + assertEquals( (char) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "short" ); + assertEquals( (short) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "int" ); + assertEquals( (int) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "long" ); + assertEquals( (long) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "float" ); + assertEquals( (float) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "double" ); + assertEquals( (double) 7, visitor.visit( new Cast( primitiveClass, value ) ) ); + try { - visitor.visit( new Cast( new Type( "void" ), value ) ); - fail("Although 'void' is a primitive, you can't cast to it"); + when( primitiveClass.getFullyQualifiedName() ).thenReturn( "void" ); + visitor.visit( new Cast( primitiveClass, value ) ); + + fail( "Although 'void' is a primitive, you can't cast to it" ); } - catch( IllegalArgumentException iae) - { + catch ( IllegalArgumentException iae ) + { } - + + JavaClass stringClass = mock( JavaClass.class ); + when( stringClass.getFullyQualifiedName() ).thenReturn( "java.lang.String" ); when( value.accept( visitor ) ).thenReturn( "hello world" ); - assertEquals( (String) "hello world", visitor.visit( new Cast( new Type( "java.lang.String" ), value ) ) ); + assertEquals( (String) "hello world", visitor.visit( new Cast( stringClass, value ) ) ); + JavaClass listClass = mock( JavaClass.class ); + when( listClass.getFullyQualifiedName() ).thenReturn( "java.util.List" ); Object list = Collections.EMPTY_LIST; when( value.accept( visitor ) ).thenReturn( list ); - assertEquals( (List<?>) list, visitor.visit( new Cast( new Type( "java.util.List" ), value ) ) ); - + assertEquals( (List<?>) list, visitor.visit( new Cast( listClass, value ) ) ); } @Test
To unsubscribe from this list please visit:
