# HG changeset patch # User Jakub Nesveda # Date 1423173023 -3600 # Node ID 3925afb63587a94e110565399daf60375f09dfa9 # Parent 0ca40b727a4f4bee62cb3dcf93db072f5eca818f Cleanup - removed unable to fix methods from CustomMock diff -r 0ca40b727a4f -r 3925afb63587 CustomMock.st --- a/CustomMock.st Thu Feb 05 22:42:42 2015 +0100 +++ b/CustomMock.st Thu Feb 05 22:50:23 2015 +0100 @@ -84,14 +84,13 @@ mockClass := Smalltalk classNamed: mockClassName. self createMockMethodWithSingleValue: mockClass. - self createMockMethodWithBlockValue: mockClass. self createMockMethodWithCompileMethod: mockClass. ]. ^ mockClass "Created: / 15-06-2014 / 19:15:52 / Jakub Nesveda " - "Modified: / 24-01-2015 / 19:40:02 / Jakub Nesveda " + "Modified: / 05-02-2015 / 22:46:05 / Jakub Nesveda " ! createMockGetters: aMockClass forSelectors: aSelectors @@ -124,29 +123,6 @@ "Modified: / 24-09-2014 / 21:26:12 / Jakub Nesveda " ! -createMockMethodWithBlockValue: aMockClass - "Generates mock method for given mock class - to support custom method implementation by block value" - - | instVarName classVarName | - - classVarName := self variableNameForClassMockedSelectors. - - self - createMockMethod: aMockClass theMetaclass - methodSource: (self blockValueMethodSource: classVarName) - mockedSelectorsVariableName: classVarName. - - instVarName := self variableNameForInstanceMockedSelectors. - - self - createMockMethod: aMockClass theNonMetaclass - methodSource: (self blockValueMethodSource: instVarName) - mockedSelectorsVariableName: instVarName. - - "Created: / 21-09-2014 / 22:51:39 / Jakub Nesveda " -! - createMockMethodWithCompileMethod: aMockClass "Generates mock method for given mock class to support custom method implementation by given method source" @@ -189,65 +165,6 @@ !CustomMock methodsFor:'code generation - sources'! -blockValueMethodSource: aMockedSelectorsVariableName - "Returns mock method source code for given variable name - which holds mocked selectors and its block values. - These values are so called blocks which contains executable code." - - ^ 'mockSelector: aSelector withBlockValue: aBlock - - | valueMethod mockSelector argNumber | - - self error: ''Do not use this method - makes always test pass!!!!!!''. - - `mockedSelectorsVariableName isNil ifTrue: [ - `mockedSelectorsVariableName := Dictionary new - ]. - - `mockedSelectorsVariableName at: aSelector asSymbol put: aBlock. - Transcript showCR: ''SRC: '', aBlock source. - valueMethod := ''value''. - mockSelector := ''''. - argNumber := 0. - (aSelector asString subStrings: $:) do: [ :param | - | argName | - - argName := ''arg'', argNumber asString. - - (argNumber > 0) ifTrue: [ - mockSelector := mockSelector, '':'', argName, '' '', param. - - (argNumber > 1) ifTrue: [ - valueMethod := valueMethod, '' value:'', argName. - ] - ifFalse: [ - valueMethod := valueMethod, '':'', argName. - ]. - ] - ifFalse: [ - mockSelector := param. - ]. - - valueMethod := valueMethod. - argNumber := argNumber + 1. - ]. - - (CodeGenerator new - class: self class; - protocol: ''mocks''; - source: (''`@selector - - ^ (`mockedSelectorsVariableName at: `#selector) `@value''); - replace: ''`@selector'' with: mockSelector asSymbol; - replace: ''`#selector'' with: ($#, aSelector); - replace: ''`@value'' with: valueMethod asSymbol; - replace: ''`mockedSelectorsVariableName'' with: ''' , aMockedSelectorsVariableName , '''; - change) execute.'. - - "Created: / 10-07-2014 / 22:28:27 / Jakub Nesveda " - "Modified: / 25-09-2014 / 22:43:27 / Jakub Nesveda " -! - compileMockMethodSource "Returns mock method source code which will compile method source." diff -r 0ca40b727a4f -r 3925afb63587 CustomMockTests.st --- a/CustomMockTests.st Thu Feb 05 22:42:42 2015 +0100 +++ b/CustomMockTests.st Thu Feb 05 22:50:23 2015 +0100 @@ -72,40 +72,6 @@ "Created: / 23-09-2014 / 22:53:52 / Jakub Nesveda " ! -test_class_and_instance_methods_overriden_by_mock_block_value - | class mockClass | - - self skipIf: true description: 'unable to fix'. - - [ - class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'. - model createMethodImmediate: (class theMetaclass) protocol: 'p' source: 'aSelector_01: aParam - ^ 10'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: aParam - ^ 15'. - - self assert: (class aSelector_01: nil) = 10. - self assert: (class new aSelector_01: nil) = 15. - - mockClass := mock mockClassOf: class. - mockClass mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 20 ]. - mockClass new mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 25 ]. - - self assert: (mockClass aSelector_01: nil) = 20. - self assert: (mockClass new aSelector_01: nil) = 25. - - testCompleted := true. - - ] ensure: [ - "Need to test if test is complete, because in this case - sometimes happens that the test terminates and is marked as success." - self assert: testCompleted - ]. - - "Created: / 10-07-2014 / 19:06:47 / Jakub Nesveda " - "Modified: / 23-09-2014 / 23:21:26 / Jakub Nesveda " -! - test_class_methods_overriden_by_compiled_mock_method | class mockClass | @@ -171,41 +137,6 @@ "Modified (format): / 22-09-2014 / 23:14:13 / Jakub Nesveda " ! -test_class_methods_overriden_by_mock_block_value - | class mockClass | - - self skipIf: true description: 'unable to fix'. - - [ - class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'. - model createMethodImmediate: (class theMetaclass) protocol: 'p' source: 'aSelector_01: aParam - ^ 10'. - model createMethodImmediate: (class theMetaclass) protocol: 'p' source: 'aSelector_02: aParam - - (self aSelector_01: aParam) = 10 ifTrue: [ ^ true ]. - - ^ false'. - - self assert: (class aSelector_02: nil). - - mockClass := mock mockClassOf: class. - mockClass mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 20 ]. - - self assert: (mockClass aSelector_01: nil) = 20. - self assert: (mockClass aSelector_02: nil) not. - - testCompleted := true. - - ] ensure: [ - "Need to test if test is complete, because in this case - sometimes happens that the test terminates and is marked as success." - self assert: testCompleted - ]. - - "Created: / 10-07-2014 / 18:21:33 / Jakub Nesveda " - "Modified: / 23-09-2014 / 23:21:57 / Jakub Nesveda " -! - test_create_mock_getters_for_selectors | expectedSource01 actualSource01 expectedSource02 actualSource02 mockClass | @@ -407,174 +338,6 @@ "Modified (format): / 22-09-2014 / 23:14:40 / Jakub Nesveda " ! -test_methods_overriden_by_mock_block_value - | class mockClassInstance | - - self skipIf: true description: 'unable to fix'. - - [ - class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: aParam - ^ 10'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_02: aParam - - (self aSelector_01: aParam) = 10 ifTrue: [ ^ true ]. - - ^ false'. - - self assert: (class new aSelector_02: nil). - - mockClassInstance := mock mockOf: class. - mockClassInstance mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 20 ]. - - self assert: (mockClassInstance aSelector_01: nil) = 20. - self assert: (mockClassInstance aSelector_02: nil) not. - - - testCompleted := true. - - ] ensure: [ - "Need to test if test is complete, because in this case - sometimes happens that the test terminates and is marked as success." - self assert: testCompleted - ]. - - "Created: / 17-06-2014 / 21:48:00 / Jakub Nesveda " - "Modified: / 23-09-2014 / 23:22:17 / Jakub Nesveda " -! - -test_methods_overriden_by_mock_block_value_with_none_params - | class mockClassInstance | - - self skipIf: true description: 'unable to fix'. - - [ - class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_01 - ^ 10'. - - self assert: (class new aSelector_01 = 10). - - mockClassInstance := mock mockOf: class. - mockClassInstance mockSelector: #aSelector_01 withBlockValue: [ ^ 30 ]. - - self assert: (mockClassInstance aSelector_01) = 30. - - testCompleted := true. - - ] ensure: [ - "Need to test if test is complete, because in this case - sometimes happens that the test terminates and is marked as success." - self assert: testCompleted - ]. - - "Created: / 20-06-2014 / 09:02:04 / Jakub Nesveda " - "Modified: / 23-09-2014 / 23:22:24 / Jakub Nesveda " -! - -test_methods_overriden_by_mock_block_value_with_params - | class mockClassInstance | - - self skipIf: true description: 'unable to fix'. - - [ - class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: aParam - ^ 10'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_02: aParam - - (self aSelector_01: aParam) = 10 ifTrue: [ ^ true ]. - - ^ false'. - - self assert: (class new aSelector_02: nil). - - mockClassInstance := mock mockOf: class. - mockClassInstance mockSelector: #aSelector_01: withBlockValue: [ :aParam | - aParam = 5 ifTrue: [ - ^ 10 - ]. - - ^ 30 - ]. - - self assert: (mockClassInstance aSelector_01: 5) = 10. - self assert: (mockClassInstance aSelector_02: 3) not. - - testCompleted := true. - - ] ensure: [ - "Need to test if test is complete, because in this case - sometimes happens that the test terminates and is marked as success." - self assert: testCompleted - ]. - - "Created: / 17-06-2014 / 21:56:37 / Jakub Nesveda " - "Modified: / 23-09-2014 / 23:22:28 / Jakub Nesveda " -! - -test_methods_overriden_by_mock_block_value_with_three_params - | class mockClassInstance | - - self skipIf: true description: 'unable to fix'. - - [ - class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: arg_01 param_02: arg_02 param_03: arg_03 - ^ 10'. - - self assert: ((class new aSelector_01: 1 param_02: 2 param_03: 3) = 10). - - mockClassInstance := mock mockOf: class. - mockClassInstance mockSelector: #aSelector_01:param_02:param_03: withBlockValue: [ - :arg_01 :arg_02 :arg_03 | - - ^ arg_01 + arg_02 + arg_03 - ]. - - self assert: (mockClassInstance aSelector_01: 3 param_02: 3 param_03: 3) = 9. - - testCompleted := true. - - ] ensure: [ - "Need to test if test is complete, because in this case - sometimes happens that the test terminates and is marked as success." - self assert: testCompleted - ]. - - "Created: / 20-06-2014 / 09:22:54 / Jakub Nesveda " - "Modified: / 23-09-2014 / 23:22:35 / Jakub Nesveda " -! - -test_methods_overriden_by_mock_block_value_with_two_params - | class mockClassInstance | - - self skipIf: true description: 'unable to fix'. - - [ - class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'. - model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: arg_01 param_02: arg_02 - ^ 10'. - - self assert: ((class new aSelector_01: 1 param_02: 2) = 10). - - mockClassInstance := mock mockOf: class. - mockClassInstance mockSelector: #aSelector_01:param_02: withBlockValue: [ :arg_01 :arg_02 | ^ arg_01 + arg_02 ]. - - self assert: (mockClassInstance aSelector_01: 3 param_02: 3) = 6. - - testCompleted := true. - - ] ensure: [ - "Need to test if test is complete, because in this case - sometimes happens that the test terminates and is marked as success." - self assert: testCompleted - ]. - - "Created: / 20-06-2014 / 09:19:53 / Jakub Nesveda " - "Modified: / 23-09-2014 / 23:22:40 / Jakub Nesveda " -! - test_mock_count_incremented_when_new_class_created | class mockCount | diff -r 0ca40b727a4f -r 3925afb63587 patches/patches.rc --- a/patches/patches.rc Thu Feb 05 22:42:42 2015 +0100 +++ b/patches/patches.rc Thu Feb 05 22:50:23 2015 +0100 @@ -25,7 +25,7 @@ VALUE "LegalCopyright", "My CopyRight or CopyLeft\0" VALUE "ProductName", "LibraryName\0" VALUE "ProductVersion", "6.2.5.1525\0" - VALUE "ProductDate", "Thu, 05 Feb 2015 21:41:46 GMT\0" + VALUE "ProductDate", "Thu, 05 Feb 2015 21:48:33 GMT\0" END END diff -r 0ca40b727a4f -r 3925afb63587 refactoring_custom.rc --- a/refactoring_custom.rc Thu Feb 05 22:42:42 2015 +0100 +++ b/refactoring_custom.rc Thu Feb 05 22:50:23 2015 +0100 @@ -25,7 +25,7 @@ VALUE "LegalCopyright", "My CopyRight or CopyLeft\0" VALUE "ProductName", "ProductName\0" VALUE "ProductVersion", "6.2.5.1525\0" - VALUE "ProductDate", "Thu, 05 Feb 2015 21:41:44 GMT\0" + VALUE "ProductDate", "Thu, 05 Feb 2015 21:48:32 GMT\0" END END