edu.rice.cs.drjava.model
Class GlobalModelTestCase

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--edu.rice.cs.drjava.model.GlobalModelTestCase
All Implemented Interfaces:
Test
Direct Known Subclasses:
DebugTest, GlobalIndentTest, GlobalModelCompileTest, GlobalModelIOTest, GlobalModelJUnitTest, GlobalModelOtherTest, JUnitErrorModelTest, SingleDisplayModelTest

public abstract class GlobalModelTestCase
extends TestCase

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,v 1.37 2002/09/04 21:02:16 csreis Exp $

Inner Class Summary
 class GlobalModelTestCase.CancelingSelector
           
static class GlobalModelTestCase.CompileShouldFailListener
          A model listener for situations expecting a compilation to fail.
static class GlobalModelTestCase.CompileShouldSucceedListener
           
 class GlobalModelTestCase.FileSelector
          this class is used by several test cases in Compile Tests that expect incorrect behavior concerning the saving of files.
 class GlobalModelTestCase.OpenWarningException
           
 class GlobalModelTestCase.OverwriteException
           
static class GlobalModelTestCase.TestListener
          A GlobalModelListener for testing.
 class GlobalModelTestCase.WarningFileSelector
           
 
Field Summary
protected  DefaultGlobalModel _model
           
protected static DefaultGlobalModel _originalModel
          the prototype global model to hold the interpreter.
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 junit.framework.TestCase
fName
 
Constructor Summary
GlobalModelTestCase(String name)
          Constructor.
 
Method Summary
protected  void assertCompileErrorsPresent(boolean b)
           
protected  void assertCompileErrorsPresent(String name, boolean b)
           
protected  void assertContents(String s, OpenDefinitionsDocument doc)
           
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 createModel()
          Instantiates the GlobalModel to be used in the test cases.
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)
           
protected  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.
protected  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  File writeToNewTempFile(String text)
          Creates a new temporary file and writes the given text to it.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, name, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

_originalModel

protected static final DefaultGlobalModel _originalModel
the prototype global model to hold the interpreter. This prevents us from having to re-invoke the interpreter every time!

_model

protected DefaultGlobalModel _model

_tempDir

protected File _tempDir

FOO_TEXT

protected static final String FOO_TEXT

BAR_TEXT

protected static final String BAR_TEXT

BAZ_TEXT

protected static final String BAZ_TEXT

FOO_MISSING_CLOSE_TEXT

protected static final String FOO_MISSING_CLOSE_TEXT

FOO_PACKAGE_AFTER_IMPORT

protected static final String FOO_PACKAGE_AFTER_IMPORT

FOO_PACKAGE_INSIDE_CLASS

protected static final String FOO_PACKAGE_INSIDE_CLASS

FOO_PACKAGE_AS_FIELD

protected static final String FOO_PACKAGE_AS_FIELD

FOO_PACKAGE_AS_FIELD_2

protected static final String FOO_PACKAGE_AS_FIELD_2

FOO_PACKAGE_AS_PART_OF_FIELD

protected static final String FOO_PACKAGE_AS_PART_OF_FIELD
Constructor Detail

GlobalModelTestCase

public GlobalModelTestCase(String name)
Constructor.
Parameters:
String - name
Method Detail

setUp

protected void setUp()
              throws IOException
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 TestCase

tearDown

protected void tearDown()
                 throws IOException
Teardown for each test case, which recursively deletes the temporary directory created in setUp.
Overrides:
tearDown in class TestCase

createModel

protected void createModel()
Instantiates the GlobalModel to be used in the test cases.

changeDocumentText

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

tempFile

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

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.

tempDirectory

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

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.

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

interpret

protected String interpret(String input)
                    throws BadLocationException
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.
Parameters:
input - text to interpret
Returns:
The output from this interpretation, in String form, as it was printed to the interactions document.

interpretIgnoreResult

protected void interpretIgnoreResult(String input)
                              throws BadLocationException

assertNumOpenDocs

protected void assertNumOpenDocs(int num)

assertModified

protected void assertModified(boolean b,
                              OpenDefinitionsDocument doc)

assertLength

protected void assertLength(int len,
                            OpenDefinitionsDocument doc)
                     throws BadLocationException

assertContents

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

assertCompileErrorsPresent

protected void assertCompileErrorsPresent(boolean b)

assertCompileErrorsPresent

protected void assertCompileErrorsPresent(String name,
                                          boolean b)