![]() | Force-FrameworkMark Brennand |
| Description | Classes providing the Mocker API. Rather than defining fixed lists of functions and arguments to be mocked, this solution defines the arguments first and then list all the methods that expect those arguments from the class or interface being mocked. Arguments are checked for matches using comparators. A default set of comparators are provided. Custom comparators may be added for arguments to be matched. The default comparator for a custom object or collection of custom objects requires that only the fields set in the object to be matched are set identically in the custom object(s) passed to the mocked method call. The Modifier interface may be used to return a value from a mocked method based on the arguments to the call. For example, this could be used to add a fake Id to custom objects being inserted. See README for full details of the Mocker API. Copyright (c) 2025 Mark Brennand, released under MIT License. |
|---|---|
| Author | Mark Brennand |
| Description | Returns an argument which can be used in a whenArgument call to represent a method parameter which must be of the given Type but whose value is not checked. The parameter may be null if the types match. |
|---|---|
| Parameter | type: The Type the argument is for. |
| Returns | The argument. |
| Description | Returns an argument which can be used in a whenArgument call to represent a method parameter which must be of the given Type but whose value is not checked. The parameter must be non null if the types match. |
|---|---|
| Parameter | type: The Type the argument is for. |
| Returns | The argument. |
| Description | Generates a fake id for the given object type. |
|---|---|
| Parameter | objectType: The object type to have a fake Id generated for. |
| Returns | The fake id. |
| Description | Creates a new Mocker that may be used to define a mocking scenario. |
|---|---|
| Parameter | forType: The class to be mocked. |
| Returns | A Mocker which may be used to define a mocking scenario. |
| Description | Creates a new Mocker that may be used to define a mocking scenario. The Factory argument will be called to create the stubbed object. |
|---|---|
| Parameter | factory: Factory that will create the stubbed object. |
| Returns | A Mocker which may be used to define a mocking scenario. |
| Description | Validates that all the methods in the mocked objects have been called the required number of times. If a method has not been called the correct number of times, an Assertion.AssertionException is thrown. If the method has not set a called count value, it is not validated. |
|---|
| Description | Interface allowing a user of the Mocker.of method to be called back to create the stubbed object. As stubbed objects cannot be created by the Mocker if they are in a different namespace, this interface can be used to create the stubbed object in the caller's namespace. |
|---|
| Description | Creates an instance of a stubbed object. The implementation will be responsible for deciding the class of the object to stub. |
|---|---|
| Parameter | provider: The provider to use for the new stubbed object. |
| Returns | The stubbed object. |
| Description | An implementation of the Modifier interface can be added as argument to Method.returns to make changes to the method arguments when a match for the arguments is found and the registered method is called. An example use case for this would be to add an Id to objects inserted through a call to a mocked method. |
|---|
| Description | Called to make changes to the return value using the arguments passed into the Method. |
|---|---|
| Parameter | arguments: The arguments passed to the Method. |
| Returns | The return value. |
| Description | Argument setting class. It is designed to be callable from both the Mocker, Arguments and Method classes. This is so all three can perform chaining of calls. |
|---|
| Description | Gets the mocked object for the class being mocked. |
|---|---|
| Returns | The mocked object. |
| Description | Creates an argument grouping which has a single argument. This would represent a mocked method which has one parameter. |
|---|---|
| Parameter | argument: The expected parameter value. |
| Returns | The object instance for method chaining. |
| Description | Creates an argument grouping which has two arguments. This would represent a mocked method which has two parameters. |
|---|---|
| Parameter | argument1: The expected value of the first parameter. |
| Parameter | argument2: The expected value of the second parameter. |
| Returns | The object instance for method chaining. |
| Description | Creates an argument grouping which has three arguments. This would represent a mocked method which has three parameters. |
|---|---|
| Parameter | argument1: The expected value of the first parameter. |
| Parameter | argument2: The expected value of the second parameter. |
| Parameter | argument3: The expected value of the third parameter. |
| Returns | The object instance for method chaining. |
| Description | Creates an argument grouping which has four arguments. This would represent a mocked method which has four parameters. |
|---|---|
| Parameter | argument1: The expected value of the first parameter. |
| Parameter | argument2: The expected value of the second parameter. |
| Parameter | argument3: The expected value of the third parameter. |
| Parameter | argument4: The expected value of the fourth parameter. |
| Returns | The object instance for method chaining. |
| Description | Creates an argument grouping which has five arguments. This would represent a mocked method which has five parameters. |
|---|---|
| Parameter | argument1: The expected value of the first parameter. |
| Parameter | argument2: The expected value of the second parameter. |
| Parameter | argument3: The expected value of the third parameter. |
| Parameter | argument4: The expected value of the fourth parameter. |
| Parameter | argument5: The expected value of the fifth parameter. |
| Returns | The object instance for method chaining. |
| Description | Creates an argument grouping which has the given arguments. |
|---|---|
| Parameter | expectedArguments: The arguments to be matched. |
| Returns | The object instance for method chaining. |
| Description | Creates an argument grouping which has no values. This would represent a method with no arguments. |
|---|---|
| Returns | The object instance for method chaining. |
| Description | Method definition associated with an Argument. |
|---|
| Description | Sets the number of times the mocked object is expected to be called. The check is performed when the Mocker.validate method is called. |
|---|---|
| Parameter | expectedCount: The number of times the method is expected to be called. |
| Returns | The object instance for method chaining. |
| Description | Registers a new method for the parent's arguments. The method will be called when the arguments are matched. |
|---|---|
| Parameter | methodName: The name of the method expected. |
| Returns | The mew method instance for method chaining. |
| Description | Sets the return value from the method if the arguments are matched and it is called. The return value may be set to an instance of Modifier to return a value based on the arguments passed to the mocked method call. |
|---|---|
| Parameter | returnValue: The value to be returned if the arguments are matched and this method is called. |
| Returns | The object instance for method chaining. |
| Description | Sets the Exception to be thrown from the method if the arguments are matched and it is called. |
|---|---|
| Parameter | throws: The Exception to throw if the arguments are matched and this method is called. |
| Returns | The object instance for method chaining. |
| Description | Class representing a list of arguments for which mocked methods are to be registered. |
|---|
| Description | Registers a new method for the expected arguments. The method will be called when the arguments are matched. |
|---|---|
| Parameter | methodName: The name of the method expected. |
| Returns | The method instance for method chaining. |
| Description | Adds comparators to the default comparators used when checking the arguments for equivalence. Any additional comparators will be called before the default ones. |
|---|---|
| Parameter | comparators: The additional comparators to be used when checking the expected arguments for equivalence. |
| Returns | The object instance for method chaining. |