Class MockSystemRoleFactory

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
  • Constructor Details Link icon

    • MockSystemRoleFactory Link icon

      public MockSystemRoleFactory()
  • Method Details Link icon

    • newInstance Link icon

      @Nonnull public static MockSystemRoleFactory newInstance()
      Returns a new instance of the factory..
      Returns:
      a new instance of the factory
    • findRoles Link icon

      @Nonnull public <R> List<R> findRoles(@Nonnull Object owner, @Nonnull Class<? extends R> roleType)
      Specified by:
      findRoles in interface it.tidalwave.role.spi.SystemRoleFactory
    • with Link icon

      @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 owner
      R - the static type of the role
      Parameters:
      ownerType - the type of the owner
      roleType - the type of the role
      roleFactory - a factory function that instantiates the roles
      Returns:
      a new factory that supports the given owner and role type