Skip to content

Commit

Permalink
Added tests for the after too
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Oct 25, 2024
1 parent 0595b74 commit 0c29b9b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
35 changes: 35 additions & 0 deletions src/MethodProxies-Tests/MpArgumentListTestHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Class {
#name : 'MpArgumentListTestHandler',
#superclass : 'MpHandler',
#instVars : [
'beforeArgs',
'afterArgs'
],
#category : 'MethodProxies-Tests',
#package : 'MethodProxies-Tests'
}

{ #category : 'accessing' }
MpArgumentListTestHandler >> afterArgs [

^ afterArgs
]

{ #category : 'evaluating' }
MpArgumentListTestHandler >> afterExecutionWithReceiver: anObject arguments: anArrayOfObjects returnValue: aReturnValue [

afterArgs := anArrayOfObjects.
^ aReturnValue
]

{ #category : 'accessing' }
MpArgumentListTestHandler >> beforeArgs [

^ beforeArgs
]

{ #category : 'evaluating' }
MpArgumentListTestHandler >> beforeExecutionWithReceiver: anObject arguments: anArrayOfObjects [

beforeArgs := anArrayOfObjects
]
21 changes: 0 additions & 21 deletions src/MethodProxies-Tests/MpArgumentsArrayHandler.class.st

This file was deleted.

33 changes: 24 additions & 9 deletions src/MethodProxies-Tests/MpMethodProxyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,61 @@ MpMethodProxyTest >> handlerClass [
MpMethodProxyTest >> testArgumentListIsSent [

| mp handler |
mp := MpMethodProxy onMethod: MpClassA >> #methodWithArgument: handler: (handler := MpArgumentsArrayHandler new).
mp := MpMethodProxy onMethod: MpClassA >> #methodWithArgument: handler: (handler := MpArgumentListTestHandler new).

self installMethodProxy: mp.

MpClassA new x: 1; methodWithArgument: 111.

mp uninstall.
self assert: handler argsArray size equals: 1.
self assert: handler argsArray first equals: 111
"Test before"
self assert: handler beforeArgs size equals: 1.
self assert: handler beforeArgs first equals: 111.

"Test after"
self assert: handler afterArgs size equals: 1.
self assert: handler afterArgs first equals: 111.
]

{ #category : 'tests - safety' }
MpMethodProxyTest >> testArgumentListIsSentSizeTwo [

| mp handler |
mp := MpMethodProxy
onMethod: MpClassA >> #methodWithArgumentOne:argumentTwo: handler: (handler := MpArgumentsArrayHandler new).
onMethod: MpClassA >> #methodWithArgumentOne:argumentTwo: handler: (handler := MpArgumentListTestHandler new).

self installMethodProxy: mp.

MpClassA new x:1; methodWithArgumentOne: 22 argumentTwo: 33.

mp uninstall.
self assert: handler argsArray size equals: 2.
self assert: handler argsArray first equals: 22.
self assert: handler argsArray second equals: 33
"Test before"
self assert: handler beforeArgs size equals: 2.
self assert: handler beforeArgs first equals: 22.
self assert: handler beforeArgs second equals: 33.

"Test after"
self assert: handler afterArgs size equals: 2.
self assert: handler afterArgs first equals: 22.
self assert: handler afterArgs second equals: 33
]

{ #category : 'tests - safety' }
MpMethodProxyTest >> testArgumentListIsSentSizeZero [

| mp handler |
mp := MpMethodProxy onMethod: MpClassA >> #methodTwo handler: (handler := MpArgumentsArrayHandler new).
mp := MpMethodProxy onMethod: MpClassA >> #methodTwo handler: (handler := MpArgumentListTestHandler new).

self installMethodProxy: mp.

MpClassA new methodTwo.

mp uninstall.
self assert: handler argsArray isEmpty
"Test before"
self assert: handler beforeArgs isEmpty.

"Test after"
self assert: handler afterArgs isEmpty.
]

{ #category : 'tests - safety' }
Expand Down

0 comments on commit 0c29b9b

Please sign in to comment.