Class JpaMocker


  • public class JpaMocker
    extends Object
    A mocker of the JPA environment.
    Author:
    mmoquillon
    • Constructor Detail

      • JpaMocker

        public JpaMocker​(CommonAPITestRule commonAPITestRule)
        Constructs a mocker for the JPA environment context.
        Parameters:
        commonAPITestRule - the CommonAPITestRule rule used in the test.
    • Method Detail

      • mockRepository

        public <T extends AbstractJpaEntityRepository<E>,​E extends AbstractJpaEntity> T mockRepository​(Class<T> repoType,
                                                                                                             Mutable<E> savedEntity)
        Mocks the specified repository and uses the specified mutable container to store any entity that is asked to be saved with the saving method of the mocked repository.
        Type Parameters:
        T - the concrete type of the repository to mock.
        E - the concrete type of the entity that is stored into the repository.
        Parameters:
        repoType - the actual type of the repository to mock.
        savedEntity - the mutable container used to store any entity saved.
        Returns:
        the mock of the repository.
      • mockJPA

        public <T extends Entity> void mockJPA​(Mutable<T> savedEntity,
                                               Class<T> entityType)
        Mocks the JPA backend.
        Type Parameters:
        T - the type of the entity
        Parameters:
        savedEntity - the mutable container having possibly an entity that was saved. Used to find such an entity when invoking the JPA entity finder.
        entityType - the actual class of the entity.