Skip to content

API_MockTestHelper

Class · Group: Web Services

apex
global inherited sharing class API_MockTestHelper

Test helper for API mock verification. Provides assertion methods that delegate to API_MockFactory verification API with descriptive error messages.

Since: 1.0

Example:

apex
API_MockFactory.forService('API_SendEmail').body('{}').statusCode(200).register();
// ... execute callout logic ...
API_MockTestHelper.assertServiceCalled('API_SendEmail');
API_MockTestHelper.assertServiceCalledTimes('API_SendEmail', 1);

See Also: API_MockFactory


Methods

MethodDescription
global static void assertLastRequestContains(String serviceName, String expectedContent)Asserts that the last request body contains the expected text.
global static void assertServiceCalled(String serviceName)Asserts that a service was called at least once.
global static void assertServiceCalledTimes(String serviceName, Integer expectedCount)Asserts that a service was called exactly the specified number of times.
global static void assertServiceNeverCalled(String serviceName)Asserts that a service was never called.

Method Details

assertLastRequestContains

apex
global static void assertLastRequestContains(String serviceName, String expectedContent)

Asserts that the last request body contains the expected text.

Parameters:

  • serviceName (String) - The service class name to verify
  • expectedContent (String) - Text expected in the last request body

Since: 1.0

assertServiceCalled

apex
global static void assertServiceCalled(String serviceName)

Asserts that a service was called at least once.

Parameters:

  • serviceName (String) - The service class name to verify

Since: 1.0

assertServiceCalledTimes

apex
global static void assertServiceCalledTimes(String serviceName, Integer expectedCount)

Asserts that a service was called exactly the specified number of times.

Parameters:

  • serviceName (String) - The service class name to verify
  • expectedCount (Integer) - The expected number of invocations

Since: 1.0

assertServiceNeverCalled

apex
global static void assertServiceNeverCalled(String serviceName)

Asserts that a service was never called.

Parameters:

  • serviceName (String) - The service class name to verify

Since: 1.0