java.lang.Object
it.tidalwave.ui.test.MockSystemRoleFactory
- All Implemented Interfaces:
it.tidalwave.role.spi.SystemRoleFactory
@API(status=EXPERIMENTAL)
public final class MockSystemRoleFactory
extends Object
implements it.tidalwave.role.spi.SystemRoleFactory
A mock implementation of
SystemRoleFactory
for tests. It should be created by passing triples that associate a class type, a role type and a
factory function:
final var rf = MockSystemRoleFactory.newInstance()
.with(Datum.class, Role1.class, o -> List.of(new MockRole1a(o), new MockRole2(o)))
.with(Datum.class, Role2.class, o -> List.of(new MockRole3(o)));
The function argument is the owner of the roles.
This class must be installed before each test run (e.g. in a method annotated with BeforeMethod
):
SystemRoleFactory.reset();
SystemRoleFactory.set(MockSystemRoleFactory.newInstance().with(...));
- Author:
- Fabrizio Giudici
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<R> List
<R> static MockSystemRoleFactory
Returns a new instance of the factory.<T,
R> MockSystemRoleFactory Returns a new factory that supports the given owner and role type.
-
Constructor Details
-
Method Details
-
newInstance
Returns a new instance of the factory..- Returns:
- a new instance of the factory
-
findRoles
- Specified by:
findRoles
in interfaceit.tidalwave.role.spi.SystemRoleFactory
-
with
@Nonnull public <T,R> MockSystemRoleFactory with(@Nonnull Class<T> ownerType, @Nonnull Class<R> roleType, @Nonnull Function<T, List<R>> roleFactory) Returns a new factory that supports the given owner and role type..- Type Parameters:
T
- the static type of the ownerR
- the static type of the role- Parameters:
ownerType
- the type of the ownerroleType
- the type of the roleroleFactory
- a factory function that instantiates the roles- Returns:
- a new factory that supports the given owner and role type
-