Skip to content

Commit

Permalink
Merge pull request #124 from bobalicious/feature/add-is-fluent-to-ind…
Browse files Browse the repository at this point in the history
…ovidual-methods

Added 'isFluent' to individual methods
  • Loading branch information
rob-baillie-ortoo authored Aug 4, 2023
2 parents dee9d05 + 853c935 commit f5962bf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
20 changes: 17 additions & 3 deletions force-app/amoss_main/default/classes/Amoss_Instance.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ public without sharing class Amoss_Instance implements StubProvider { //NOPMD -
* .method( 'methodName' )
* .returnsItself()
*
* Has 'returningItself' and 'willReturnItself' as synonyms, and these methods are entirely interchangeable based on preference.
* Has 'returningItself', 'willReturnItself' and 'isFluent' as synonyms, and these methods are entirely interchangeable based on preference.
*/
public Amoss_NextExpectationDefiner returnsItself() {
expectation.setExpectionReturns( new Amoss_ExpectationValueReturn().setReturnValue( expectation.getAmossInstance().getDouble() ) );
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public without sharing class Amoss_Instance implements StubProvider { //NOPMD -
* .method( 'methodName' )
* .willReturnItself()
*
* Has 'returningItself' and 'returnsItself' as synonyms, and these methods are entirely interchangeable based on preference.
* Has 'returningItself', 'returnsItself' and 'isFluent' as synonyms, and these methods are entirely interchangeable based on preference.
*/
public Amoss_NextExpectationDefiner willReturnItself() {
return this.returnsItself();
Expand Down Expand Up @@ -1290,13 +1290,27 @@ public without sharing class Amoss_Instance implements StubProvider { //NOPMD -
* .method( 'methodName' )
* .returningItself()
*
* Has 'willReturnItself' and 'returnsItself' as synonyms, and these methods are entirely interchangeable based on preference.
* Has 'willReturnItself', 'returnsItself' and 'isFluent' as synonyms, and these methods are entirely interchangeable based on preference.
*/
public Amoss_NextExpectationDefiner returningItself() {
return this.returnsItself();
}


/**
* States that the current double (I.E. the effective 'this') should be returned when this 'expectation' or 'when' is met.
*
* For example, to specify:
* .when()
* .method( 'methodName' )
* .returnsItself()
*
* Has 'returningItself', 'willReturnItself' and 'returnsItself' as synonyms, and these methods are entirely interchangeable based on preference.
*/
public Amoss_NextExpectationDefiner isFluent() {
return this.returnsItself();
}

/**
* States that when this 'expectation' or 'when' is met, the method show throw the given exception.
*
Expand Down
23 changes: 23 additions & 0 deletions force-app/amoss_tests/default/classes/AmossTest_InstanceTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,29 @@ public with sharing class AmossTest_InstanceTest {
Assert.areEqual( classToDoubleController.getDouble(), returnFromDouble, 'when.method.returningItself, and the method called, will return the double' );
}

/**
* @method when.method.isFluent
* @case when that method is called
* @result will return the double
*/
@isTest
private static void whenMethodIsFluent_whenCalled_returnTheDouble() {

Amoss_Instance classToDoubleController = new Amoss_Instance( AmossTest_ClassToDouble.class );
AmossTest_ClassToDouble classToDouble = (AmossTest_ClassToDouble)classToDoubleController.getDouble();

classToDoubleController
.when()
.method( 'fluentMethod' )
.isFluent();

Test.startTest();
AmossTest_ClassToDouble returnFromDouble = classToDouble.fluentMethod();
Test.stopTest();

Assert.areEqual( classToDoubleController.getDouble(), returnFromDouble, 'when.method.isFluent, and the method called, will return the double' );
}

/**
* @method isFluent
* @case when an unspecified, fluent method is called
Expand Down

0 comments on commit f5962bf

Please sign in to comment.