JUnitTestCaseProxy.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 16 Dec 2012 21:04:02 +0100
branchdirectory_structure_refactoring
changeset 1899 800c0f76adce
parent 1818 2e5ed72e7dfd
child 1839 9dba543140c3
permissions -rw-r--r--
Closing branch directory_structure_refactoring

"
 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:$(

! !

!JUnitTestCaseProxy methodsFor:'private'!

performTest

    <resource: #skipInDebuggersWalkBack>

    [
        self javaClass new perform: testSelector sunitAsSymbol
    ] on: JavaError do: [:ex|
        "This is the tricky part. We have to auto-magically convert
         jUnit's AssertionFailedError to sUnits TestFailure's"

        "Bad, bad, I know..."
        (ex parameter class name == #'junit/framework/AssertionFailedError')
            ifTrue:
                [ TestResult failure sunitSignalWith: ex description ]
            ifFalse:
                [ ex pass ]
    ]

    "Created: / 01-03-2011 / 14:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-05-2012 / 22:12:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JUnitTestCaseProxy class methodsFor:'documentation'!

version_SVN
    ^ '$Id$'
! !

JUnitTestCaseProxy initialize!