- Revision
- 1389
- Author
- rfscholte
- Date
- 2011-10-09 05:30:53 -0500 (Sun, 09 Oct 2011)
Log Message
Move AbstractJavaEntity to separate package
Modified Paths
- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractInheritableJavaEntity.java
- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java
Added Paths
- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntity.java
- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntityTest.java
Removed Paths
Diff
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractInheritableJavaEntity.java (1388 => 1389)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractInheritableJavaEntity.java 2011-10-09 10:27:28 UTC (rev 1388) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractInheritableJavaEntity.java 2011-10-09 10:30:53 UTC (rev 1389) @@ -21,6 +21,8 @@ import java.util.List; +import com.thoughtworks.qdox.model.impl.AbstractJavaEntity; + /** * @author Aslak Hellesøy * @version $Revision$
Deleted: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractJavaEntity.java (1388 => 1389)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractJavaEntity.java 2011-10-09 10:27:28 UTC (rev 1388) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractJavaEntity.java 2011-10-09 10:30:53 UTC (rev 1389) @@ -1,173 +0,0 @@ -package com.thoughtworks.qdox.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.Collections; -import java.util.List; - -public abstract class AbstractJavaEntity extends AbstractBaseJavaEntity implements JavaModel { - - private List<String> modifiers = Collections.emptyList(); - private JavaClass parentCls; - private String name; - - /** - * Return list of modifiers as Strings. - * (public, private, protected, final, abstract, static) - * @return a list of modifiers, never <code>null</code> - */ - public List<String> getModifiers() { - return modifiers; - } - - public void setModifiers(List<String> modifiers) { - this.modifiers = modifiers; - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isAbstract(int)} - * - * @return <code>true</code> if entity is abstract, otherwise <code>false</code> - */ - public boolean isAbstract() { - return isModifierPresent("abstract"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isPublic(int)} - * - * @return <code>true</code> if entity is public, otherwise <code>false</code> - */ - public boolean isPublic() { - return isModifierPresent("public"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isPrivate(int)} - * - * @return <code>true</code> if entity is private, otherwise <code>false</code> - */ - public boolean isPrivate() { - return isModifierPresent("private"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isProtected(int)} - * - * @return <code>true</code> if entity is protected, otherwise <code>false</code> - */ - public boolean isProtected() { - return isModifierPresent("protected"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isStatic(int)} - * - * @return <code>true</code> if entity is static, otherwise <code>false</code> - */ - public boolean isStatic() { - return isModifierPresent("static"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isFinal(int)} - * - * @return <code>true</code> if entity is final, otherwise <code>false</code> - */ - public boolean isFinal() { - return isModifierPresent("final"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isSynchronized(int)} - * - * @return <code>true</code> if entity is sunchronized, otherwise <code>false</code> - */ - public boolean isSynchronized() { - return isModifierPresent("synchronized"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isTransient(int)} - * - * @return <code>true</code> if entity is transient, otherwise <code>false</code> - */ - public boolean isTransient() { - return isModifierPresent("transient"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isVolatile(int)} - * - * @return <code>true</code> if entity is volatile, otherwise <code>false</code> - * @since 1.4 - */ - public boolean isVolatile() { - return isModifierPresent("volatile"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isNative(int)} - * - * @return <code>true</code> if entity is native, otherwise <code>false</code> - * @since 1.4 - */ - public boolean isNative() { - return isModifierPresent("native"); - } - - /** - * Equivalent of {@link java.lang.reflect.Modifier#isStrict(int)} - * - * @return <code>true</code> if entity is strictfp, otherwise <code>false</code> - * @since 1.4 - */ - public boolean isStrictfp() { - return isModifierPresent("strictfp"); - } - - /** - * Returns <code>true</code> if one of the modifiers matches the {@code modifier} - * - * @param modifier the modifier - * @return <code>true</code> if the modifier is present, otherwise <code>false</code> - */ - private boolean isModifierPresent(String modifier) { - return modifiers.contains(modifier); - } - - public void setParentClass( JavaClass parentClass ) - { - this.parentCls = parentClass; - } - - public JavaClass getParentClass() - { - return parentCls; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -}
Copied: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntity.java (from rev 1303, trunk/qdox/src/main/java/com/thoughtworks/qdox/model/AbstractJavaEntity.java) (0 => 1389)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntity.java (rev 0) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntity.java 2011-10-09 10:30:53 UTC (rev 1389) @@ -0,0 +1,177 @@ +package com.thoughtworks.qdox.model.impl; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Collections; +import java.util.List; + +import com.thoughtworks.qdox.model.AbstractBaseJavaEntity; +import com.thoughtworks.qdox.model.JavaClass; +import com.thoughtworks.qdox.model.JavaModel; + +public abstract class AbstractJavaEntity extends AbstractBaseJavaEntity implements JavaModel { + + private List<String> modifiers = Collections.emptyList(); + private JavaClass parentCls; + private String name; + + /** + * Return list of modifiers as Strings. + * (public, private, protected, final, abstract, static) + * @return a list of modifiers, never <code>null</code> + */ + public List<String> getModifiers() { + return modifiers; + } + + public void setModifiers(List<String> modifiers) { + this.modifiers = modifiers; + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isAbstract(int)} + * + * @return <code>true</code> if entity is abstract, otherwise <code>false</code> + */ + public boolean isAbstract() { + return isModifierPresent("abstract"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isPublic(int)} + * + * @return <code>true</code> if entity is public, otherwise <code>false</code> + */ + public boolean isPublic() { + return isModifierPresent("public"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isPrivate(int)} + * + * @return <code>true</code> if entity is private, otherwise <code>false</code> + */ + public boolean isPrivate() { + return isModifierPresent("private"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isProtected(int)} + * + * @return <code>true</code> if entity is protected, otherwise <code>false</code> + */ + public boolean isProtected() { + return isModifierPresent("protected"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isStatic(int)} + * + * @return <code>true</code> if entity is static, otherwise <code>false</code> + */ + public boolean isStatic() { + return isModifierPresent("static"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isFinal(int)} + * + * @return <code>true</code> if entity is final, otherwise <code>false</code> + */ + public boolean isFinal() { + return isModifierPresent("final"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isSynchronized(int)} + * + * @return <code>true</code> if entity is sunchronized, otherwise <code>false</code> + */ + public boolean isSynchronized() { + return isModifierPresent("synchronized"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isTransient(int)} + * + * @return <code>true</code> if entity is transient, otherwise <code>false</code> + */ + public boolean isTransient() { + return isModifierPresent("transient"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isVolatile(int)} + * + * @return <code>true</code> if entity is volatile, otherwise <code>false</code> + * @since 1.4 + */ + public boolean isVolatile() { + return isModifierPresent("volatile"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isNative(int)} + * + * @return <code>true</code> if entity is native, otherwise <code>false</code> + * @since 1.4 + */ + public boolean isNative() { + return isModifierPresent("native"); + } + + /** + * Equivalent of {@link java.lang.reflect.Modifier#isStrict(int)} + * + * @return <code>true</code> if entity is strictfp, otherwise <code>false</code> + * @since 1.4 + */ + public boolean isStrictfp() { + return isModifierPresent("strictfp"); + } + + /** + * Returns <code>true</code> if one of the modifiers matches the {@code modifier} + * + * @param modifier the modifier + * @return <code>true</code> if the modifier is present, otherwise <code>false</code> + */ + private boolean isModifierPresent(String modifier) { + return modifiers.contains(modifier); + } + + public void setParentClass( JavaClass parentClass ) + { + this.parentCls = parentClass; + } + + public JavaClass getParentClass() + { + return parentCls; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +}
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java (1388 => 1389)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java 2011-10-09 10:27:28 UTC (rev 1388) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java 2011-10-09 10:30:53 UTC (rev 1389) @@ -1,6 +1,5 @@ package com.thoughtworks.qdox.model.impl; -import com.thoughtworks.qdox.model.AbstractJavaEntity; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaParameterizedType;
Deleted: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/AbstractJavaEntityTest.java (1388 => 1389)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/AbstractJavaEntityTest.java 2011-10-09 10:27:28 UTC (rev 1388) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/AbstractJavaEntityTest.java 2011-10-09 10:30:53 UTC (rev 1389) @@ -1,129 +0,0 @@ -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.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import org.junit.Test; - -public class AbstractJavaEntityTest { - - private AbstractJavaEntity newAbstractJavaEntity() { - return new AbstractJavaEntity() - { - public String getCodeBlock() - { - return null; - } - }; - } - - @Test - public void testGetTagsByNameMethod() throws Exception { - AbstractBaseJavaEntity entity = newAbstractJavaEntity(); - List<DocletTag> tags = new LinkedList<DocletTag>(); - - DocletTag monkeyIsGoodTag = mock(DocletTag.class); - when(monkeyIsGoodTag.getName()).thenReturn( "monkey" ); - DocletTag monkeyIsFunnyTag = mock(DocletTag.class); - when(monkeyIsFunnyTag.getName()).thenReturn( "monkey" ); - DocletTag horseNotSoMuchTag = mock(DocletTag.class); - when(horseNotSoMuchTag.getName()).thenReturn( "horse" ); - - tags.add(monkeyIsGoodTag); - tags.add(monkeyIsFunnyTag); - tags.add(horseNotSoMuchTag); - entity.setTags(tags); - - assertEquals(2, entity.getTagsByName("monkey").size()); - assertEquals(1, entity.getTagsByName("horse").size()); - assertEquals(0, entity.getTagsByName("non existent tag").size()); - } - - @Test - public void testGetSingleTagByName() throws Exception { - AbstractBaseJavaEntity entity = newAbstractJavaEntity(); - List<DocletTag> tags = new LinkedList<DocletTag>(); - - DocletTag monkeyIsGoodTag = mock(DocletTag.class); - when(monkeyIsGoodTag.getName()).thenReturn( "monkey" ); - when(monkeyIsGoodTag.getValue()).thenReturn( "is good" ); - DocletTag monkeyIsFunnyTag = mock(DocletTag.class); - when(monkeyIsFunnyTag.getName()).thenReturn( "monkey" ); - when(monkeyIsFunnyTag.getValue()).thenReturn( "is funny" ); - DocletTag horseNotSoMuchTag = mock(DocletTag.class); - when(horseNotSoMuchTag.getName()).thenReturn( "horse" ); - when(horseNotSoMuchTag.getValue()).thenReturn( "not so much" ); - - tags.add(monkeyIsGoodTag); - tags.add(monkeyIsFunnyTag); - tags.add(horseNotSoMuchTag); - entity.setTags(tags); - - assertEquals("is good", entity.getTagByName("monkey").getValue()); - assertEquals("not so much", entity.getTagByName("horse").getValue()); - assertNull(entity.getTagByName("cow")); - - } - - @Test - public void testPublicModifer() { - AbstractJavaEntity entity = newAbstractJavaEntity(); - entity.setModifiers( Collections.singletonList( "public" ) ); - assertTrue( entity.isPublic() ); - } - - @Test - public void testPrivateModifer() { - AbstractJavaEntity entity = newAbstractJavaEntity(); - entity.setModifiers(Collections.singletonList( "private" )); - assertTrue(entity.isPrivate()); - } - - @Test - public void testAbstractModifer() { - AbstractJavaEntity entity = newAbstractJavaEntity(); - entity.setModifiers(Arrays.asList(new String[]{"public", "abstract"})); - assertTrue(entity.isAbstract()); - assertTrue(!entity.isPrivate()); - } - - @Test - public void testProtectedModifer() { - AbstractJavaEntity entity = newAbstractJavaEntity(); - entity.setModifiers(Arrays.asList(new String[]{"protected", "abstract", "synchronized", "transient"})); - assertTrue(entity.isProtected()); - assertTrue(entity.isSynchronized()); - assertTrue(entity.isTransient()); - } - - @Test - public void testStaticModifer() { - AbstractJavaEntity entity = newAbstractJavaEntity(); - entity.setModifiers(Arrays.asList(new String[]{"public", "static", "final"})); - assertTrue(entity.isStatic()); - assertTrue(entity.isFinal()); - } - - @Test - public void testQDOX30() { - AbstractJavaEntity entity = newAbstractJavaEntity(); - entity.setModifiers(Arrays.asList(new String[]{"native", "volatile", "strictfp"})); - assertTrue(entity.isNative()); - assertTrue(entity.isVolatile()); - assertTrue(entity.isStrictfp()); - } - - @Test - public void testGetTagsReturnsEmptyArrayInsteadOfNull() throws Exception { - AbstractJavaEntity entity = newAbstractJavaEntity(); - assertEquals(0, entity.getTags().size()); - } -}
Copied: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntityTest.java (from rev 1303, trunk/qdox/src/test/java/com/thoughtworks/qdox/model/AbstractJavaEntityTest.java) (0 => 1389)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntityTest.java (rev 0) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/AbstractJavaEntityTest.java 2011-10-09 10:30:53 UTC (rev 1389) @@ -0,0 +1,132 @@ +package com.thoughtworks.qdox.model.impl; + +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.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import org.junit.Test; + +import com.thoughtworks.qdox.model.AbstractBaseJavaEntity; +import com.thoughtworks.qdox.model.DocletTag; + +public class AbstractJavaEntityTest { + + private AbstractJavaEntity newAbstractJavaEntity() { + return new AbstractJavaEntity() + { + public String getCodeBlock() + { + return null; + } + }; + } + + @Test + public void testGetTagsByNameMethod() throws Exception { + AbstractBaseJavaEntity entity = newAbstractJavaEntity(); + List<DocletTag> tags = new LinkedList<DocletTag>(); + + DocletTag monkeyIsGoodTag = mock(DocletTag.class); + when(monkeyIsGoodTag.getName()).thenReturn( "monkey" ); + DocletTag monkeyIsFunnyTag = mock(DocletTag.class); + when(monkeyIsFunnyTag.getName()).thenReturn( "monkey" ); + DocletTag horseNotSoMuchTag = mock(DocletTag.class); + when(horseNotSoMuchTag.getName()).thenReturn( "horse" ); + + tags.add(monkeyIsGoodTag); + tags.add(monkeyIsFunnyTag); + tags.add(horseNotSoMuchTag); + entity.setTags(tags); + + assertEquals(2, entity.getTagsByName("monkey").size()); + assertEquals(1, entity.getTagsByName("horse").size()); + assertEquals(0, entity.getTagsByName("non existent tag").size()); + } + + @Test + public void testGetSingleTagByName() throws Exception { + AbstractBaseJavaEntity entity = newAbstractJavaEntity(); + List<DocletTag> tags = new LinkedList<DocletTag>(); + + DocletTag monkeyIsGoodTag = mock(DocletTag.class); + when(monkeyIsGoodTag.getName()).thenReturn( "monkey" ); + when(monkeyIsGoodTag.getValue()).thenReturn( "is good" ); + DocletTag monkeyIsFunnyTag = mock(DocletTag.class); + when(monkeyIsFunnyTag.getName()).thenReturn( "monkey" ); + when(monkeyIsFunnyTag.getValue()).thenReturn( "is funny" ); + DocletTag horseNotSoMuchTag = mock(DocletTag.class); + when(horseNotSoMuchTag.getName()).thenReturn( "horse" ); + when(horseNotSoMuchTag.getValue()).thenReturn( "not so much" ); + + tags.add(monkeyIsGoodTag); + tags.add(monkeyIsFunnyTag); + tags.add(horseNotSoMuchTag); + entity.setTags(tags); + + assertEquals("is good", entity.getTagByName("monkey").getValue()); + assertEquals("not so much", entity.getTagByName("horse").getValue()); + assertNull(entity.getTagByName("cow")); + + } + + @Test + public void testPublicModifer() { + AbstractJavaEntity entity = newAbstractJavaEntity(); + entity.setModifiers( Collections.singletonList( "public" ) ); + assertTrue( entity.isPublic() ); + } + + @Test + public void testPrivateModifer() { + AbstractJavaEntity entity = newAbstractJavaEntity(); + entity.setModifiers(Collections.singletonList( "private" )); + assertTrue(entity.isPrivate()); + } + + @Test + public void testAbstractModifer() { + AbstractJavaEntity entity = newAbstractJavaEntity(); + entity.setModifiers(Arrays.asList(new String[]{"public", "abstract"})); + assertTrue(entity.isAbstract()); + assertTrue(!entity.isPrivate()); + } + + @Test + public void testProtectedModifer() { + AbstractJavaEntity entity = newAbstractJavaEntity(); + entity.setModifiers(Arrays.asList(new String[]{"protected", "abstract", "synchronized", "transient"})); + assertTrue(entity.isProtected()); + assertTrue(entity.isSynchronized()); + assertTrue(entity.isTransient()); + } + + @Test + public void testStaticModifer() { + AbstractJavaEntity entity = newAbstractJavaEntity(); + entity.setModifiers(Arrays.asList(new String[]{"public", "static", "final"})); + assertTrue(entity.isStatic()); + assertTrue(entity.isFinal()); + } + + @Test + public void testQDOX30() { + AbstractJavaEntity entity = newAbstractJavaEntity(); + entity.setModifiers(Arrays.asList(new String[]{"native", "volatile", "strictfp"})); + assertTrue(entity.isNative()); + assertTrue(entity.isVolatile()); + assertTrue(entity.isStrictfp()); + } + + @Test + public void testGetTagsReturnsEmptyArrayInsteadOfNull() throws Exception { + AbstractJavaEntity entity = newAbstractJavaEntity(); + assertEquals(0, entity.getTags().size()); + } +}
To unsubscribe from this list please visit:
