add possibility to generate test case class with same package as tested class in CustomTestCaseCodeGenerator
--- a/CustomTestCaseCodeGenerator.st Thu Nov 13 00:14:52 2014 +0100
+++ b/CustomTestCaseCodeGenerator.st Sat Nov 15 15:45:07 2014 +0100
@@ -2,7 +2,7 @@
CustomCodeGenerator subclass:#CustomTestCaseCodeGenerator
instanceVariableNames:'testClassName testSuperName testClassCategory generateSetUp
- generateTearDown'
+ generateTearDown samePackageAsTestedClass'
classVariableNames:''
poolDictionaries:''
category:'Interface-Refactoring-Custom-Generators'
@@ -72,6 +72,23 @@
generateTearDown := aBoolean.
!
+samePackageAsTestedClass
+ "Returns true when we should assign TestCase class
+ to the same package as tested class."
+
+ ^ samePackageAsTestedClass
+
+ "Created: / 15-11-2014 / 11:54:37 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+samePackageAsTestedClass: aBoolean
+ "see samePackageAsTestedClass"
+
+ samePackageAsTestedClass := aBoolean
+
+ "Created: / 15-11-2014 / 11:56:36 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
testClassCategory
^ testClassCategory
!
@@ -114,6 +131,14 @@
"Created: / 16-09-2014 / 10:27:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+defaultSamePackageAsTestedClass
+ "default value for samePackageAsTestedClass"
+
+ ^ true
+
+ "Created: / 15-11-2014 / 12:21:40 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
defaultSetUpCodeGeneratorClass
^ CustomTestCaseSetUpCodeGenerator
!
@@ -165,6 +190,7 @@
].
generateSetUp := self defaultGenerateSetUp.
generateTearDown := self defaultGenerateTearDown.
+ samePackageAsTestedClass := self defaultSamePackageAsTestedClass.
"/ Now open the dialog...
@@ -193,12 +219,15 @@
dialog
addCheckBoxOn:((AspectAdaptor forAspect:#generateTearDown) subject:self)
labeled:'Generate #tearDown'.
+ dialog
+ addCheckBoxOn:((AspectAdaptor forAspect:#samePackageAsTestedClass) subject:self)
+ labeled:'Same package as tested class'.
dialog addButtons.
dialog open.
"Created: / 16-09-2014 / 09:39:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 16-09-2014 / 11:27:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 16-10-2014 / 22:36:29 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ "Modified: / 15-11-2014 / 12:26:44 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
!
generateTestCaseCodeFor:testCase forClassUnderTest:anObject
@@ -215,13 +244,18 @@
(testCase := model createClass)
superclassName:testSuperName;
name:testClassName asSymbol;
- category:testClassCategory;
- compile.
+ category:testClassCategory.
+
+ self samePackageAsTestedClass ifTrue: [
+ testCase package: classUnderTest package
+ ].
+
+ testCase compile.
self generateTestCaseCodeFor:testCase forClassUnderTest:classUnderTest
"Created: / 16-09-2014 / 10:28:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 10-10-2014 / 23:52:52 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ "Modified: / 15-11-2014 / 15:32:01 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
!
generateTestCaseSetUpCodeFor:testCase
--- a/CustomTestCaseCodeGeneratorTests.st Thu Nov 13 00:14:52 2014 +0100
+++ b/CustomTestCaseCodeGeneratorTests.st Sat Nov 15 15:45:07 2014 +0100
@@ -34,6 +34,57 @@
"Created: / 14-10-2014 / 10:42:20 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
"Modified: / 05-11-2014 / 22:37:00 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+test_test_class_generated_with_package
+ | class testClass |
+
+ class := self classWithInstanceVariable
+ category: 'Some-Category';
+ package: #some_package_01;
+ yourself.
+
+ self assertClassNotExists: class name.
+
+ context selectedClasses: (Array with: class theMetaclass ).
+
+ generatorOrRefactoring
+ configureInContext: context;
+ executeInContext: context.
+
+ self assert: generatorOrRefactoring samePackageAsTestedClass.
+
+ testClass := Smalltalk at: generatorOrRefactoring testClassName asSymbol.
+
+ self assertClassExists: class name.
+ self assert: (testClass package) = #some_package_01.
+
+ "Created: / 15-11-2014 / 15:21:39 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+test_test_class_generated_without_package
+ | class testClass |
+
+ class := self classWithInstanceVariable
+ category: 'Some-Category';
+ package: #some_package_01;
+ yourself.
+
+ self assertClassNotExists: class name.
+
+ context selectedClasses: (Array with: class theMetaclass ).
+
+ generatorOrRefactoring
+ configureInContext: context;
+ samePackageAsTestedClass: false;
+ executeInContext: context.
+
+ testClass := Smalltalk at: generatorOrRefactoring testClassName asSymbol.
+
+ self assertClassExists: class name.
+ self deny: (testClass package) = #some_package_01.
+
+ "Created: / 15-11-2014 / 15:37:59 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
! !
!CustomTestCaseCodeGeneratorTests class methodsFor:'documentation'!
--- a/abbrev.stc Thu Nov 13 00:14:52 2014 +0100
+++ b/abbrev.stc Sat Nov 15 15:45:07 2014 +0100
@@ -50,6 +50,7 @@
CustomCodeGeneratorUserPreferencesTests CustomCodeGeneratorUserPreferencesTests jn:refactoring_custom 'Interface-Refactoring-Custom-Tests' 1
CustomCodeSelectionToResourceTranslationTests CustomCodeSelectionToResourceTranslationTests jn:refactoring_custom 'Interface-Refactoring-Custom-Refactorings-Tests' 1
CustomDefaultGetterMethodsCodeGeneratorTests CustomDefaultGetterMethodsCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
+CustomIsAbstractCodeGeneratorTests CustomIsAbstractCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
CustomLazyInitializationAccessMethodsCodeGeneratorTests CustomLazyInitializationAccessMethodsCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
CustomLazyInitializationGetterMethodsCodeGeneratorTests CustomLazyInitializationGetterMethodsCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
CustomLocalChangeManager CustomLocalChangeManager jn:refactoring_custom 'Interface-Refactoring-Custom' 0
--- a/patches/patches.rc Thu Nov 13 00:14:52 2014 +0100
+++ b/patches/patches.rc Sat Nov 15 15:45:07 2014 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "LibraryName\0"
VALUE "ProductVersion", "6.2.4.1420\0"
- VALUE "ProductDate", "Wed, 12 Nov 2014 23:00:42 GMT\0"
+ VALUE "ProductDate", "Sat, 15 Nov 2014 14:42:58 GMT\0"
END
END
--- a/refactoring_custom.rc Thu Nov 13 00:14:52 2014 +0100
+++ b/refactoring_custom.rc Sat Nov 15 15:45:07 2014 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.4.1420\0"
- VALUE "ProductDate", "Wed, 12 Nov 2014 23:00:39 GMT\0"
+ VALUE "ProductDate", "Sat, 15 Nov 2014 14:42:55 GMT\0"
END
END