refactoring_custom/SmallSense__CustomTestCaseSetUpCodeGeneratorTests.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 14 Jun 2015 09:46:51 +0100
changeset 833 297eb38e4eee
parent 832 SmallSense__CustomTestCaseSetUpCodeGeneratorTests.st@59c248fc74f0
child 943 43d408a5e517
permissions -rw-r--r--
Package jn:refactoring_custom renamed to stx:goodies/smallsense/refactoring_custom

"
A custom code generation and refactoring support for Smalltalk/X
Copyright (C) 2013-2015 Jakub Nesveda
Copyright (C) 2013-now  Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'stx:goodies/smallsense/refactoring_custom' }"

"{ NameSpace: SmallSense }"

CustomCodeGeneratorOrRefactoringTestCase subclass:#CustomTestCaseSetUpCodeGeneratorTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Refactoring-Custom-Generators-Tests'
!

!CustomTestCaseSetUpCodeGeneratorTests class methodsFor:'documentation'!

copyright
"
A custom code generation and refactoring support for Smalltalk/X
Copyright (C) 2013-2015 Jakub Nesveda
Copyright (C) 2013-now  Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
! !

!CustomTestCaseSetUpCodeGeneratorTests methodsFor:'accessing'!

generatorOrRefactoring
    ^ CustomTestCaseSetUpCodeGenerator new
! !

!CustomTestCaseSetUpCodeGeneratorTests methodsFor:'tests'!

test_set_up_method_generated_default_package
    | expectedPackage class actualPackage |

    class := model createClass
        name: #DummyTestCase01;
        superclassName: #TestCase;
        package: #dummy_package01;
        compile;
        yourself. 

    context selectedClasses: {class}.  

    expectedPackage := #dummy_package01.
    generatorOrRefactoring executeInContext: context.
    actualPackage := ((Smalltalk at: #DummyTestCase01) compiledMethodAt: #setUp) package.  
    self assert: expectedPackage = actualPackage

    "Created: / 31-01-2015 / 21:26:09 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
!

test_set_up_method_generated_not_same_package
    | expectedPackage class actualPackage |

    class := model createClass
        name: #DummyTestCase01;
        superclassName: #TestCase;
        package: #dummy_package01;
        compile;
        yourself. 

    context selectedClasses: {class}.  

    expectedPackage := PackageId noProjectID.
    generatorOrRefactoring samePackageAsTestedClass: false.  
    generatorOrRefactoring executeInContext: context.
    actualPackage := ((Smalltalk at: #DummyTestCase01) compiledMethodAt: #setUp) package.  
    self assert: expectedPackage = actualPackage

    "Created: / 31-01-2015 / 21:31:21 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
!

test_set_up_method_generated_same_method_protocol  
    | class expectedCategory actualCategory |

    class := model createClass
        name: #DummyTestCase01;
        superclassName: #TestCase;
        compile;
        yourself. 

    context selectedClasses: {class}.  

    expectedCategory := (Smalltalk::TestCase compiledMethodAt: #setUp) category.
    generatorOrRefactoring executeInContext: context.
    actualCategory := ((Smalltalk at: #DummyTestCase01) compiledMethodAt: #setUp) category.
    self assert: expectedCategory = actualCategory

    "Created: / 31-01-2015 / 21:36:48 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
    "Modified: / 12-06-2015 / 20:46:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_set_up_method_generated_same_package
    | expectedPackage class actualPackage |

    class := model createClass
        name: #DummyTestCase01;
        superclassName: #TestCase;
        package: #dummy_package01;
        compile;
        yourself. 

    context selectedClasses: {class}.  

    expectedPackage := #dummy_package01.
    generatorOrRefactoring samePackageAsTestedClass: true.  
    generatorOrRefactoring executeInContext: context.
    actualPackage := ((Smalltalk at: #DummyTestCase01) compiledMethodAt: #setUp) package.  
    self assert: expectedPackage = actualPackage

    "Created: / 31-01-2015 / 21:30:22 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
!

test_set_up_method_generated_set_up_implemented
    | expectedSource class |

    class := model createClass
        name: #DummyTestCase01;
        superclassName: #TestCase;
        compile;
        yourself. 

    context selectedClasses: {class}.  

    expectedSource := 'setUp
    super setUp.

    "Add your own code here..."'.
    generatorOrRefactoring executeInContext: context.  
    self assertMethodSource: expectedSource atSelector: #setUp forClass: class

    "Created: / 31-01-2015 / 20:30:22 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
!

test_set_up_method_generated_set_up_not_implemented
    | expectedSource class |

    class := model createClass
        name: #DummyTestCase01;
        compile;
        yourself.

    context selectedClasses: {class}.  

    expectedSource := 'setUp
    "/ super setUp.
    "Add your own code here..."'.
    generatorOrRefactoring buildForClass: class.  
    self assertMethodSource: expectedSource atSelector: #setUp forClass: class

    "Created: / 31-01-2015 / 20:30:55 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
! !