- Revision
- 1284
- Author
- rfscholte
- Date
- 2011-08-03 15:44:12 -0500 (Wed, 03 Aug 2011)
Log Message
Add tests for AnnotationValueList
Modified Paths
Added Paths
Diff
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/AnnotationValueList.java (1283 => 1284)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/AnnotationValueList.java 2011-08-03 18:38:07 UTC (rev 1283) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/AnnotationValueList.java 2011-08-03 20:44:12 UTC (rev 1284) @@ -23,28 +23,34 @@ import java.util.List; import java.util.ListIterator; +public class AnnotationValueList + implements AnnotationValue +{ -public class AnnotationValueList implements AnnotationValue { - private final List<AnnotationValue> valueList; - public AnnotationValueList( List<AnnotationValue> valueList ) { + public AnnotationValueList( List<AnnotationValue> valueList ) + { this.valueList = valueList; } - public List<AnnotationValue> getValueList() { + public List<AnnotationValue> getValueList() + { return valueList; } - public String toString() { + public String toString() + { StringBuffer buf = new StringBuffer(); buf.append( "{" ); - for( ListIterator<AnnotationValue> i = valueList.listIterator(); i.hasNext(); ) { + for ( ListIterator<AnnotationValue> i = valueList.listIterator(); i.hasNext(); ) + { buf.append( i.next().toString() ); - - if(i.hasNext()) { + + if ( i.hasNext() ) + { buf.append( ", " ); } } @@ -54,15 +60,26 @@ return buf.toString(); } - public Object accept( AnnotationVisitor visitor ) { + /* + * (non-Javadoc) + * @see com.thoughtworks.qdox.model._expression_.AnnotationValue#accept(com.thoughtworks.qdox.model._expression_.AnnotationVisitor) + */ + public Object accept( AnnotationVisitor visitor ) + { return visitor.visit( this ); } - public List<Object> getParameterValue() { + /* + * (non-Javadoc) + * @see com.thoughtworks.qdox.model._expression_.AnnotationValue#getParameterValue() + */ + public List<Object> getParameterValue() + { List<Object> list = new LinkedList<Object>(); - for( ListIterator<AnnotationValue> i = valueList.listIterator(); i.hasNext(); ) { - list.add( i.next().getParameterValue() ); + for ( AnnotationValue value : valueList ) + { + list.add( value.getParameterValue() ); } return list;
Added: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/_expression_/AnnotationValueListTest.java (0 => 1284)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/_expression_/AnnotationValueListTest.java (rev 0) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/_expression_/AnnotationValueListTest.java 2011-08-03 20:44:12 UTC (rev 1284) @@ -0,0 +1,94 @@ +package com.thoughtworks.qdox.model._expression_; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import org.junit.Test; + + +public class AnnotationValueListTest +{ + + @Test + public void testParameterValue_emptyList() + { + AnnotationValueList expr = new AnnotationValueList ( Collections.<AnnotationValue>emptyList() ); + assertEquals( Collections.<Object>emptyList(), expr.getParameterValue() ); + } + + @Test + public void testToString_emptyList() + { + AnnotationValueList expr = new AnnotationValueList ( Collections.<AnnotationValue>emptyList() ); + assertEquals( "{}", expr.toString() ); + } + + @Test + public void testParameterValue_singletonList() + { + AnnotationValue value= mock( AnnotationValue.class ); + when( value.getParameterValue() ).thenReturn( "2" ); + AnnotationValueList expr = new AnnotationValueList ( Collections.singletonList( value ) ); + assertEquals( Collections.singletonList( "2" ), expr.getParameterValue() ); + } + + @Test + public void testToString_singletonList() + { + AnnotationValue value= mock( AnnotationValue.class ); + when( value.getParameterValue() ).thenReturn( "2" ); + AnnotationValueList expr = new AnnotationValueList ( Collections.singletonList( value ) ); + assertEquals( "{" + value+ "}", expr.toString() ); + } + + @Test + public void testParameterValue_twoElementsList() + { + AnnotationValue value1 = mock( AnnotationValue.class ); + when( value1.getParameterValue() ).thenReturn( "2" ); + AnnotationValue value2 = mock( AnnotationValue.class ); + when( value2.getParameterValue() ).thenReturn( "3" ); + List<AnnotationValue> actualList = new LinkedList<AnnotationValue>(); + actualList.add( value1 ); + actualList.add( value2 ); + AnnotationValueList expr = new AnnotationValueList( actualList ); + List<String> expectedParameterValue = new LinkedList<String>(); + expectedParameterValue.add( "2" ); + expectedParameterValue.add( "3" ); + assertEquals( expectedParameterValue, expr.getParameterValue() ); + } + + @Test + public void testToString_twoElementsList() + { + AnnotationValue value1 = mock( AnnotationValue.class ); + when( value1.getParameterValue() ).thenReturn( "2" ); + AnnotationValue value2 = mock( AnnotationValue.class ); + when( value2.getParameterValue() ).thenReturn( "3" ); + List<AnnotationValue> actualList = new LinkedList<AnnotationValue>(); + actualList.add( value1 ); + actualList.add( value2 ); + AnnotationValueList expr = new AnnotationValueList( actualList ); + List<String> expectedParameterValue = new LinkedList<String>(); + expectedParameterValue.add( "2" ); + expectedParameterValue.add( "3" ); + assertEquals( "{" + value1+ ", " + value2 + "}", expr.toString() ); + } + + @Test + public void testAccept() + { + AnnotationVisitor visitor = mock( AnnotationVisitor.class ); + AnnotationValueList expr = new AnnotationValueList ( null ); + Object visitResult = new Object(); + when( visitor.visit( expr ) ).thenReturn( visitResult ); + assertSame( expr.accept( visitor ), visitResult ); + } + +}
To unsubscribe from this list please visit:
