JUnitTestCaseProxy.st
branchdevelopment
changeset 3011 83579e128194
parent 2982 673487527490
child 3012 8a803c26ea93
equal deleted inserted replaced
3010:8b3f1f16a660 3011:83579e128194
   162     "Created: / 03-12-2012 / 22:02:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   162     "Created: / 03-12-2012 / 22:02:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   163 ! !
   163 ! !
   164 
   164 
   165 !JUnitTestCaseProxy methodsFor:'private'!
   165 !JUnitTestCaseProxy methodsFor:'private'!
   166 
   166 
       
   167 handleRaisedException:ex
       
   168    "Some methods are expected to raise an exception, I take care of that. If the exception
       
   169    is not expected, I convert it to something expected by stx tools."    
       
   170 
       
   171     | method |
       
   172     method := self javaClass lookupMethodFor: testSelector.
       
   173     method notNil ifTrue:[
       
   174         |annotation|
       
   175         annotation := (method annotations runtimeVisible at:'Lorg/junit/Test;').
       
   176         (annotation values includesKey: 'expected') ifTrue: [
       
   177             |classNameIndex className expectedExceptionClass|
       
   178             classNameIndex :=  (annotation values at: 'expected') classIndex.
       
   179             className := (self javaClass constantPool at: classNameIndex).
       
   180             expectedExceptionClass := Java classForName: className.
       
   181             (ex equalsOrIsSubclassOf: expectedExceptionClass) ifTrue: [
       
   182                 "this is the expected exception, just continue"
       
   183                 ^ self.
       
   184             ].
       
   185         ].
       
   186     ].
       
   187     TestResult failure sunitSignalWith: ex getMessage.
       
   188 
       
   189     "Created: / 08-02-2014 / 21:31:16 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
       
   190 !
       
   191 
   167 performTest
   192 performTest
   168 
   193 
   169     <resource: #skipInDebuggersWalkBack>
   194     <resource: #skipInDebuggersWalkBack>
   170 
   195 
   171     | assertions |
   196     | assertions |
   172 
   197 
   173     assertions := SignalSet 
   198     assertions := SignalSet 
   174                     with: (Java classForName:'java.lang.AssertionError')
   199                     with: (Java classForName:'java.lang.AssertionError')                    
   175                     with: (Java classForName:'junit.framework.AssertionFailedError')
   200                     with: (Java classForName:'junit.framework.AssertionFailedError')
       
   201                     with: (Java classForName:'java.lang.RuntimeException')
   176                     "/ JavaVM unimplementedNativeMethodSignal is Signal, not exception.
   202                     "/ JavaVM unimplementedNativeMethodSignal is Signal, not exception.
   177                     "/ Therefore it MUST be listed here!!!!!!
   203                     "/ Therefore it MUST be listed here!!!!!!
   178                     with: (JavaVM unimplementedNativeMethodSignal).
   204                     with: (JavaVM unimplementedNativeMethodSignal).
   179     [
   205     [
   180         self javaClass new perform: testSelector sunitAsSymbol
   206         self javaClass new perform: testSelector sunitAsSymbol
   181     ] on: assertions do: [:ex|
   207     ] on: assertions do: [:ex|
   182         "This is the tricky part. We have to auto-magically convert
   208         "This is the tricky part. We have to auto-magically convert
   183          jUnit's AssertionFailedError to sUnits TestFailure's"
   209          jUnit's AssertionFailedError to sUnits TestFailure's"
   184         TestResult failure sunitSignalWith: ex getMessage
   210         self handleRaisedException: ex.
   185     ]
   211     ]
   186 
   212 
   187     "Created: / 01-03-2011 / 14:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   213     "Created: / 01-03-2011 / 14:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   188     "Modified: / 22-01-2014 / 14:40:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   214     "Modified: / 22-01-2014 / 14:40:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   215     "Modified: / 08-02-2014 / 21:31:16 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
   189 ! !
   216 ! !
   190 
   217 
   191 !JUnitTestCaseProxy class methodsFor:'documentation'!
   218 !JUnitTestCaseProxy class methodsFor:'documentation'!
   192 
   219 
   193 version_CVS
   220 version_CVS