edu.rice.cs.drjava.model
Class GlobalModelTestCase

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.MultiThreadedTestCase
                  extended by edu.rice.cs.drjava.model.GlobalModelTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
DebugTestCase, GlobalIndentTest, GlobalModelCompileErrorsTest, GlobalModelCompileIOTest, GlobalModelCompileSuccessTestCase, GlobalModelCompileTest, GlobalModelIOTest, GlobalModelJUnitTest, GlobalModelOtherTest, InteractionsModelErrorTest, JUnitErrorModelTest, SingleDisplayModelTest

public abstract class GlobalModelTestCase
extends MultiThreadedTestCase

Base class for tests over the GlobalModel. This class provides a number of convenience methods for testing the GlobalModel. It also contains a model instance (reset in setUp() and a temporary directory that's created per test invocation (and subsequently cleaned in tearDown(). This reduces the burden for such file management stuff in the test cases themselves.

Version:
$Id: GlobalModelTestCase.java 5443 2011-08-17 04:58:50Z rcartwright $

Nested Class Summary
static class GlobalModelTestCase.CancelingSelector
           
static class GlobalModelTestCase.CompileShouldFailListener
          A model listener for situations expecting a compilation to fail.
static class GlobalModelTestCase.CompileShouldSucceedListener
          A model listener for situations expecting a compilation to succeed.
static class GlobalModelTestCase.FileMovedWarningException
           
static class GlobalModelTestCase.FileSelector
          This class is used by several test cases in Compile Tests that expect incorrect behavior concerning the saving of files.
static class GlobalModelTestCase.InteractionListener
           
static class GlobalModelTestCase.JUnitNonTestListener
          Listener class for failing JUnit invocation.
static class GlobalModelTestCase.JUnitTestListener
           
static class GlobalModelTestCase.OpenWarningException
           
static class GlobalModelTestCase.OverwriteException
           
static class GlobalModelTestCase.SaveCopyFileSelector
           
static class GlobalModelTestCase.TestGlobalModel
           
static class GlobalModelTestCase.TestListener
          A GlobalModelListener for testing.
static class GlobalModelTestCase.WarningFileSelector
           
 
Nested classes/interfaces inherited from class junit.framework.TestCase
junit.framework.TestCase.WrappedException
 
Field Summary
protected  OpenDefinitionsDocument _doc
           
protected  InteractionsController _interactionsController
           
static Log _log
           
protected  DefaultGlobalModel _model
           
protected  File _tempDir
           
protected static String BAR_TEXT
           
protected static String BAZ_TEXT
           
protected static String FOO_MISSING_CLOSE_TEXT
           
protected static String FOO_PACKAGE_AFTER_IMPORT
           
protected static String FOO_PACKAGE_AS_FIELD
           
protected static String FOO_PACKAGE_AS_FIELD_2
           
protected static String FOO_PACKAGE_AS_PART_OF_FIELD
           
protected static String FOO_PACKAGE_INSIDE_CLASS
           
protected static String FOO_TEXT
           
 
Fields inherited from class edu.rice.cs.drjava.model.MultiThreadedTestCase
_testFailed
 
Constructor Summary
GlobalModelTestCase()
           
 
Method Summary
private  void _assertInteractionContainsHelper(String text, boolean shouldContain)
           
private  void _assertInteractionMatchesHelper(String regex, boolean shouldMatch)
           
protected  void assertCompileErrorsPresent(boolean b)
           
protected  void assertCompileErrorsPresent(String name, boolean b)
           
protected  void assertContents(String s, OpenDefinitionsDocument doc)
           
protected  void assertInteractionsContains(String text)
          Asserts that the given string exists in the Interactions Document.
protected  void assertInteractionsDoesNotContain(String text)
          Asserts that the given string does not exist in the Interactions Document.
protected  void assertInteractionsDoesNotMatch(String regex)
          Asserts that the text in the Interactions Document does NOT match the given regex.
protected  void assertInteractionsMatches(String regex)
          Asserts that the text in the Interactions Document matches the given regex.
protected  void assertLength(int len, OpenDefinitionsDocument doc)
           
protected  void assertModified(boolean b, OpenDefinitionsDocument doc)
           
protected  void assertNumOpenDocs(int num)
           
protected  void changeDocumentText(String s, OpenDefinitionsDocument doc)
          Clear all old text and insert the given text.
protected  File classForJava(File sourceFile, String className)
          Given a .java file and a class file name, returns the corresponding .class file.
protected  File createFile(String name)
           
protected  void doCompile(OpenDefinitionsDocument doc, File file)
          Saves to the given file, and then compiles the given document.
protected  OpenDefinitionsDocument doCompile(String text, File file)
          Compiles a new file with the given text.
protected  String getCompilerErrorString()
          Returns a string with all compiler errors.
protected  String getInteractionsText()
          Returns the current contents of the interactions document
protected  String interpret(String input)
          Puts the given input into the interactions document and then interprets it, returning the result that was put into the interactions document.
protected  void interpretIgnoreResult(String input)
          Appends the input string to the interactions pane and interprets it.
protected  void safeLoadHistory(GlobalModelTestCase.FileSelector fs)
           
protected  void safeSaveHistory(GlobalModelTestCase.FileSelector fs)
           
protected  void saveAllFiles(GlobalModel model, FileSaveSelector fs)
           
protected  void saveFile(OpenDefinitionsDocument doc, FileSaveSelector fss)
          Invokes doc.saveFile from within the event thread.
protected  void saveFileAs(OpenDefinitionsDocument doc, FileSaveSelector fss)
          Invokes doc.saveFileAs from within the event thread.
protected  void saveFileCopy(OpenDefinitionsDocument doc, FileSaveSelector fss)
          Invokes doc.saveFileCopy from within the event thread.
 void setUp()
          Setup for each test case, which does the following.
protected  OpenDefinitionsDocument setupDocument(String text)
          Creates and returns a new document, makes sure newFile is fired, and then adds some text.
 void tearDown()
          Teardown for each test case, which recursively deletes the temporary directory created in setUp.
protected  File tempDirectory()
          Create a new temporary directory in _tempDir.
protected  File tempFile()
          Create a new temporary file in _tempDir.
protected  File tempFile(int i)
          Create a new temporary file in _tempDir.
protected static void testStartCompile(OpenDefinitionsDocument doc)
          Invokes startCompile on the given document in the event thread.
protected  File writeToNewTempFile(String text)
          Creates a new temporary file and writes the given text to it.
 
Methods inherited from class edu.rice.cs.drjava.model.MultiThreadedTestCase
join, listenerFail, listenerFail, wait
 
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

_log

public static final Log _log

_model

protected volatile DefaultGlobalModel _model

_interactionsController

protected volatile InteractionsController _interactionsController

_tempDir

protected volatile File _tempDir

_doc

protected volatile OpenDefinitionsDocument _doc

FOO_TEXT

protected static final String FOO_TEXT
See Also:
Constant Field Values

BAR_TEXT

protected static final String BAR_TEXT
See Also:
Constant Field Values

BAZ_TEXT

protected static final String BAZ_TEXT
See Also:
Constant Field Values

FOO_MISSING_CLOSE_TEXT

protected static final String FOO_MISSING_CLOSE_TEXT
See Also:
Constant Field Values

FOO_PACKAGE_AFTER_IMPORT

protected static final String FOO_PACKAGE_AFTER_IMPORT
See Also:
Constant Field Values

FOO_PACKAGE_INSIDE_CLASS

protected static final String FOO_PACKAGE_INSIDE_CLASS
See Also:
Constant Field Values

FOO_PACKAGE_AS_FIELD

protected static final String FOO_PACKAGE_AS_FIELD
See Also:
Constant Field Values

FOO_PACKAGE_AS_FIELD_2

protected static final String FOO_PACKAGE_AS_FIELD_2
See Also:
Constant Field Values

FOO_PACKAGE_AS_PART_OF_FIELD

protected static final String FOO_PACKAGE_AS_PART_OF_FIELD
See Also:
Constant Field Values
Constructor Detail

GlobalModelTestCase

public GlobalModelTestCase()
Method Detail

setUp

public void setUp()
           throws Exception
Setup for each test case, which does the following.
  1. Creates a new GlobalModel in _model for each test case run.
  2. Creates a new temporary directory in _tempDir.

Overrides:
setUp in class MultiThreadedTestCase
Throws:
Exception - This convention is mandated by the JUnit TestCase class which is an ancestor of this class.

tearDown

public void tearDown()
              throws Exception
Teardown for each test case, which recursively deletes the temporary directory created in setUp.

Overrides:
tearDown in class MultiThreadedTestCase
Throws:
Exception

changeDocumentText

protected void changeDocumentText(String s,
                                  OpenDefinitionsDocument doc)
Clear all old text and insert the given text.


tempFile

protected File tempFile()
                 throws IOException
Create a new temporary file in _tempDir.

Throws:
IOException

tempFile

protected File tempFile(int i)
                 throws IOException
Create a new temporary file in _tempDir. Calls with the same int will return the same filename, while calls with different ints will return different filenames.

Throws:
IOException

tempDirectory

protected File tempDirectory()
                      throws IOException
Create a new temporary directory in _tempDir.

Throws:
IOException

createFile

protected File createFile(String name)

classForJava

protected File classForJava(File sourceFile,
                            String className)
Given a .java file and a class file name, returns the corresponding .class file.


writeToNewTempFile

protected File writeToNewTempFile(String text)
                           throws IOException
Creates a new temporary file and writes the given text to it. The File object for the new file is returned.

Throws:
IOException

setupDocument

protected OpenDefinitionsDocument setupDocument(String text)
                                         throws BadLocationException
Creates and returns a new document, makes sure newFile is fired, and then adds some text. When this method is done newCount is reset to 0.

Returns:
the new modified document
Throws:
BadLocationException

safeLoadHistory

protected void safeLoadHistory(GlobalModelTestCase.FileSelector fs)

safeSaveHistory

protected void safeSaveHistory(GlobalModelTestCase.FileSelector fs)

testStartCompile

protected static void testStartCompile(OpenDefinitionsDocument doc)
Invokes startCompile on the given document in the event thread.


doCompile

protected OpenDefinitionsDocument doCompile(String text,
                                            File file)
                                     throws IOException,
                                            BadLocationException,
                                            InterruptedException
Compiles a new file with the given text. The compile is expected to succeed and it is checked to make sure it worked reasonably. This method does not return until the Interactions JVM has reset and is ready to use.

Parameters:
text - Code for the class to be compiled
file - File to save the class in
Returns:
Document after it has been saved and compiled
Throws:
IOException
BadLocationException
InterruptedException

doCompile

protected void doCompile(OpenDefinitionsDocument doc,
                         File file)
                  throws IOException,
                         InterruptedException
Saves to the given file, and then compiles the given document. The compile is expected to succeed and it is checked to make sure it worked reasonably. This method does not return until the Interactions JVM has reset and is ready to use.

Parameters:
doc - Document containing the code to be compiled
file - File to save the class in
Throws:
IOException
InterruptedException

getCompilerErrorString

protected String getCompilerErrorString()
Returns a string with all compiler errors.


interpret

protected String interpret(String input)
                    throws EditDocumentException
Puts the given input into the interactions document and then interprets it, returning the result that was put into the interactions document. This assumes the interactions document is in a state with no text after the prompt. To be sure this is the case, you can reset interactions first. This method provides its own listener to synchronized with the completion of the interaction.

Parameters:
input - text to interpret
Returns:
The output from this interpretation, in String form, as it was printed to the interactions document.
Throws:
EditDocumentException

interpretIgnoreResult

protected void interpretIgnoreResult(String input)
                              throws EditDocumentException
Appends the input string to the interactions pane and interprets it.

Throws:
EditDocumentException

assertInteractionsContains

protected void assertInteractionsContains(String text)
                                   throws EditDocumentException
Asserts that the given string exists in the Interactions Document.

Throws:
EditDocumentException

assertInteractionsDoesNotContain

protected void assertInteractionsDoesNotContain(String text)
                                         throws EditDocumentException
Asserts that the given string does not exist in the Interactions Document.

Throws:
EditDocumentException

_assertInteractionContainsHelper

private void _assertInteractionContainsHelper(String text,
                                              boolean shouldContain)
                                       throws EditDocumentException
Throws:
EditDocumentException

assertInteractionsMatches

protected void assertInteractionsMatches(String regex)
                                  throws EditDocumentException
Asserts that the text in the Interactions Document matches the given regex.

Throws:
EditDocumentException

assertInteractionsDoesNotMatch

protected void assertInteractionsDoesNotMatch(String regex)
                                       throws EditDocumentException
Asserts that the text in the Interactions Document does NOT match the given regex.

Throws:
EditDocumentException

_assertInteractionMatchesHelper

private void _assertInteractionMatchesHelper(String regex,
                                             boolean shouldMatch)
                                      throws EditDocumentException
Throws:
EditDocumentException

getInteractionsText

protected String getInteractionsText()
                              throws EditDocumentException
Returns the current contents of the interactions document

Throws:
EditDocumentException

assertNumOpenDocs

protected void assertNumOpenDocs(int num)

assertModified

protected void assertModified(boolean b,
                              OpenDefinitionsDocument doc)

assertLength

protected void assertLength(int len,
                            OpenDefinitionsDocument doc)

assertContents

protected void assertContents(String s,
                              OpenDefinitionsDocument doc)
                       throws BadLocationException
Throws:
BadLocationException

saveFile

protected void saveFile(OpenDefinitionsDocument doc,
                        FileSaveSelector fss)
Invokes doc.saveFile from within the event thread.


saveFileAs

protected void saveFileAs(OpenDefinitionsDocument doc,
                          FileSaveSelector fss)
Invokes doc.saveFileAs from within the event thread.


saveFileCopy

protected void saveFileCopy(OpenDefinitionsDocument doc,
                            FileSaveSelector fss)
Invokes doc.saveFileCopy from within the event thread.


saveAllFiles

protected void saveAllFiles(GlobalModel model,
                            FileSaveSelector fs)

assertCompileErrorsPresent

protected void assertCompileErrorsPresent(boolean b)

assertCompileErrorsPresent

protected void assertCompileErrorsPresent(String name,
                                          boolean b)