cleaned up these tests.
authorChris Koeritz <fred@gruntose.com>
Sat, 2 Mar 2013 21:21:35 +0000 (16:21 -0500)
committerChris Koeritz <fred@gruntose.com>
Sat, 2 Mar 2013 21:21:35 +0000 (16:21 -0500)
kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java
kona/src/test/java/semantics/instance_of.java

index e722b130e06fbc58a7ca69b296ce40d205625923..d28857f010d83042a5e4e1caab812005cfd2c282 100644 (file)
@@ -2,51 +2,58 @@ package test.java.semantics;
 
 import java.io.FileNotFoundException;
 
-class finally_behavior_test
+//hmmm: convert this to simple unit test.
+public class behavior_of_finally_when_exception_in_catch
 {
-    int calibrador = 17;
+       private int calibrador = 17;
 
-    public finally_behavior_test()
-    {
-    }
+       private boolean ranRight = false;
 
-    public int funkyTown() throws FileNotFoundException
-    {
-        if (calibrador < 3) {
-            // we should never get here.  it should always raise an exception.
-            System.out.println("where did you put it?");
-        } else {
-            throw new FileNotFoundException("is it larger than a breadbox?");
-        }
-        return 25;
-    }
+       public behavior_of_finally_when_exception_in_catch()
+       {
+       }
 
-    public void runTest() throws Throwable
-    {
-        try {
-            int zooty = funkyTown();
-            System.out.println("zooty is " + zooty + " but how did we get here???");
-        } catch (Throwable cause) {
-            System.out.println("caught exception, now will rethrow.");
-            throw cause;
-        } finally {
-            System.out.println("still got to finally, our assumptions are safe.");
-        }
-    }
+       public int funkyTown() throws FileNotFoundException
+       {
+               if (calibrador < 3) {
+                       // we should never get here. it should always raise an exception.
+                       System.out.println("where did you put it?");
+               } else {
+                       throw new FileNotFoundException("is it larger than a breadbox?");
+               }
+               return 25;
+       }
 
-    public static void main(String s[]) throws Exception
-    {
-        // we are asserting that the finally clause of an exception handler will still
-        // fire when an exception is raised in the catch clause. otherwise, all our
-        // assumptions about being able to use finally properly are thrown out the window.
-        finally_behavior_test tony = new finally_behavior_test();
-        try {
-            tony.runTest();
-        } catch (Throwable cause) {
-            //yawn.
-        }
-        System.out.println("Hey, did the finally clause say it ran above?");
-        System.out.println("If so, great.  If not, we've got problems.");
-    }
+       public void runTest() throws Throwable
+       {
+               try {
+                       int zooty = funkyTown();
+                       System.out.println("zooty is " + zooty + " but how did we get here???");
+               } catch (Throwable cause) {
+                       System.out.println("caught exception, now will rethrow.  so far this is fine.");
+                       throw cause;
+               } finally {
+                       System.out.println("ran finally clause; our assumptions are safe.  we MUST see this line!!");
+                       ranRight = true;
+               }
+       }
 
+       public static void main(String s[]) throws Exception
+       {
+               // we are asserting that the finally clause of an exception handler will still
+               // fire when an exception is raised in the catch clause. otherwise, all our
+               // assumptions about being able to use finally properly are thrown out the window.
+               behavior_of_finally_when_exception_in_catch tony = new behavior_of_finally_when_exception_in_catch();
+               try {
+                       tony.runTest();
+               } catch (Throwable cause) {
+                       // yawn.
+               }
+               System.out.println("the finally clause needs to have run above; otherwise, we've got bad problems.");
+               if (!tony.ranRight) {
+                       System.out.println("FAILURE in assumptions about the finally clause!!!");
+               } else {
+                       System.out.println("okay, cool.  test succeeded.");
+               }
+       }
 }
index 2a5f2b0fb0532d20468e94d6eb83ec3ec4b9822c..47d2d826fb302bda29993097cd9d5685af7b44f3 100644 (file)
@@ -2,25 +2,28 @@ package test.java.semantics;
 
 import java.util.List;
 
+//hmmm: convert this to simple unit test.
 class instance_of
 {
-    public instance_of() {}
-    
-    public Object cogitate() {
-        return null;
-    }
+       public instance_of()
+       {
+       }
 
-    public static void main(String s[]) throws Exception
-    {
-        // we are just asserting that it is safe to do instanceof on an object that is null.
-        // let's test that theory.
-        instance_of tony = new instance_of();
-        Object fred = tony.cogitate();  // will produce null.
-        if (fred instanceof List<?>) {
-            throw new Exception("that should not have happened!");
-        } else {
-            System.out.println("told us null is not an instance of List, which is correct.");
-        }
-        
-    }
+       public Object cogitate()
+       {
+               return null;
+       }
+
+       public static void main(String s[]) throws Exception
+       {
+               // we are just asserting that it is safe to do instanceof on an object that is null.
+               // let's test that theory.
+               instance_of tony = new instance_of();
+               Object fred = tony.cogitate(); // will produce null.
+               if (fred instanceof List<?>) {
+                       throw new Exception("FAILURE!  fred should not be instance of List<?> !  null is an instance of something!");
+               } else {
+                       System.out.println("told us null is not an instance of List, which is correct.");
+               }
+       }
 }
\ No newline at end of file