edu.rice.cs.drjava.model.repl
Class JavaInterpreterTest

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.repl.JavaInterpreterTest
All Implemented Interfaces:
Test

public class JavaInterpreterTest
extends DrJavaTestCase

Tests the functionality of the repl interpreter.

Version:
$Id: JavaInterpreterTest.java 5436 2011-08-02 06:58:19Z mgricken $

Nested Class Summary
 
Nested classes/interfaces inherited from class junit.framework.TestCase
TestCase.WrappedException
 
Field Summary
private  ClassPathManager _classPathManager
           
private  Interpreter _interpreter
           
private  ClassLoader _interpreterLoader
           
private  InteractionsPaneOptions _interpreterOptions
           
static boolean testValue
           
 
Constructor Summary
JavaInterpreterTest()
           
 
Method Summary
private  Object interpret(String s)
           
protected  void setUp()
          The setup method run before each test.
 void testArrayCloning()
          Test that array cloning works.
 void testBooleanOps()
          Test simple operations with Booleans
 void testCharacterOps()
          Test character operations.
 void testConstants()
          Make sure interpreting simple constants works.
 void testDeclareVoidMethod()
          Tests that declaring a void method in the Interactions Pane won't cause a bad type exception.
 void testDoubleOps()
          Test double operations.
private  void tester(Pair<String,Object>[] cases)
          Asserts that the results of interpreting the first of each Pair is equal to the second.
 void testEvaluationVisitorExtensionNO_RESULT()
          Test the operation of the EvaluationVisitorExtension by performing a computation with no results (interpreter should return NO_RESULT and not null)
 void testIncompatibleAssignment()
          Ensure that the interpreter rejects assignments where the right type is not a subclass of the left type.
 void testInitializeArrays()
          Test that arrays initializers are accepted.
 void testIntegerOps()
          Tests integer operations.
 void testNullInstanceOf()
          Tests that null can be used in instanceof expressions.
 void testSemicolon()
          Tests that String and character declarations do not return a result, while the variables themselves return a quoted result.
 void testShortCircuit()
          Tests short circuiting
 void testStringOps()
          Test string operations
 void testThrowNull()
          Test throwing null, for bug 3008828.
 void testTypeCheckerExtension()
          Test the operation of the TypeCheckerExtension by performing the operations ((false) ? 2/0 : 1) and ((false) ? 2%0 : 1), which should not throw Exceptions in the Java interpreter.
 void testUserDefinedVoidMethod()
          Tests that a call to user-defined void method returns NO_RESULT, instead of null.
 void testVariableDefaultValues()
          Tests that variables are assigned default values.
 void testVariableDefinition()
          Tests simple variable definitions which broke the initial implementation of variable redefinition (tested by testVariableRedefinition).
 void testVariableRedefinition()
          Tests that variable declarations with errors will not allow the interpreter to not define the variable.
 
Methods inherited from class edu.rice.cs.drjava.DrJavaTestCase
setConfigSetting, setDocText, tearDown
 
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

_interpreterOptions

private volatile InteractionsPaneOptions _interpreterOptions

_interpreter

private volatile Interpreter _interpreter

_classPathManager

private volatile ClassPathManager _classPathManager

_interpreterLoader

private volatile ClassLoader _interpreterLoader

testValue

public static boolean testValue
Constructor Detail

JavaInterpreterTest

public JavaInterpreterTest()
Method Detail

setUp

protected void setUp()
              throws Exception
The setup method run before each test.

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

tester

private void tester(Pair<String,Object>[] cases)
             throws InterpreterException
Asserts that the results of interpreting the first of each Pair is equal to the second.

Parameters:
cases - an array of Pairs
Throws:
InterpreterException

interpret

private Object interpret(String s)
                  throws InterpreterException
Throws:
InterpreterException

testConstants

public void testConstants()
                   throws InterpreterException
Make sure interpreting simple constants works. Note that strings and characters are quoted.

Throws:
InterpreterException

testBooleanOps

public void testBooleanOps()
                    throws InterpreterException
Test simple operations with Booleans

Throws:
InterpreterException

testShortCircuit

public void testShortCircuit()
                      throws InterpreterException
Tests short circuiting

Throws:
InterpreterException

testIntegerOps

public void testIntegerOps()
                    throws InterpreterException
Tests integer operations.

Throws:
InterpreterException

testDoubleOps

public void testDoubleOps()
                   throws InterpreterException
Test double operations.

Throws:
InterpreterException

testStringOps

public void testStringOps()
                   throws InterpreterException
Test string operations

Throws:
InterpreterException

testCharacterOps

public void testCharacterOps()
                      throws InterpreterException
Test character operations.

Throws:
InterpreterException

testSemicolon

public void testSemicolon()
                   throws InterpreterException
Tests that String and character declarations do not return a result, while the variables themselves return a quoted result.

Throws:
InterpreterException

testNullInstanceOf

public void testNullInstanceOf()
                        throws InterpreterException
Tests that null can be used in instanceof expressions.

Throws:
InterpreterException

testVariableDefinition

public void testVariableDefinition()
                            throws InterpreterException
Tests simple variable definitions which broke the initial implementation of variable redefinition (tested by testVariableRedefinition).

Throws:
InterpreterException

testVariableDefaultValues

public void testVariableDefaultValues()
                               throws InterpreterException
Tests that variables are assigned default values.

Throws:
InterpreterException

testVariableRedefinition

public void testVariableRedefinition()
                              throws InterpreterException
Tests that variable declarations with errors will not allow the interpreter to not define the variable. This will get rid of annoying "Error: Redefinition of 'variable'" messages after fixing the error. Note that if the error occurs during the evaluation of the right hand side then the variable is defined. This is for two reasons: The compiler would have accepted this variable declaration so that no more variables could have been defined with the same name afterwards, and we don't know how to make sure the evaluation doesn't return errors without actually evaluating which may have side-effects.

Throws:
InterpreterException

testIncompatibleAssignment

public void testIncompatibleAssignment()
                                throws InterpreterException
Ensure that the interpreter rejects assignments where the right type is not a subclass of the left type.

Throws:
InterpreterException

testTypeCheckerExtension

public void testTypeCheckerExtension()
Test the operation of the TypeCheckerExtension by performing the operations ((false) ? 2/0 : 1) and ((false) ? 2%0 : 1), which should not throw Exceptions in the Java interpreter.


testEvaluationVisitorExtensionNO_RESULT

public void testEvaluationVisitorExtensionNO_RESULT()
Test the operation of the EvaluationVisitorExtension by performing a computation with no results (interpreter should return NO_RESULT and not null)


testInitializeArrays

public void testInitializeArrays()
                          throws InterpreterException
Test that arrays initializers are accepted.

Throws:
InterpreterException

testArrayCloning

public void testArrayCloning()
                      throws InterpreterException
Test that array cloning works.

Throws:
InterpreterException

testDeclareVoidMethod

public void testDeclareVoidMethod()
Tests that declaring a void method in the Interactions Pane won't cause a bad type exception. Tests bug #915906 "Methods in Interactions no longer work".


testUserDefinedVoidMethod

public void testUserDefinedVoidMethod()
                               throws InterpreterException
Tests that a call to user-defined void method returns NO_RESULT, instead of null. This test does not pass, it is currently broken.

Throws:
InterpreterException

testThrowNull

public void testThrowNull()
                   throws InterpreterException
Test throwing null, for bug 3008828.

Throws:
InterpreterException