Author: hoang_to
Date: 2011-06-29 01:50:58 -0400 (Wed, 29 Jun 2011)
New Revision: 6774
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkipCommentReader.java
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java
Log:
GTNPORTAL-1943: Update SkipCommentReader and JUnit tests
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkipCommentReader.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkipCommentReader.java 2011-06-29
04:55:29 UTC (rev 6773)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkipCommentReader.java 2011-06-29
05:50:58 UTC (rev 6774)
@@ -190,9 +190,7 @@
nextChar = readSingleCharacter();
}
- String line = builder.toString().trim();
-
- return line;
+ return builder.toString().trim();
}
/**
Modified:
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java 2011-06-29
04:55:29 UTC (rev 6773)
+++
portal/branches/branch-GTNPORTAL-1921/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestSkipCommentReader.java 2011-06-29
05:50:58 UTC (rev 6774)
@@ -127,7 +127,49 @@
line = skipCommentReader.readLine();
assertEquals("4.abcdefghijklmn", line);
+ }
+ public void testNumberOfCommingEscapes() throws IOException
+ {
+ String COMMENT_BLOCK = "/*COMMENT BLOCK*/";
+ StringBuilder builder = new StringBuilder();
+ builder.append(COMMENT_BLOCK).append("1.abcdefghijklmn\n");
+ builder.append("2.abcdefghijklmn\n");
+
builder.append("3.").append(COMMENT_BLOCK).append("abcdefghijklmn\n");
+
+ Reader reader = new StringReader(builder.toString());
+ initiateReader(reader);
+
+ skipCommentReader.setNumberOfCommingEscapes(COMMENT_BLOCK.length());
+ String firstLine = skipCommentReader.readLine();
+ assertEquals(COMMENT_BLOCK + "1.abcdefghijklmn", firstLine);
+
+ String secondLine = skipCommentReader.readLine();
+ assertEquals("2.abcdefghijklmn", secondLine);
+
+ skipCommentReader.setNumberOfCommingEscapes(2 + COMMENT_BLOCK.length());
+ String thirdLine = skipCommentReader.readLine();
+ assertEquals("3." + COMMENT_BLOCK + "abcdefghijklmn",
thirdLine);
}
+
+ public void testCursorState() throws IOException
+ {
+ Reader reader = new StringReader("0123456//*xxxx*/*789");
+ initiateReader(reader);
+
+ assertEquals(SkipCommentReader.State.ENCOUNTING_ORDINARY_CHARACTER,
skipCommentReader.getCursorState());
+ for(int i = 0; i < 7; i++)
+
+ {
+ int readChar = skipCommentReader.readSingleCharacter();
+ assertEquals(SkipCommentReader.State.ENCOUNTING_ORDINARY_CHARACTER,
skipCommentReader.getCursorState());
+ }
+
+ skipCommentReader.readSingleCharacter();
+ assertEquals(SkipCommentReader.State.ENCOUNTING_FORWARD_SLASH,
skipCommentReader.getCursorState());
+
+ skipCommentReader.readSingleCharacter();//The comment block is automatically
skipped
+ assertEquals(SkipCommentReader.State.ENCOUNTING_ASTERIK,
skipCommentReader.getCursorState());
+ }
}