Skip to content

Commit

Permalink
Avoid usage of System.lineSeparator() due to JDK 1.6 compatibility. T…
Browse files Browse the repository at this point in the history
…hanks to Matt Benson
  • Loading branch information
gastaldi committed Nov 12, 2014
1 parent ddcc845 commit 54b3ee9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
Expand Up @@ -84,7 +84,7 @@ public String getFullText()
{
text.append(fragment);
}
text.append(System.lineSeparator());
text.append(System.getProperty("line.separator"));
}
return text.toString().trim();
}
Expand Down
Expand Up @@ -24,6 +24,8 @@
*/
public class JavaDocTest
{
private static final String LINE_SEPARATOR = System.getProperty("line.separator");

@Test
public void testJavaDocParsing() throws Exception
{
Expand Down Expand Up @@ -69,10 +71,10 @@ public void testJavaDocRefTag() throws Exception
@Test
public void testJavaDocCreation() throws Exception
{
String expected = "/**" + System.lineSeparator()
+ " * Do Something" + System.lineSeparator()
+ " * @author George Gastaldi" + System.lineSeparator() + " */" + System.lineSeparator()
+ "public class MyClass" + System.lineSeparator() + "{" + System.lineSeparator() + "}";
String expected = "/**" + LINE_SEPARATOR
+ " * Do Something" + LINE_SEPARATOR
+ " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR
+ "public class MyClass" + LINE_SEPARATOR + "{" + LINE_SEPARATOR + "}";
JavaClassSource javaClass = Roaster.create(JavaClassSource.class).setPublic().setName("MyClass");
Assert.assertFalse(javaClass.hasJavaDoc());
JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
Expand All @@ -83,28 +85,28 @@ public void testJavaDocCreation() throws Exception
@Test
public void testJavaDocSetFullText() throws Exception
{
String expected = "/**" + System.lineSeparator()
+ " * Do Something" + System.lineSeparator()
+ " * @author George Gastaldi" + System.lineSeparator() + " */" + System.lineSeparator()
+ "public class MyClass" + System.lineSeparator() + "{" + System.lineSeparator() + "}";
String expected = "/**" + LINE_SEPARATOR
+ " * Do Something" + LINE_SEPARATOR
+ " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR
+ "public class MyClass" + LINE_SEPARATOR + "{" + LINE_SEPARATOR + "}";
JavaClassSource javaClass = Roaster.create(JavaClassSource.class).setPublic().setName("MyClass");
Assert.assertFalse(javaClass.hasJavaDoc());
JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
javaDoc.setFullText("Do Something" + System.lineSeparator() + "* @author George Gastaldi");
javaDoc.setFullText("Do Something" + LINE_SEPARATOR + "* @author George Gastaldi");
Assert.assertEquals(expected, javaClass.toString());
}

@Test
public void testJavaDocGetFullText() throws Exception
{
String text = "/**" + System.lineSeparator()
+ " * Do Something" + System.lineSeparator()
+ " * @author George Gastaldi" + System.lineSeparator() + " */" + System.lineSeparator()
+ "public class MyClass" + System.lineSeparator() + "{" + System.lineSeparator() + "}";
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" + System.lineSeparator() + "@author George Gastaldi";
String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi";
Assert.assertEquals(expected, javaDoc.getFullText());
}

Expand All @@ -113,17 +115,17 @@ public void testJavaDocField() throws Exception
{
String text =
"public class MyClass {"
+ "/**" + System.lineSeparator()
+ " * Do Something" + System.lineSeparator()
+ " * @author George Gastaldi" + System.lineSeparator() + " */" + System.lineSeparator() + ""
+ "/**" + LINE_SEPARATOR
+ " * Do Something" + LINE_SEPARATOR
+ " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR + ""
+ "private String foo;}";
JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
Assert.assertFalse(javaClass.hasJavaDoc());
Assert.assertEquals(1, javaClass.getFields().size());
FieldSource<JavaClassSource> field = javaClass.getFields().get(0);
Assert.assertTrue(field.hasJavaDoc());
JavaDocSource<FieldSource<JavaClassSource>> javaDoc = field.getJavaDoc();
String expected = "Do Something" + System.lineSeparator() + "@author George Gastaldi";
String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi";
Assert.assertEquals(expected, javaDoc.getFullText());
}

Expand All @@ -132,17 +134,17 @@ public void testJavaDocMethod() throws Exception
{
String text =
"public class MyClass {"
+ "/**" + System.lineSeparator()
+ " * Do Something" + System.lineSeparator()
+ " * @author George Gastaldi" + System.lineSeparator() + " */" + System.lineSeparator() + ""
+ "/**" + LINE_SEPARATOR
+ " * Do Something" + LINE_SEPARATOR
+ " * @author George Gastaldi" + LINE_SEPARATOR + " */" + LINE_SEPARATOR + ""
+ "private void foo(){};}";
JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
Assert.assertFalse(javaClass.hasJavaDoc());
Assert.assertEquals(1, javaClass.getMethods().size());
MethodSource<JavaClassSource> method = javaClass.getMethods().get(0);
Assert.assertTrue(method.hasJavaDoc());
JavaDocSource<MethodSource<JavaClassSource>> javaDoc = method.getJavaDoc();
String expected = "Do Something" + System.lineSeparator() + "@author George Gastaldi";
String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi";
Assert.assertEquals(expected, javaDoc.getFullText());
}

Expand Down

0 comments on commit 54b3ee9

Please sign in to comment.