![]() This is what our controller is going to do.This post explains how to capture multiple arguments passed to a method in a consecutive calls. They should capture the input from the user and then offload to a service to enable maximum reuse across the system. Our controllerĬontrollers should be as lightweight as possible and shouldn’t include any business logic, ideally. Our focal point is going to be how to test that our customer service layer in the middle of all of this, correctly calls the duplicate account service layer with the correct information without having to run the actual callout logic.Īt this point you might be wondering why not just run the duplicate account service layer logic? Well, we could, but it’s not nice and involves possibly setting up extra test data and even having to mock the callout response in that layer even before we can start testing the layer above it (the customer service layer). Lastly, the duplicate account service layer which is responsible for making the callout to the external system.One service layer for creating the customer and asking another layer if a duplicate exists in the external system.A controller for interacting with the Visualforce page.In some situations though, it is helpful to assert on certain arguments after the. This is also the recommended way of matching arguments because it makes tests clean and simple. Mockito verifies argument values in natural Java style: by using an equals() method. It is used to capture argument values for further assertions. Argument captor captures argument values for further assertions. We’re going to also create the layers in the correct set up: ArgumentCaptor The AgrumentCaptor is a class that is defined in the org.mockito package. We will be creating a Visualforce page controller which is going to create a new account in the system, so long as the customer does not exist in an external system. To explain what this feature is I’m going to walk through a simple day to day activity as a developer. If you’re not familiar with ApexMocks then I highly recommend checking out the Github repository where you can find several links to lots of existing documentation: This blog is heavily based on the application structure found within the FFLIB sample code repository which you find at: Argument capture can really enhance your unit testing capabilities within FFLIB and ApexMocks based projects. In this blog post I’m writing about ApexMocks and one particular feature which I found extremely useful, argument capture.
0 Comments
Leave a Reply. |