diff --git a/src/Famix-Tests/FamixTInvocationTest.class.st b/src/Famix-Tests/FamixTInvocationTest.class.st new file mode 100644 index 00000000..52a9e3e1 --- /dev/null +++ b/src/Famix-Tests/FamixTInvocationTest.class.st @@ -0,0 +1,63 @@ +Class { + #name : #FamixTInvocationTest, + #superclass : #TestCase, + #instVars : [ + 'invocation' + ], + #category : #'Famix-Tests' +} + +{ #category : #running } +FamixTInvocationTest >> setUp [ + + super setUp. + invocation := MooseEntity new + addTalent: FamixTInvocation; + yourself. + + invocation initialize +] + +{ #category : #running } +FamixTInvocationTest >> testInvokedEntity [ + + | function | + function := MooseEntity new + addTalent: FamixTFunction; + initialize; + yourself. + + invocation addCandidate: function. + + self assert: invocation candidates size equals: 1. + self assert: invocation invokedEntity equals: function +] + +{ #category : #running } +FamixTInvocationTest >> testInvokedEntityWithMoreThan1Candidate [ + + | function1 function2 | + function1 := MooseEntity new + addTalent: FamixTFunction; + initialize; + yourself. + + function2 := MooseEntity new + addTalent: FamixTFunction; + initialize; + yourself. + + invocation + addCandidate: function1; + addCandidate: function2. + + self assert: invocation candidates size equals: 2. + self should: [ invocation invokedEntity ] raise: Error +] + +{ #category : #running } +FamixTInvocationTest >> testInvokedEntityWithNoCandidate [ + + self assertEmpty: invocation candidates. + self should: [ invocation invokedEntity ] raise: Error +] diff --git a/src/Famix-Traits/FamixTInvocation.trait.st b/src/Famix-Traits/FamixTInvocation.trait.st index fe2df6aa..d7be54cb 100644 --- a/src/Famix-Traits/FamixTInvocation.trait.st +++ b/src/Famix-Traits/FamixTInvocation.trait.st @@ -160,6 +160,16 @@ FamixTInvocation >> getReceivingFamixClass [ ifFalse: [ ^ tmpReceiver ] ] +{ #category : #accessing } +FamixTInvocation >> invokedEntity [ + "This method returns only one candidate if there is one, or raises an error if there is more or less than one candidate." + + self candidates size = 1 ifFalse: [ + self error: '1 candidate was expected but ' , self candidates size asString , ' candidates are present in this invocation.' ]. + + ^ self candidates anyOne +] + { #category : #testing } FamixTInvocation >> isInvocation [