CustomMockTests.st
changeset 816 3925afb63587
parent 804 14025d247548
child 829 59bfd92fcef0
equal deleted inserted replaced
815:0ca40b727a4f 816:3925afb63587
    70     ].
    70     ].
    71 
    71 
    72     "Created: / 23-09-2014 / 22:53:52 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
    72     "Created: / 23-09-2014 / 22:53:52 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
    73 !
    73 !
    74 
    74 
    75 test_class_and_instance_methods_overriden_by_mock_block_value
       
    76     | class mockClass |
       
    77 
       
    78     self skipIf: true description: 'unable to fix'. 
       
    79 
       
    80     [
       
    81         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
       
    82         model createMethodImmediate: (class theMetaclass) protocol: 'p' source: 'aSelector_01: aParam
       
    83         ^ 10'.
       
    84         model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: aParam
       
    85         ^ 15'.
       
    86 
       
    87         self assert: (class aSelector_01: nil) = 10.
       
    88         self assert: (class new aSelector_01: nil) = 15.
       
    89 
       
    90         mockClass := mock mockClassOf: class.
       
    91         mockClass mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 20 ].
       
    92         mockClass new mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 25 ].
       
    93 
       
    94         self assert: (mockClass aSelector_01: nil) = 20.
       
    95         self assert: (mockClass new aSelector_01: nil) = 25.
       
    96 
       
    97         testCompleted := true.
       
    98 
       
    99     ] ensure: [
       
   100         "Need to test if test is complete, because in this case
       
   101         sometimes happens that the test terminates and is marked as success."
       
   102         self assert: testCompleted
       
   103     ].
       
   104 
       
   105     "Created: / 10-07-2014 / 19:06:47 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   106     "Modified: / 23-09-2014 / 23:21:26 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   107 !
       
   108 
       
   109 test_class_methods_overriden_by_compiled_mock_method
    75 test_class_methods_overriden_by_compiled_mock_method
   110     | class mockClass |
    76     | class mockClass |
   111 
    77 
   112     [
    78     [
   113         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
    79         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
   167         self assert: testCompleted
   133         self assert: testCompleted
   168     ].
   134     ].
   169 
   135 
   170     "Created: / 10-07-2014 / 19:35:52 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   136     "Created: / 10-07-2014 / 19:35:52 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   171     "Modified (format): / 22-09-2014 / 23:14:13 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   137     "Modified (format): / 22-09-2014 / 23:14:13 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   172 !
       
   173 
       
   174 test_class_methods_overriden_by_mock_block_value
       
   175     | class mockClass |
       
   176 
       
   177     self skipIf: true description: 'unable to fix'. 
       
   178 
       
   179     [
       
   180         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
       
   181         model createMethodImmediate: (class theMetaclass) protocol: 'p' source: 'aSelector_01: aParam
       
   182         ^ 10'.
       
   183         model createMethodImmediate: (class theMetaclass) protocol: 'p' source: 'aSelector_02: aParam
       
   184 
       
   185         (self aSelector_01: aParam) = 10 ifTrue: [ ^ true ].
       
   186 
       
   187         ^ false'.
       
   188 
       
   189         self assert: (class aSelector_02: nil).
       
   190 
       
   191         mockClass := mock mockClassOf: class.
       
   192         mockClass mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 20 ].
       
   193 
       
   194         self assert: (mockClass aSelector_01: nil) = 20.
       
   195         self assert: (mockClass aSelector_02: nil) not.
       
   196 
       
   197         testCompleted := true.
       
   198 
       
   199     ] ensure: [
       
   200         "Need to test if test is complete, because in this case
       
   201         sometimes happens that the test terminates and is marked as success."
       
   202         self assert: testCompleted
       
   203     ].
       
   204 
       
   205     "Created: / 10-07-2014 / 18:21:33 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   206     "Modified: / 23-09-2014 / 23:21:57 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   207 !
   138 !
   208 
   139 
   209 test_create_mock_getters_for_selectors    
   140 test_create_mock_getters_for_selectors    
   210     | expectedSource01 actualSource01 expectedSource02 actualSource02 mockClass |
   141     | expectedSource01 actualSource01 expectedSource02 actualSource02 mockClass |
   211 
   142 
   403         self assert: testCompleted
   334         self assert: testCompleted
   404     ].
   335     ].
   405 
   336 
   406     "Created: / 15-06-2014 / 20:19:47 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   337     "Created: / 15-06-2014 / 20:19:47 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   407     "Modified (format): / 22-09-2014 / 23:14:40 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   338     "Modified (format): / 22-09-2014 / 23:14:40 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
   408 !
       
   409 
       
   410 test_methods_overriden_by_mock_block_value
       
   411     | class mockClassInstance |
       
   412 
       
   413     self skipIf: true description: 'unable to fix'.
       
   414 
       
   415     [
       
   416         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
       
   417         model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: aParam
       
   418         ^ 10'.
       
   419         model createMethodImmediate: class protocol: 'p' source: 'aSelector_02: aParam
       
   420 
       
   421         (self aSelector_01: aParam) = 10 ifTrue: [ ^ true ].
       
   422 
       
   423         ^ false'.
       
   424 
       
   425         self assert: (class new aSelector_02: nil).
       
   426 
       
   427         mockClassInstance := mock mockOf: class.
       
   428         mockClassInstance mockSelector: #aSelector_01: withBlockValue: [ :aParam | ^ 20 ].
       
   429 
       
   430         self assert: (mockClassInstance aSelector_01: nil) = 20.
       
   431         self assert: (mockClassInstance aSelector_02: nil) not.
       
   432 
       
   433 
       
   434         testCompleted := true.
       
   435 
       
   436     ] ensure: [ 
       
   437         "Need to test if test is complete, because in this case
       
   438         sometimes happens that the test terminates and is marked as success."
       
   439         self assert: testCompleted
       
   440     ].
       
   441 
       
   442     "Created: / 17-06-2014 / 21:48:00 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   443     "Modified: / 23-09-2014 / 23:22:17 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   444 !
       
   445 
       
   446 test_methods_overriden_by_mock_block_value_with_none_params
       
   447     | class mockClassInstance |
       
   448 
       
   449     self skipIf: true description: 'unable to fix'.
       
   450 
       
   451     [
       
   452         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
       
   453         model createMethodImmediate: class protocol: 'p' source: 'aSelector_01
       
   454         ^ 10'.
       
   455 
       
   456         self assert: (class new aSelector_01 = 10).
       
   457 
       
   458         mockClassInstance := mock mockOf: class.
       
   459         mockClassInstance mockSelector: #aSelector_01 withBlockValue: [ ^ 30 ].
       
   460 
       
   461         self assert: (mockClassInstance aSelector_01) = 30.
       
   462 
       
   463         testCompleted := true.
       
   464 
       
   465     ] ensure: [
       
   466         "Need to test if test is complete, because in this case
       
   467         sometimes happens that the test terminates and is marked as success."
       
   468         self assert: testCompleted
       
   469     ].
       
   470 
       
   471     "Created: / 20-06-2014 / 09:02:04 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   472     "Modified: / 23-09-2014 / 23:22:24 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   473 !
       
   474 
       
   475 test_methods_overriden_by_mock_block_value_with_params
       
   476     | class mockClassInstance |
       
   477 
       
   478     self skipIf: true description: 'unable to fix'.
       
   479 
       
   480     [
       
   481         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
       
   482         model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: aParam
       
   483         ^ 10'.
       
   484         model createMethodImmediate: class protocol: 'p' source: 'aSelector_02: aParam
       
   485 
       
   486         (self aSelector_01: aParam) = 10 ifTrue: [ ^ true ].
       
   487 
       
   488         ^ false'.
       
   489 
       
   490         self assert: (class new aSelector_02: nil).
       
   491 
       
   492         mockClassInstance := mock mockOf: class.
       
   493         mockClassInstance mockSelector: #aSelector_01: withBlockValue: [ :aParam | 
       
   494             aParam = 5 ifTrue: [
       
   495                 ^ 10
       
   496             ].
       
   497 
       
   498             ^ 30
       
   499         ].
       
   500 
       
   501         self assert: (mockClassInstance aSelector_01: 5) = 10.
       
   502         self assert: (mockClassInstance aSelector_02: 3) not.
       
   503 
       
   504         testCompleted := true.
       
   505 
       
   506     ] ensure: [ 
       
   507         "Need to test if test is complete, because in this case
       
   508         sometimes happens that the test terminates and is marked as success."
       
   509         self assert: testCompleted
       
   510     ].
       
   511 
       
   512     "Created: / 17-06-2014 / 21:56:37 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   513     "Modified: / 23-09-2014 / 23:22:28 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   514 !
       
   515 
       
   516 test_methods_overriden_by_mock_block_value_with_three_params
       
   517     | class mockClassInstance |
       
   518 
       
   519     self skipIf: true description: 'unable to fix'.
       
   520 
       
   521     [
       
   522         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
       
   523         model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: arg_01 param_02: arg_02 param_03: arg_03
       
   524         ^ 10'.
       
   525 
       
   526         self assert: ((class new aSelector_01: 1 param_02: 2 param_03: 3) = 10).
       
   527 
       
   528         mockClassInstance := mock mockOf: class.
       
   529         mockClassInstance mockSelector: #aSelector_01:param_02:param_03: withBlockValue: [ 
       
   530             :arg_01 :arg_02 :arg_03 | 
       
   531 
       
   532             ^ arg_01 + arg_02 + arg_03
       
   533         ].
       
   534 
       
   535         self assert: (mockClassInstance aSelector_01: 3 param_02: 3 param_03: 3) = 9.
       
   536 
       
   537         testCompleted := true.
       
   538 
       
   539     ] ensure: [ 
       
   540         "Need to test if test is complete, because in this case
       
   541         sometimes happens that the test terminates and is marked as success."
       
   542         self assert: testCompleted
       
   543     ].
       
   544 
       
   545     "Created: / 20-06-2014 / 09:22:54 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   546     "Modified: / 23-09-2014 / 23:22:35 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   547 !
       
   548 
       
   549 test_methods_overriden_by_mock_block_value_with_two_params
       
   550     | class mockClassInstance |
       
   551 
       
   552     self skipIf: true description: 'unable to fix'.
       
   553 
       
   554     [
       
   555         class := model createClassImmediate: 'TestClassForMockTestCase' superClassName: 'Object'.
       
   556         model createMethodImmediate: class protocol: 'p' source: 'aSelector_01: arg_01 param_02: arg_02
       
   557         ^ 10'.
       
   558 
       
   559         self assert: ((class new aSelector_01: 1 param_02: 2) = 10).
       
   560 
       
   561         mockClassInstance := mock mockOf: class.
       
   562         mockClassInstance mockSelector: #aSelector_01:param_02: withBlockValue: [ :arg_01 :arg_02 | ^ arg_01 + arg_02 ].
       
   563 
       
   564         self assert: (mockClassInstance aSelector_01: 3 param_02: 3) = 6.
       
   565 
       
   566         testCompleted := true.
       
   567 
       
   568     ] ensure: [ 
       
   569         "Need to test if test is complete, because in this case
       
   570         sometimes happens that the test terminates and is marked as success."
       
   571         self assert: testCompleted
       
   572     ].
       
   573 
       
   574     "Created: / 20-06-2014 / 09:19:53 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   575     "Modified: / 23-09-2014 / 23:22:40 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
       
   576 !
   339 !
   577 
   340 
   578 test_mock_count_incremented_when_new_class_created
   341 test_mock_count_incremented_when_new_class_created
   579     | class mockCount |
   342     | class mockCount |
   580 
   343