Fixes / improvements in testcase generatoris, update to new API.
--- a/CustomCodeGeneratorOrRefactoringTestCaseCodeGenerator.st Tue Sep 16 11:09:25 2014 +0100
+++ b/CustomCodeGeneratorOrRefactoringTestCaseCodeGenerator.st Tue Sep 16 11:11:21 2014 +0100
@@ -36,12 +36,32 @@
"Modified: / 22-08-2014 / 18:50:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!CustomCodeGeneratorOrRefactoringTestCaseCodeGenerator methodsFor:'executing'!
+!CustomCodeGeneratorOrRefactoringTestCaseCodeGenerator class methodsFor:'queries'!
+
+availableInContext:aCustomContext
+ | classes |
+
+ classes := aCustomContext selectedClasses.
+ ^ classes notEmpty
+ and:[ classes allSatisfy: [:e | e inheritsFrom: CustomCodeGeneratorOrRefactoring ] ].
+
+ "Created: / 15-09-2014 / 15:19:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
-buildForClass: aClass testClass: aTestClass
+!CustomCodeGeneratorOrRefactoringTestCaseCodeGenerator methodsFor:'accessing - defaults'!
+
+defaultTestSuperName
+ ^ 'CustomCodeGeneratorOrRefactoringTestCase'
+
+ "Created: / 16-09-2014 / 10:32:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CustomCodeGeneratorOrRefactoringTestCaseCodeGenerator methodsFor:'executing - private'!
+
+generateTestCaseCodeFor:aTestClass forClassUnderTest:aClass
| source className |
- aTestClass superclassName: 'CustomCodeGeneratorOrRefactoringTestCase'.
+ super generateTestCaseCodeFor:aTestClass forClassUnderTest:aClass.
className := aClass theNonMetaClass name.
source := 'test_code_generated
@@ -66,8 +86,7 @@
replace: '`className' with: className asString;
createMethod
- "Created: / 13-06-2014 / 09:27:15 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
- "Modified: / 23-08-2014 / 19:56:09 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ "Created: / 16-09-2014 / 10:40:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CustomCodeGeneratorOrRefactoringTestCaseCodeGenerator class methodsFor:'documentation'!
--- a/CustomIsAbstractCodeGenerator.st Tue Sep 16 11:09:25 2014 +0100
+++ b/CustomIsAbstractCodeGenerator.st Tue Sep 16 11:11:21 2014 +0100
@@ -54,7 +54,7 @@
!CustomIsAbstractCodeGenerator methodsFor:'executing'!
-executeInContext:aCustomContext
+buildInContext:aCustomContext
"Generates the code or perform the refactoring. This method
is guaranteed to be called only if #availableInContext: returns
true.
@@ -71,7 +71,6 @@
].
]
- "Created: / 20-03-2014 / 01:38:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (comment): / 31-03-2014 / 23:26:25 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ "Created: / 16-09-2014 / 07:20:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
--- a/CustomSimpleTestCaseCodeGenerator.st Tue Sep 16 11:09:25 2014 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-"{ Package: 'jn:refactoring_custom' }"
-
-CustomTestCaseCodeGenerator subclass:#CustomSimpleTestCaseCodeGenerator
- instanceVariableNames:''
- classVariableNames:''
- poolDictionaries:''
- category:'Interface-Refactoring-Custom-Generators'
-!
-
-!CustomSimpleTestCaseCodeGenerator class methodsFor:'accessing-presentation'!
-
-description
- ^ 'Generates TestCase subclass for selected classes'
-
- "Modified: / 27-04-2014 / 11:03:05 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
-!
-
-label
- ^ 'TestCase class'
-
- "Modified: / 27-04-2014 / 10:46:01 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
-! !
-
-!CustomSimpleTestCaseCodeGenerator methodsFor:'executing'!
-
-buildForClass: aClass testClass: aTestClass
-
- codeBuilder
- class: aTestClass;
-
- protocol: 'tests';
- source: ('test_something
- self assert: ''a'' = ''b''');
- createMethod;
-
- protocol: 'initialization & release';
- source: ('setUp
- ^ self');
- createMethod;
-
- source: ('tearDown
- ^ self');
- createMethod
-
- "Created: / 13-06-2014 / 09:28:04 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
-! !
-
--- a/CustomTestCaseCodeGenerator.st Tue Sep 16 11:09:25 2014 +0100
+++ b/CustomTestCaseCodeGenerator.st Tue Sep 16 11:11:21 2014 +0100
@@ -1,7 +1,8 @@
"{ Package: 'jn:refactoring_custom' }"
CustomCodeGenerator subclass:#CustomTestCaseCodeGenerator
- instanceVariableNames:''
+ instanceVariableNames:'testClassName testSuperName testClassCategory generateSetUp
+ generateTearDown'
classVariableNames:''
poolDictionaries:''
category:'Interface-Refactoring-Custom-Generators'
@@ -26,7 +27,12 @@
!CustomTestCaseCodeGenerator class methodsFor:'queries'!
availableInContext:aCustomContext
- ^aCustomContext selectedClasses notEmptyOrNil
+ | classes |
+
+ classes := aCustomContext selectedClasses.
+ ^ classes isEmptyOrNil or:[ classes noneSatisfy: [:cls | cls inheritsFrom: TestCase ] ].
+
+ "Modified: / 15-09-2014 / 18:23:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
availableInPerspective:aCustomPerspective
@@ -39,41 +45,167 @@
^ self == CustomTestCaseCodeGenerator
! !
-!CustomTestCaseCodeGenerator methodsFor:'executing'!
+!CustomTestCaseCodeGenerator methodsFor:'accessing'!
+
+generateSetUp
+ ^ generateSetUp
+!
+
+generateSetUp:aBoolean
+ generateSetUp := aBoolean.
+!
+
+generateTearDown
+ ^ generateTearDown
+!
-buildForClass: aClass testClass: aTestClass
- "Here should be building methods for testclass, altering test class..."
+generateTearDown:aBoolean
+ generateTearDown := aBoolean.
+!
+
+testClassCategory
+ ^ testClassCategory
+!
+
+testClassCategory:aString
+ testClassCategory := aString.
+!
+
+testClassName
+ ^ testClassName
+!
- self subclassResponsibility
+testClassName:aString
+ testClassName := aString.
+!
+
+testSuperName
+ ^ testSuperName
+!
+
+testSuperName:aString
+ testSuperName := aString.
+! !
+
+!CustomTestCaseCodeGenerator methodsFor:'accessing - defaults'!
+
+defaultGenerateSetUp
+ "raise an error: this method should be implemented (TODO)"
- "Created: / 13-06-2014 / 09:28:17 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ ^ self shouldImplement
+
+ "Created: / 16-09-2014 / 10:27:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+defaultGenerateTearDown
+ "raise an error: this method should be implemented (TODO)"
+
+ ^ self shouldImplement
+
+ "Created: / 16-09-2014 / 10:27:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+defaultTestSuperName
+ ^ 'TestCase'
+! !
+
+!CustomTestCaseCodeGenerator methodsFor:'executing - private'!
+
buildInContext:aCustomContext
-
- aCustomContext selectedClasses do: [ :class |
- | className testClassName |
+ | classes |
- className := class theNonMetaClass name.
-
- (className endsWith: 'Tests') ifFalse: [
- | testClass |
-
- testClassName := className, 'Tests'.
+ classes := aCustomContext selectedClasses.
+ classes notEmptyOrNil ifTrue: [
+ classes do: [:cls |
+ | name |
- codeBuilder package: class package.
-
- testClass := codeBuilder createClass.
- testClass
- className: testClassName;
- superclassName: 'TestCase';
- category: (self testCategory: class category).
-
- self buildForClass: class testClass: testClass
+ name := cls theNonMetaClass name , 'Tests'.
+ self generateTestCaseNamed:name forClassUnderTest: cls theNonMetaclass
]
- ]
+ ] ifFalse:[
+ self generateTestCaseNamed:testClassName forClassUnderTest: (classes size == 1 ifTrue:[classes anElement theNonMetaclass] ifFalse:[nil]) .
+ ].
"Modified: / 30-08-2014 / 22:15:46 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ "Modified: / 16-09-2014 / 10:30:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+configureInContext:aCustomContext
+ | classes |
+
+ classes := aCustomContext selectedClasses.
+ testSuperName := self defaultTestSuperName.
+ classes size == 0 ifTrue:[
+ testClassName := 'NewTestCase'.
+ testClassCategory := 'Some Tests'
+ ] ifFalse:[
+ classes size == 1 ifTrue:[
+ testClassName := classes anElement name , 'Tests'.
+ testClassCategory := classes anElement category , '-Tests'.
+ ] ifFalse:[
+ testClassCategory := 'Some Tests'.
+ ].
+ ].
+ generateSetUp := self defaultGenerateSetUp.
+ generateTearDown := self defaultGenerateTearDown.
+
+ "/ Now open the dialog...
+
+ classes isEmptyOrNil ifTrue:[
+ dialog
+ addClassNameEntryOn:((AspectAdaptor forAspect:#testClassName)
+ subject:self)
+ labeled:'Class'
+ validateBy:nil.
+ ].
+ dialog
+ addClassNameEntryOn:((AspectAdaptor forAspect:#testSuperName)
+ subject:self)
+ labeled:'Superclass'
+ validateBy:nil.
+ dialog
+ addClassCategoryEntryOn:((AspectAdaptor forAspect:#testCategoryName)
+ subject:self)
+ labeled:'Category'
+ validateBy:nil.
+ dialog addSeparator.
+ dialog
+ addCheckBoxOn:((AspectAdaptor forAspect:#generateSetUp) subject:self)
+ labeled:'Generate #setUp'.
+ dialog
+ addCheckBoxOn:((AspectAdaptor forAspect:#generateTearDown) subject:self)
+ labeled:'Generate #tearDown'.
+ dialog addButtons.
+ dialog open.
+
+ "Created: / 16-09-2014 / 09:39:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+generateTestCaseCodeFor:testCase forClassUnderTest:anObject
+ | subcontext |
+
+ subcontext := CustomSubContext new.
+ subcontext selectedClasses:(Array with:testCase).
+ generateSetUp ifTrue:[
+ (CustomTestCaseSetUpCodeGenerator subGeneratorOf:self)
+ buildInContext:subcontext.
+ ].
+ generateTearDown ifTrue:[
+ (CustomTestCaseTearDownCodeGenerator subGeneratorOf:self)
+ buildInContext:subcontext.
+ ].
+!
+
+generateTestCaseNamed:testCaseClassName forClassUnderTest:classUnderTest
+ | testCase |
+
+ (testCase := codeBuilder createClass)
+ superclassName:testSuperName;
+ className:testClassName;
+ category:testClassCategory.
+ self generateTestCaseCodeFor:testCase forClassUnderTest:classUnderTest
+
+ "Created: / 16-09-2014 / 10:28:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CustomTestCaseCodeGenerator methodsFor:'protected'!
--- a/CustomTestCaseMethodCodeGenerator.st Tue Sep 16 11:09:25 2014 +0100
+++ b/CustomTestCaseMethodCodeGenerator.st Tue Sep 16 11:11:21 2014 +0100
@@ -18,6 +18,19 @@
"Created: / 24-08-2014 / 16:16:09 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
!
+group
+ "Returns a collection strings describing a group to which
+ receiver belongs. A groups may be nested hence the array of
+ strings. For example for subgroup 'Accessors' in group 'Generators'
+ this method should return #('Generators' 'Accessors')."
+
+ "/ By default return an empty array which means the item will appear
+ "/ in top-level group.
+ ^ #('Testing')
+
+ "Created: / 05-08-2014 / 14:14:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
label
"Returns show label describing the receiver. This label
is used in UI as menu item/tree item label."
--- a/CustomTestCaseSetUpCodeGenerator.st Tue Sep 16 11:09:25 2014 +0100
+++ b/CustomTestCaseSetUpCodeGenerator.st Tue Sep 16 11:11:21 2014 +0100
@@ -59,7 +59,7 @@
superHasSetup := current includesSelector: #setUp.
current := current superclass.
].
- (superHasSetup and:[ current name ~~ #TestCase ]) ifTrue:[
+ superHasSetup ifTrue:[
source := 'setUp
super setUp.
@@ -68,6 +68,8 @@
category := (current compiledMethodAt: #setUp) category.
] ifFalse:[
source := 'setUp
+ "/ super setUp.
+
"Add your own code here..."
'.
category := (TestCase compiledMethodAt: #setUp) category.
@@ -79,6 +81,7 @@
category: category.
"Created: / 05-08-2014 / 14:17:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 15-09-2014 / 15:13:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
buildInContext:aCustomContext
--- a/CustomTestCaseTearDownCodeGenerator.st Tue Sep 16 11:09:25 2014 +0100
+++ b/CustomTestCaseTearDownCodeGenerator.st Tue Sep 16 11:11:21 2014 +0100
@@ -59,7 +59,7 @@
superHasSetup := current includesSelector: #tearDown.
current := current superclass.
].
- (superHasSetup and:[ current name ~~ #TestCase ]) ifTrue:[
+ superHasSetup ifTrue:[
source := 'tearDown
"Add your own code here..."
@@ -69,6 +69,8 @@
] ifFalse:[
source := 'tearDown
"Add your own code here..."
+
+ "/ super tearDown.
'.
category := (TestCase compiledMethodAt: #tearDown ) category.
].
@@ -79,6 +81,7 @@
category: category.
"Created: / 05-08-2014 / 14:17:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 15-09-2014 / 15:13:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
buildInContext:aCustomContext
--- a/jn_refactoring_custom.st Tue Sep 16 11:09:25 2014 +0100
+++ b/jn_refactoring_custom.st Tue Sep 16 11:11:21 2014 +0100
@@ -48,6 +48,8 @@
#'stx:goodies/refactoryBrowser/helpers' "RBNamespace - referenced by CustomSourceCodeBuilder::Class>>asRBClass"
#'stx:libbasic3' "Change - referenced by CustomCodeGeneratorOrRefactoringTestCase>>assertSource:sameAs:"
#'stx:libview' "WindowGroup - referenced by CustomCodeGeneratorOrRefactoring>>executeInContextWithWaitCursor:"
+ #'stx:libwidg' "DialogBox - referenced by CustomUserDialog>>initialize"
+ #'stx:libwidg2' "CheckBox - referenced by CustomDialog>>addCheckBoxOn:labeled:"
)
!
@@ -153,7 +155,6 @@
CustomSimpleAccessMethodsCodeGenerator
CustomSimpleGetterMethodsCodeGenerator
CustomSimpleSetterMethodsCodeGenerator
- CustomSimpleTestCaseCodeGenerator
CustomValueHolderAccessMethodsCodeGenerator
CustomValueHolderGetterMethodsCodeGenerator
CustomValueHolderWithChangeNotificationAccessMethodsCodeGenerator
--- a/refactoring_custom.rc Tue Sep 16 11:09:25 2014 +0100
+++ b/refactoring_custom.rc Tue Sep 16 11:11:21 2014 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.4.0\0"
- VALUE "ProductDate", "Tue, 16 Sep 2014 10:04:46 GMT\0"
+ VALUE "ProductDate", "Tue, 16 Sep 2014 10:10:02 GMT\0"
END
END