From 628b94d93906cdc989e7b412796a82d5f32f0710 Mon Sep 17 00:00:00 2001 From: Suraj Pillai <85.suraj@gmail.com> Date: Sat, 4 Nov 2023 09:26:13 -0400 Subject: [PATCH] Update Readme --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index d82c3f5..0bd986b 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,32 @@ A universal mocking class for Apex, built using the [Apex Stub API](https://deve AccountDBService mockDBService = (AccountDBService)mockInstance.createStub(); ``` +#### Sequential Mocks + +There might be instances where you may need the same method to mock different return values within the same test when +testing utility methods or selector classes and such. You can specify different return values based on the call count +in such cases + +- A basic example + +```java + mockInstance.when('getOneAccount').thenReturnUntil(3,mockAccountOne).thenReturn(mockAccountTwo); +``` + +Here, `mockAccountOne` is returned the first 3 times `getOneAccount` is called. All subsequent calls to `getOneAccount` +will return `mockAccountTwo` + +- You can also pair it with param types or to mock exceptions + +```java + mockInstance.when('getOneAccount').withParamTypes(new List{Id.class}) + .thenReturnUntil(1,mockAccountOne) + .thenThrowUntil(3,mockException) + .thenReturn(mockAccountThree); +``` + +**Note**: It is recommended that you end all setup method call chains with `thenReturn` or `thenThrow` + #### Mutating arguments There might be instances where you need to modify the original arguments passed into the function. A typical example