edu.rice.cs.drjava.model
Class FindReplaceMachineTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by edu.rice.cs.drjava.DrJavaTestCase
              extended by edu.rice.cs.drjava.model.FindReplaceMachineTest
All Implemented Interfaces:
junit.framework.Test

public class FindReplaceMachineTest
extends DrJavaTestCase

Tests the FindReplaceMachine.

Version:
$Id: FindReplaceMachineTest.java 5444 2011-08-17 07:54:58Z rcartwright $

Nested Class Summary
 
Nested classes/interfaces inherited from class junit.framework.TestCase
junit.framework.TestCase.WrappedException
 
Field Summary
private  OpenDefinitionsDocument _doc
           
private  OpenDefinitionsDocument _docNext
           
private  OpenDefinitionsDocument _docPrev
           
private  FindReplaceMachine _frm
           
private static AbstractGlobalModel _model
           
private  int _offset
           
private  FindResult _result
           
private  File _tempDir
           
private static String EVIL_TEXT
           
private static String EVIL_TEXT_NEXT
           
private static String EVIL_TEXT_PREV
           
private static String FIND_MULTI_LINE_SEARCH_STR
           
private static String FIND_WHOLE_WORD_TEST_1
           
private static String IGNORE_TEXT
           
 
Constructor Summary
FindReplaceMachineTest()
           
 
Method Summary
private  void _assertOffset(FindReplaceMachine frm, int current)
           
private  void _assertOffsets(FindReplaceMachine frm, int start, int current)
           
private  void _initFrm(int pos)
           
private  void _testFindNextFails(FindReplaceMachine frm, int start, int current)
           
private  void _testFindNextSucceeds(FindReplaceMachine frm, int start, int found)
           
private  void _testFindNextSucceeds(FindReplaceMachine frm, int start, int found, OpenDefinitionsDocument doc)
           
private  void replaceAll()
           
 void setUp()
          Initializes the document for the tests.
 void tearDown()
          Clean up for every test case.
 void testAnyOccurrenceSearchIgnore()
           
 void testCreateMachineSuccess()
           
 void testFindMatchWithCaretInMiddle()
           
 void testFindMatchWithCaretInMiddleBackwards()
           
 void testFindMultiLine()
           
 void testFindNextAndFailIsOnMatch()
           
 void testFindNextOnSuffix()
           
 void testFindNextUpdatesCurrent()
           
 void testFindNoMatchCase()
           
 void testFindPartialSubstrings()
          This test checks that a findNext won't find two matches that partially overlap.
 void testFindPrevOnPrefix()
           
 void testFindReplaceInAllOpenFiles()
          This test addresses feature request #784514 Find/Replace in all Open Files.
 void testFindReplaceInAllOpenFilesWholeWord()
           
 void testMultipleCallsToFindNext()
           
 void testNotInDocument()
           
 void testReplaceAllBackwards()
           
 void testReplaceAllContinue()
           
 void testReplaceAllContinueNoMatchCase()
           
 void testReplaceAllSameWord()
          This test checks that replacing a word with itself will halt on replace all.
 void testReplaceCreatesMatch()
          This tests that a replace all where the replacement action creates a new match does not replace this new match
 void testReplaceCreatesMatchBackwards()
          This tests that a replace all backwards where the replacement action creates a new match does not replace this new match
 void testSearchesDoNotRepeatWhenChangingDirection()
          This test addresses bug #745714 Searches Repeat When Changing Direction.
 void testSimpleReplace()
           
 void testStartFromTopContinue()
           
 void testWholeWordSearchIgnore()
           
 void testWholeWordSearchOnTestString1()
           
 
Methods inherited from class edu.rice.cs.drjava.DrJavaTestCase
setConfigSetting, setDocText
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_doc

private volatile OpenDefinitionsDocument _doc

_docPrev

private volatile OpenDefinitionsDocument _docPrev

_docNext

private volatile OpenDefinitionsDocument _docNext

_result

private volatile FindResult _result

_frm

private volatile FindReplaceMachine _frm

_tempDir

private volatile File _tempDir

_offset

private volatile int _offset

_model

private static final AbstractGlobalModel _model

EVIL_TEXT

private static final String EVIL_TEXT
See Also:
Constant Field Values

EVIL_TEXT_PREV

private static final String EVIL_TEXT_PREV
See Also:
Constant Field Values

EVIL_TEXT_NEXT

private static final String EVIL_TEXT_NEXT
See Also:
Constant Field Values

FIND_WHOLE_WORD_TEST_1

private static final String FIND_WHOLE_WORD_TEST_1
See Also:
Constant Field Values

FIND_MULTI_LINE_SEARCH_STR

private static final String FIND_MULTI_LINE_SEARCH_STR

IGNORE_TEXT

private static final String IGNORE_TEXT
See Also:
Constant Field Values
Constructor Detail

FindReplaceMachineTest

public FindReplaceMachineTest()
Method Detail

setUp

public void setUp()
           throws Exception
Initializes the document for the tests.

Overrides:
setUp in class DrJavaTestCase
Throws:
Exception - This convention is mandated by JUnit.TestCase, the superclass of this class.

tearDown

public void tearDown()
              throws Exception
Description copied from class: DrJavaTestCase
Clean up for every test case. Only used in unit tests. Added because Windows would intermittently throw a java.util.concurrent.RejectedExecutionException during cleanup.

Overrides:
tearDown in class DrJavaTestCase
Throws:
Exception

_initFrm

private void _initFrm(int pos)

testCreateMachineSuccess

public void testCreateMachineSuccess()
                              throws BadLocationException
Throws:
BadLocationException

testFindNextUpdatesCurrent

public void testFindNextUpdatesCurrent()
                                throws BadLocationException
Throws:
BadLocationException

testFindNextAndFailIsOnMatch

public void testFindNextAndFailIsOnMatch()
                                  throws BadLocationException
Throws:
BadLocationException

testFindNextOnSuffix

public void testFindNextOnSuffix()
                          throws BadLocationException
Throws:
BadLocationException

testFindPrevOnPrefix

public void testFindPrevOnPrefix()
                          throws BadLocationException
Throws:
BadLocationException

testMultipleCallsToFindNext

public void testMultipleCallsToFindNext()
                                 throws BadLocationException
Throws:
BadLocationException

testStartFromTopContinue

public void testStartFromTopContinue()
                              throws BadLocationException
Throws:
BadLocationException

testNotInDocument

public void testNotInDocument()
                       throws BadLocationException
Throws:
BadLocationException

testSimpleReplace

public void testSimpleReplace()
                       throws BadLocationException
Throws:
BadLocationException

testReplaceAllContinue

public void testReplaceAllContinue()
                            throws BadLocationException
Throws:
BadLocationException

testFindNoMatchCase

public void testFindNoMatchCase()
                         throws BadLocationException
Throws:
BadLocationException

testReplaceAllContinueNoMatchCase

public void testReplaceAllContinueNoMatchCase()
                                       throws BadLocationException
Throws:
BadLocationException

testReplaceAllBackwards

public void testReplaceAllBackwards()
                             throws BadLocationException
Throws:
BadLocationException

testFindMatchWithCaretInMiddle

public void testFindMatchWithCaretInMiddle()
                                    throws BadLocationException
Throws:
BadLocationException

testFindMatchWithCaretInMiddleBackwards

public void testFindMatchWithCaretInMiddleBackwards()
                                             throws BadLocationException
Throws:
BadLocationException

testReplaceCreatesMatch

public void testReplaceCreatesMatch()
                             throws BadLocationException
This tests that a replace all where the replacement action creates a new match does not replace this new match

Throws:
BadLocationException

testReplaceCreatesMatchBackwards

public void testReplaceCreatesMatchBackwards()
                                      throws BadLocationException
This tests that a replace all backwards where the replacement action creates a new match does not replace this new match

Throws:
BadLocationException

testReplaceAllSameWord

public void testReplaceAllSameWord()
                            throws BadLocationException
This test checks that replacing a word with itself will halt on replace all.

Throws:
BadLocationException

testFindPartialSubstrings

public void testFindPartialSubstrings()
                               throws BadLocationException
This test checks that a findNext won't find two matches that partially overlap. This is the current behavior of the FindReplaceMachine, though at some time in the future someone may want to change it.

Throws:
BadLocationException

testSearchesDoNotRepeatWhenChangingDirection

public void testSearchesDoNotRepeatWhenChangingDirection()
                                                  throws BadLocationException
This test addresses bug #745714 Searches Repeat When Changing Direction. The word that was just found should not be found again after toggling the search backwards flag.

Throws:
BadLocationException

testFindReplaceInAllOpenFiles

public void testFindReplaceInAllOpenFiles()
                                   throws BadLocationException
This test addresses feature request #784514 Find/Replace in all Open Files.

Throws:
BadLocationException

testFindReplaceInAllOpenFilesWholeWord

public void testFindReplaceInAllOpenFilesWholeWord()
                                            throws BadLocationException
Throws:
BadLocationException

testFindMultiLine

public void testFindMultiLine()
                       throws BadLocationException
Throws:
BadLocationException

testWholeWordSearchOnTestString1

public void testWholeWordSearchOnTestString1()
                                      throws BadLocationException
Throws:
BadLocationException

testWholeWordSearchIgnore

public void testWholeWordSearchIgnore()
                               throws BadLocationException
Throws:
BadLocationException

testAnyOccurrenceSearchIgnore

public void testAnyOccurrenceSearchIgnore()
                                   throws BadLocationException
Throws:
BadLocationException

_testFindNextSucceeds

private void _testFindNextSucceeds(FindReplaceMachine frm,
                                   int start,
                                   int found,
                                   OpenDefinitionsDocument doc)

_testFindNextSucceeds

private void _testFindNextSucceeds(FindReplaceMachine frm,
                                   int start,
                                   int found)

_testFindNextFails

private void _testFindNextFails(FindReplaceMachine frm,
                                int start,
                                int current)

_assertOffsets

private void _assertOffsets(FindReplaceMachine frm,
                            int start,
                            int current)

_assertOffset

private void _assertOffset(FindReplaceMachine frm,
                           int current)

replaceAll

private void replaceAll()