public final class CommonsMock extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CommonsMock.Param
This class represents a parameter description for a single mockable type.
|
| Constructor and Description |
|---|
CommonsMock() |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
mock(Class<T> aClass,
Object... aParams)
Create a mock instance of the passed class.
|
<T> ICommonsList<T> |
mockMany(int nCount,
Class<T> aClass,
Object... aParams)
Create a
List of mocked objects. |
<T> ICommonsSet<T> |
mockSet(int nCount,
Class<T> aClass,
Object... aParams)
Create a
ICommonsSet of mocked objects. |
<T> void |
registerPerInstance(Class<T> aDstClass,
CommonsMock.Param[] aParams,
Function<IGetterDirectTrait[],T> aSupplier)
Create a mock supplier with parameters.
|
<T> void |
registerPerInstance(Class<T> aClass,
Supplier<T> aSupplier)
Register a simple supplier (=factory) to be invoked when an instance of the
passed class is to be mocked.
|
void |
registerPerInstance(com.helger.commons.mock.CommonsMock.MockSupplier aSupplier)
Register an arbitrary MockSupplier.
|
<T> void |
registerPerInstanceConstant(T aObject)
Register a constant mock object.
|
static <T> void |
registerStatic(Class<T> aDstClass,
CommonsMock.Param[] aParams,
Function<IGetterDirectTrait[],T> aSupplier)
Create a mock supplier with parameters.
|
static <T> void |
registerStatic(Class<T> aClass,
Supplier<T> aSupplier)
Register a simple supplier (=factory) to be invoked when an instance of the
passed class is to be mocked.
|
static void |
registerStatic(com.helger.commons.mock.CommonsMock.MockSupplier aSupplier)
Register an arbitrary MockSupplier that is available across tests!
|
static <T> void |
registerStaticConstant(T aObject)
Register a constant mock object.
|
public static final <T> void registerStaticConstant(@Nonnull T aObject)
T - The type to be mockedaObject - The object to be used as a mock result. May not be null
.public static final <T> void registerStatic(@Nonnull Class<T> aClass, @Nonnull Supplier<T> aSupplier)
T - The type to be mockedaClass - The class to be mocked. May not be null.aSupplier - The supplier/factory to be invoked when to mock this class. May not
be null.public static final <T> void registerStatic(@Nonnull Class<T> aDstClass, @Nonnull CommonsMock.Param[] aParams, @Nonnull Function<IGetterDirectTrait[],T> aSupplier)
T - The type to be mockedaDstClass - The destination class to be mocked. May not be null.aParams - The parameter declarations to be used. May not be null.aSupplier - The generic function to be invoked. Must take an array of
IGetterDirectTrait and return an instance of the passed
class.public static final void registerStatic(@Nonnull com.helger.commons.mock.CommonsMock.MockSupplier aSupplier)
aSupplier - The supplier to be registered. May not be null.public final <T> void registerPerInstanceConstant(@Nonnull T aObject)
T - The type to be mockedaObject - The object to be used as a mock result. May not be null
.public final <T> void registerPerInstance(@Nonnull Class<T> aClass, @Nonnull Supplier<T> aSupplier)
T - The type to be mockedaClass - The class to be mocked. May not be null.aSupplier - The supplier/factory to be invoked when to mock this class. May not
be null.public final <T> void registerPerInstance(@Nonnull Class<T> aDstClass, @Nonnull CommonsMock.Param[] aParams, @Nonnull Function<IGetterDirectTrait[],T> aSupplier)
T - The type to be mockedaDstClass - The destination class to be mocked. May not be null.aParams - The parameter declarations to be used. May not be null.aSupplier - The generic function to be invoked. Must take an array of
IGetterDirectTrait and return an instance of the passed
class.public final void registerPerInstance(@Nonnull com.helger.commons.mock.CommonsMock.MockSupplier aSupplier)
aSupplier - The supplier to be registered. May not be null.@Nonnull public <T> T mock(@Nonnull Class<T> aClass, @Nullable Object... aParams)
T - The type to be mockedaClass - The class to be mocked. May not be null.aParams - An optional array of parameters to be passed to the mocking
supplier. May be null or empty.null.IllegalStateException - If an exception occurred during the mock instance creation.@Nonnull @ReturnsMutableCopy public <T> ICommonsList<T> mockMany(@Nonnegative int nCount, @Nonnull Class<T> aClass, @Nullable Object... aParams)
List of mocked objects.T - The type to be mockednCount - Number of objects to be mocked. Must be ≥ 0.aClass - The class to be mocked.aParams - An optional array of parameters to be passed to the mocking supplier
for each object to be mocked. May be null or empty.nCount entries.@Nonnull @ReturnsMutableCopy public <T> ICommonsSet<T> mockSet(@Nonnegative int nCount, @Nonnull Class<T> aClass, @Nullable Object... aParams)
ICommonsSet of mocked objects.T - The type to be mockednCount - Number of objects to be mocked. Must be ≥ 0.aClass - The class to be mocked.aParams - An optional array of parameters to be passed to the mocking supplier
for each object to be mocked. May be null or empty.nCount entries.Copyright © 2014–2019 Philip Helger. All rights reserved.