bobalicious / amoss

Amoss - Apex Mock Objects, Spies and Stubs - A Simple Mocking framework for Apex (Salesforce)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resolve behaviour with expected SObjects - clarify difference between 'same instance' and 'same properties' checking

bobalicious opened this issue · comments

Turns out that assert.equals and '==' matches sObjects that are different instances, but have the same properties set to the same values. This isn't ideal for the mock framework when we most likely want to check that we have the same actual instance.

This is required because it is reasonable to assume that some behaviours we are checking rely on the mutation of parameters, and we would want to make sure that the instance of an sobject being passed in is the same actual object as one another one.

Change behaviours to:

Default behaviour - only match if the parameter passed is the same instance as theContact:

  • expects().method('methodName').withParameter( theContact )
  • expects().method('methodName').withParameter().setTo( theContact )
  • expects().method('methodName').withParameterNamed( 'contact' ).setTo( theContact )

Property based matching behaviour - will match if the parameter passed has all the properties that are set on theContact set to matching values. The passed parameter is allowed to have additional properties set:

  • expects().method('methodName').withParameter().havingFieldsSetLike( theContact )
  • expects().method('methodName').withParameterNamed( 'contact' ).havingFieldsSetLike( theContact )