src/JavaExceptionTests.st
branchjk_new_structure
changeset 1452 69dcb9c33742
parent 1450 4817f2a363d6
child 1455 0bd5fedc1d2c
--- a/src/JavaExceptionTests.st	Tue Apr 03 16:45:03 2012 +0000
+++ b/src/JavaExceptionTests.st	Tue Apr 03 16:50:39 2012 +0000
@@ -21,7 +21,7 @@
 "{ Package: 'stx:libjava' }"
 
 TestCase subclass:#JavaExceptionTests
-	instanceVariableNames:''
+	instanceVariableNames:'signal'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Languages-Java-Tests'
@@ -65,6 +65,64 @@
     "Created: / 30-03-2012 / 13:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+
+!JavaExceptionTests methodsFor:'callbacks'!
+
+call: trhower with: aBoolean
+
+    aBoolean ifTrue:[signal raise].
+
+    "Created: / 03-04-2012 / 17:33:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+throw_me: aBoolean
+
+    aBoolean ifTrue:[signal raise].
+
+    "Created: / 03-04-2012 / 17:31:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaExceptionTests methodsFor:'error handling (interop)'!
+
+doesNotUnderstand:aMessage
+
+    | method  selector class args|
+    selector := aMessage selector.
+    args := aMessage arguments.
+    class := self class.
+
+    JavaLookup isNil ifTrue:[
+        (Smalltalk loadPackage: 'stx:libjava/experiments') ifFalse:[
+            self error: 'You should load package stx:libjava/experiments if you want some interop - still experimental' mayProceed: true.
+            ^nil                        
+        ]        
+    ].
+
+    method := JavaLookup instance lookupMethodForSelector: selector
+                directedTo: class
+                for: self
+                withArguments: args
+                from: thisContext sender sender
+                ilc: nil.
+
+    method isNil ifTrue:[
+        ^super doesNotUnderstand:aMessage
+    ] ifFalse:[
+        ^ method valueWithReceiver: self arguments: args
+    ].
+
+    "Created: / 06-09-2011 / 22:16:26 / Jan Kurs <kursjan@fit.cvut.cz>"
+    "Modified: / 15-12-2011 / 23:42:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaExceptionTests methodsFor:'running'!
+
+setUp
+    signal := Signal new.
+
+    "Created: / 03-04-2012 / 17:30:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaExceptionTests methodsFor:'tests'!
 
 test_01a
@@ -203,6 +261,30 @@
     self assert: thrower token == 3.
 
     "Created: / 03-04-2012 / 15:39:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_04a
+    "
+    Scenario (method activation stack, last called at bottom)
+        1) ST method, handles 'signal'
+        2) Java method with finally
+        3) Smalltak method, throws 'signal'
+    "
+
+    | thrower caught |
+    thrower := JAVA stx libjava tests SimpleExceptionThrower new.
+    [ 
+        thrower test_04: self with: true.
+        caught := false.
+        
+    ] on: signal do: [:ex|
+        caught := true.
+    ].
+
+    self assert: caught == true.
+    self assert: thrower token == 3.
+
+    "Created: / 03-04-2012 / 17:30:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaExceptionTests class methodsFor:'documentation'!