Skip to content

Commit

Permalink
Improved reporting of problems when:
Browse files Browse the repository at this point in the history
* verify called and some 'expects' remain in the stack - the term "call stack" seemed to confuse some people
* setToTheSameValueAs is called and the value cannot be JSON serialized - is now reported when the controller is set up, rather than when the method call is made against it
  • Loading branch information
rob-baillie-ortoo committed Feb 27, 2024
1 parent 34d2d10 commit d97479a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
10 changes: 9 additions & 1 deletion force-app/amoss_main/default/classes/Amoss_Instance.cls
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public without sharing class Amoss_Instance implements StubProvider { //NOPMD -
public class Amoss_ExpectsNoCallsAndCallsConfiguredException extends Exception {}
public class Amoss_ExpectedObjectCannotBeNullException extends Exception {}
public class Amoss_NotAnHttpCalloutMockException extends Exception {}
public class Amoss_UnsupportedSameValueAsTypeException extends Exception {}

private Amoss_Expectations expectations = new Amoss_Expectations();
private Amoss_Expectations whens = new Amoss_Expectations();
Expand All @@ -65,7 +66,7 @@ public without sharing class Amoss_Instance implements StubProvider { //NOPMD -

private String moreCallsThanExpectedMessage = '{0}.{1} was called more times than was expected';
private String expectedNoCallsMessage = '{0} did not expect any methods to be called';
private String expectedEmptyCallStackMessage = 'Expected call stack for {0} should be empty, and it is not';
private String expectedEmptyCallStackMessage = 'Expected the list of "expects" methods against {0} to be empty, and it is not. This means that these "expects" calls against the mock controller have not happened.';

public static Amoss_ValueVerifierBuilder valueVerifierBuilder = new Amoss_ValueVerifierBuilder();

Expand Down Expand Up @@ -3958,6 +3959,13 @@ public without sharing class Amoss_Instance implements StubProvider { //NOPMD -
* @return Amoss_SameValueAsVerifier - Itself, allowing for a fluent interface
*/
public Amoss_SameValueAsVerifier setValueToVerifyAgainst( Object value ) {

try {
JSON.serialize( value );
}
catch( Exception e ) {
throw new Amoss_UnsupportedSameValueAsTypeException( 'setToTheSameValueAs only supports types that can be JSON Serialized, and the passed value cannot (' + String.valueOf( value ) + ').\nConsider using "setTo", and if that is not possible, consider using an "anyParameter" method and checking the value of the parameter after the call instead.', e );
}
this.value = value;
return this;
}
Expand Down
Loading

0 comments on commit d97479a

Please sign in to comment.