CommentUtil { private static void blockComment(JTextArea scriptPanel) { final int startOffset = scriptPanel.getSelectionStart(); final String commentedSelection = BLOCK_COMMENT_START + scriptPanel.getSelectedText() + BLOCK_COMMENT_END; scriptPanel.replaceSelection(commentedSelection); scriptPanel.setSelectionStart(startOffset); scriptPanel.setSelectionEnd(startOffset + commentedSelection.length()); }  static void commentOrUncommentSQL(JTextArea scriptPanel); static void commentOrUncommentJava(JTextArea scriptPanel); static void commentOrUncommentR(JTextArea scriptPanel); static void blockCommentOrUncomment(JTextArea scriptPanel); static final String SQL_COMMENT_CHARACTER; static final String JAVA_COMMENT_CHARACTER; static final String R_COMMENT_CHARACTER; static final String BLOCK_COMMENT_START; static final String BLOCK_COMMENT_END; }
@Test public void testBlockComment() throws BadLocationException { org.junit.Assume.assumeTrue(!GraphicsEnvironment.isHeadless()); RSyntaxTextArea scriptPanel = new RSyntaxTextArea(); scriptPanel.setText(TEXT); scriptPanel.select(13, 226); final String beforeSelection = scriptPanel.getText(0, scriptPanel.getSelectionStart()); final String selection = scriptPanel.getText( scriptPanel.getSelectionStart(), scriptPanel.getSelectedText().length()); final String afterSelection = scriptPanel.getText( scriptPanel.getSelectionEnd(), scriptPanel.getDocument().getEndPosition().getOffset() - scriptPanel.getSelectionEnd() - 1); final String expectedText = beforeSelection + CommentUtil.BLOCK_COMMENT_START + selection + CommentUtil.BLOCK_COMMENT_END + afterSelection; CommentUtil.blockCommentOrUncomment(scriptPanel); assertEquals(expectedText, scriptPanel.getText()); assertEquals(13, scriptPanel.getSelectionStart()); assertEquals(226 + CommentUtil.BLOCK_COMMENT_START.length() + CommentUtil.BLOCK_COMMENT_END.length(), scriptPanel.getSelectionEnd()); }