@Test public void testJavaDocParsing() throws Exception { String text = "/** Text */ public class MyClass{}"; JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text); JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc(); Assert.assertNotNull(javaDoc); Assert.assertEquals("Text", javaDoc.getText()); Assert.assertTrue(javaDoc.getTagNames().isEmpty()); }
@Test public void testJavaDocParsingTags() throws Exception { String text = "/** Do Something\n*@author George Gastaldi*/ public class MyClass{}"; JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text); JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc(); Assert.assertNotNull(javaDoc); Assert.assertEquals("Do Something", javaDoc.getText()); Assert.assertEquals(1, javaDoc.getTagNames().size()); JavaDocTag authorTag = javaDoc.getTags("@author").get(0); Assert.assertEquals("@author", authorTag.getName()); Assert.assertEquals("George Gastaldi", authorTag.getValue()); }
@Test public void testJavaDocMultiLineShouldNotConcatenateWords() throws Exception { String text = "/**" + LINE_SEPARATOR + "* The country where this currency is used mostly. This field is just for" + LINE_SEPARATOR + "* informational purposes and have no effect on any processing." + LINE_SEPARATOR + "*/" + LINE_SEPARATOR + "public class MyClass{}"; JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text); JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc(); String expected = "The country where this currency is used mostly. This field is just for informational purposes and have no effect on any processing."; Assert.assertEquals(expected, javaDoc.getFullText()); }
@Test public void testJavaDocEnumConstant() throws Exception { String text = "public enum MyEnum {" + "/**" + LINE_SEPARATOR + " * Do Something" + LINE_SEPARATOR + " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR + "" + "MY_CONSTANT;}"; JavaEnumSource javaEnum = Roaster.parse(JavaEnumSource.class, text); Assert.assertFalse(javaEnum.hasJavaDoc()); EnumConstantSource enumConstant = javaEnum.getEnumConstant("MY_CONSTANT"); Assert.assertTrue(enumConstant.hasJavaDoc()); JavaDocSource<EnumConstantSource> javaDoc = enumConstant.getJavaDoc(); String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi"; Assert.assertEquals(expected, javaDoc.getFullText()); }
@Test public void testJavaDocGetFullText() throws Exception { String text = "/**" + LINE_SEPARATOR + " * Do Something" + LINE_SEPARATOR + " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR + "public class MyClass" + LINE_SEPARATOR + "{" + LINE_SEPARATOR + "}"; JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text); Assert.assertTrue(javaClass.hasJavaDoc()); JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc(); String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi"; Assert.assertEquals(expected, javaDoc.getFullText()); }
@Test public void testJavaDocSetFullText() throws Exception { String expected = "/**" + LINE_SEPARATOR + " * Do Something" + LINE_SEPARATOR + " * " + LINE_SEPARATOR + " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR + "public class MyClass {" + LINE_SEPARATOR + "}"; JavaClassSource javaClass = Roaster.create(JavaClassSource.class).setPublic().setName("MyClass"); Assert.assertFalse(javaClass.hasJavaDoc()); JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc(); javaDoc.setFullText("Do Something" + LINE_SEPARATOR + "* @author George Gastaldi"); Assert.assertEquals(expected, javaClass.toString()); }