Skip to content

Commit

Permalink
Merge pull request #869 from jecisc/invokedEntity
Browse files Browse the repository at this point in the history
Add FamixTInvocation>>#invokedEntity
  • Loading branch information
jecisc authored Jan 13, 2025
2 parents f4d806b + 4b12da0 commit 62844ee
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/Famix-Tests/FamixTInvocationTest.class.st
Original file line number Diff line number Diff line change
@@ -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
]
10 changes: 10 additions & 0 deletions src/Famix-Traits/FamixTInvocation.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down

0 comments on commit 62844ee

Please sign in to comment.