JUnitTestCaseProxy.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 16 Jan 2013 21:31:50 +0000
branchrefactoring-vmdata
changeset 1973 617e6a088dd1
parent 1953 1e42ad3fc322
child 2050 c77d58b7076b
permissions -rw-r--r--
- JavaListInspectorView class: JavaListInspectorView - JavaFormalParameterNode class: JavaFormalParameterNode - JavaTypeNode class: JavaTypeNode - JavaScanner class: JavaScanner - JavaArrayTypeNode class: JavaArrayTypeNode - JavaParser class: JavaParser - JavaCommentNode class: JavaCommentNode - JavaIntTypeNode class: JavaIntTypeNode - JavaParseNodeBuilder class: JavaParseNodeBuilder - JavaMethodDeclaratorNode class: JavaMethodDeclaratorNode - JavaScannerBase class: JavaScannerBase - JavaFloatTypeNode class: JavaFloatTypeNode - JavaDocNode class: JavaDocNode - JavaClassOrInterfaceTypeNode class: JavaClassOrInterfaceTypeNode - stx_libjava_tools class: stx_libjava_tools - JavaSettingsApplication class: JavaSettingsApplication - JavaLongTypeNode class: JavaLongTypeNode - JavaParserII class: JavaParserII - JavaSourceReference class: JavaSourceReference - JavaCharTypeNode class: JavaCharTypeNode - JavaParser_Eclipse class: JavaParser_Eclipse - JavaSyntaxHighlighter class: JavaSyntaxHighlighter - JavaMethodNode class: JavaMethodNode - JavaBooleanTypeNode class: JavaBooleanTypeNode - JavaDoubleTypeNode class: JavaDoubleTypeNode - JavaSetInspectorView class: JavaSetInspectorView - JavaParseNode class: JavaParseNode - JavaVoidTypeNode class: JavaVoidTypeNode - JavaMapInspectorView class: JavaMapInspectorView - JavaParserI class: JavaParserI - extensions ...

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010
"
"{ Package: 'stx:libjava' }"

JavaTestCaseProxy subclass:#JUnitTestCaseProxy
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Tests-Proxies'
!

!JUnitTestCaseProxy class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
! !

!JUnitTestCaseProxy class methodsFor:'initialization'!

initialize

    TestCases := Dictionary new.

    "Created: / 01-03-2011 / 10:43:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JUnitTestCaseProxy class methodsFor:'accessing'!

lookupHierarchyRoot

    ^JUnitTestCaseProxy

    "Created: / 01-03-2011 / 11:41:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-03-2011 / 14:54:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JUnitTestCaseProxy class methodsFor:'private'!

isTestSelector: selector
    | javaClass |

    self == JUnitTestCaseProxy ifTrue:[ ^ #() ].
    javaClass := self javaClass.
    (javaClass includesBehavior:(JavaVM classForName:'junit.framework.TestCase')) 
        ifTrue:[ ^ selector startsWith:'test' ].

    self testSelectors includes: selector.
    "
        (JUnitTestCase for: JAVA::stx::libjava::tests::junit::JUnit3Tests)
            testSelectors"

    "Created: / 17-04-2012 / 22:48:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testSelectors
    | javaClass |

    self == JUnitTestCaseProxy ifTrue:[ ^ #() ].
    javaClass := self javaClass.
    (javaClass includesBehavior:(JavaVM classForName:'junit.framework.TestCase')) 
        ifTrue:[ ^ javaClass selectors select:[:sel | sel startsWith:'test' ]. ].

    ^ (javaClass 
        selectMethodsAnnotatedWith:(JavaVM classForName:'org.junit.Test') typeName) 
            collect:[:method | method selector ]

    "
        (JUnitTestCase for: JAVA::stx::libjava::tests::junit::JUnit3Tests)
            testSelectors"

    "Created: / 01-03-2011 / 10:49:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-03-2011 / 00:34:39 / Marcel Hlopko <hlopik@gmail.com>"
    "Modified: / 04-03-2011 / 00:05:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JUnitTestCaseProxy class methodsFor:'subclass creation'!

for:javaClass 
    "Answers a new (anonymous) testcase proxy for
     given javaClass"

    self assert:javaClass isJavaClass description:'Not a java class'.
    self assert:javaClass isTestCaseLike
        description:'Not a testcase-like class'.    
    ^self forClassNamed: javaClass name

    "Created: / 01-03-2011 / 10:30:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-03-2011 / 00:20:49 / Marcel Hlopko <hlopik@gmail.com>"
    "Modified: / 21-06-2011 / 17:08:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JUnitTestCaseProxy methodsFor:'accessing'!

nameForHDTestReport

    ^self class javaClassName copyReplaceAll:$/ with: $.

    "Created: / 01-04-2011 / 16:10:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"

!

selectorForHDTestReport

	^testSelector upTo:$(

!

shouldSkip
    "Returns true, if this testcase should be skipped when a testsuite is run.
     This inly a hint, a test runner is not obliged to respect return value.

     Currently, the only user is stx/goodies/builder/reports"

    | method |
    method := self javaClass lookupMethodFor: testSelector.
    ^method notNil and:[(method annotations runtimeVisible includesKey: 'Lorg/junit/Ignore;')].

    "Created: / 03-12-2012 / 22:02:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JUnitTestCaseProxy methodsFor:'private'!

performTest

    <resource: #skipInDebuggersWalkBack>

    | assertions |

    assertions := SignalSet 
                    with: (Java classForName:'java.lang.AssertionError')
                    with: (Java classForName:'junit.framework.AssertionFailedError').
    [
        self javaClass new perform: testSelector sunitAsSymbol
    ] on: assertions do: [:ex|
        "This is the tricky part. We have to auto-magically convert
         jUnit's AssertionFailedError to sUnits TestFailure's"
        TestResult failure sunitSignalWith: ex getMessage
    ]

    "Created: / 01-03-2011 / 14:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 30-11-2012 / 09:59:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JUnitTestCaseProxy class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '§Id§'
! !

JUnitTestCaseProxy initialize!