From: Chris Koeritz Date: Sat, 2 Mar 2013 21:21:35 +0000 (-0500) Subject: cleaned up these tests. X-Git-Tag: 2.140.90~1081 X-Git-Url: https://feistymeow.org/gitweb/?p=feisty_meow.git;a=commitdiff_plain;h=f3623730e2de43937aa83a02c01b47fc22ac53a4 cleaned up these tests. --- diff --git a/kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java b/kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java index e722b130..d28857f0 100644 --- a/kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java +++ b/kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java @@ -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."); + } + } } diff --git a/kona/src/test/java/semantics/instance_of.java b/kona/src/test/java/semantics/instance_of.java index 2a5f2b0f..47d2d826 100644 --- a/kona/src/test/java/semantics/instance_of.java +++ b/kona/src/test/java/semantics/instance_of.java @@ -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