Skip to content

Commit bc2ff71

Browse files
author
evlich
committed
Added tests for some of the functions in koala.dynamicjava.tree.*Literal, mainly the decoding functions
git-svn-id: file:///tmp/test-svn/trunk@2868 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 52e75c0 commit bc2ff71

File tree

3 files changed

+67
-13
lines changed

3 files changed

+67
-13
lines changed

dynamicjava/src/koala/Version.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* This file is copied to Version.java by the build process, which also
5454
* fills in the right values of the date and time.
5555
*
56-
* This javadoc corresponds to build drjava-20050205-0300;
56+
* This javadoc corresponds to build drjava-20050206-0349;
5757
*
5858
* @version $Id$
5959
*/
@@ -62,7 +62,7 @@ public abstract class Version {
6262
* This string will be automatically expanded upon "ant commit".
6363
* Do not edit it by hand!
6464
*/
65-
private static final String BUILD_TIME_STRING = "20050205-0300";
65+
private static final String BUILD_TIME_STRING = "20050206-0349";
6666

6767
/** A {@link Date} version of the build time. */
6868
private static final Date BUILD_TIME = _getBuildDate();

dynamicjava/src/koala/dynamicjava/interpreter/TypeCheckerTest.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ public void testVisitWhileStatement() throws InterpreterException {
256256
assertEquals("Should have autounboxed", expected, actual);
257257

258258
_interpretText(text);
259+
260+
text = "while (new Character('a')) { }";
261+
stmt = _parseCode(text).get(0);
262+
263+
try {
264+
stmt.acceptVisitor(_typeChecker);
265+
fail("shouldn't allow while statement with character");
266+
}
267+
catch (ExecutionError e) {
268+
//Test Passed
269+
}
270+
259271
}
260272

261273
/**
@@ -272,6 +284,17 @@ public void testVisitDoStatement() throws InterpreterException {
272284
assertEquals("Should have autounboxed", expected, actual);
273285

274286
_interpretText(text);
287+
288+
text = "do { } while( 'a' );";
289+
stmt = _parseCode(text).get(0);
290+
try {
291+
stmt.acceptVisitor(_typeChecker);
292+
fail("shouldn't accept integer for boolean expression");
293+
}
294+
catch (ExecutionError e) {
295+
//Test Passed
296+
}
297+
275298
}
276299

277300
/**
@@ -290,6 +313,16 @@ public void testVisitForStatement() throws InterpreterException {
290313
assertEquals("Should have autounboxed", expected, actual);
291314

292315
_interpretText(text);
316+
317+
text = "for(; new Integer(5););";
318+
stmt = _parseCode(text).get(0);
319+
try {
320+
stmt.acceptVisitor(_typeChecker);
321+
fail("shouldn't accept integer for boolean expression");
322+
}
323+
catch (ExecutionError e) {
324+
//Test Passed
325+
}
293326
}
294327

295328
/**
@@ -547,7 +580,20 @@ public void testLabeledStatement() {
547580
assertEquals("should yield label statement", expected, actual);
548581
stmt.acceptVisitor(_typeChecker);
549582
}
550-
*/
583+
*/
584+
585+
public void testSynchronizedStatement() {
586+
String text = "synchronized (Integer.class) { }";
587+
SynchronizedStatement stmt = (SynchronizedStatement)_parseCode(text).get(0);
588+
589+
String expected = "(koala.dynamicjava.tree.BlockStatement: [])";
590+
String actual = stmt.getBody().toString();
591+
assertEquals("body of synchronized should be empty", expected, actual);
592+
expected = "(koala.dynamicjava.tree.TypeExpression: (koala.dynamicjava.tree.ReferenceType: Integer))";
593+
actual = stmt.getLock().toString();
594+
assertEquals("should be locking on Class object", expected, actual);
595+
}
596+
551597
public void testIfThenStatement() throws InterpreterException {
552598
String text = "if (B) { }";
553599
IfThenStatement stmt = (IfThenStatement) _parseCode(text).get(0);

dynamicjava/src/koala/dynamicjava/util/FileFinderTest.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,41 @@ public class FileFinderTest extends TestCase
5858

5959
public FileFinderTest(){}
6060

61-
public void testFindFile()
62-
{
61+
public void testFindFile() {
6362
File thisFile;
6463
File noFile;
6564

6665
//When running the ant script for testing this is the relative path to the directory that contains this file
6766
ff.addPath("dynamicjava/util/");
6867

6968
//Try to find a file that does exist, namely this current file
70-
try
71-
{
69+
try {
7270
thisFile = ff.findFile("FileFinderTest.java");
7371
assertTrue("Found This File", thisFile != null);
7472
}
75-
catch(IOException ioe)
76-
{
73+
catch(IOException ioe) {
7774
fail();
7875
}
7976

77+
//When running the ant script for testing this is the relative path to the directory that contains this file
78+
ff.addPath("dynamicjava/interpreter");
79+
80+
//Try to find a file that does exist, namely this current file
81+
try {
82+
thisFile = ff.findFile("Interpreter.java");
83+
assertTrue("Found This File", thisFile != null);
84+
}
85+
catch(IOException ioe) {
86+
fail();
87+
}
88+
89+
8090
//Try to find a file that does not exist
81-
try
82-
{
91+
try {
8392
noFile = ff.findFile("file.doesnotexist");
8493
fail();
8594
}
86-
catch(IOException fnf)
87-
{
95+
catch(IOException fnf) {
8896
assertEquals("File Not Found", "File Not Found: file.doesnotexist", fnf.getMessage());
8997
}
9098
}

0 commit comments

Comments
 (0)