Package org.silverpeas.core.test.unit
Class JpaMocker
- java.lang.Object
-
- org.silverpeas.core.test.unit.JpaMocker
-
public class JpaMocker extends Object
A mocker of the JPA environment for unit tests and only for unit tests; it must not be used in integration tests.- Author:
- mmoquillon
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Entity<T,?>>
voidmockJPA(org.silverpeas.kernel.util.Mutable<T> savedEntity, Class<T> entityType)
Mocks the JPA backend.static <T extends AbstractJpaEntityRepository<E>,E extends AbstractJpaEntity<E,?>>
TmockRepository(Class<T> repoType, org.silverpeas.kernel.util.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.
-
-
-
Method Detail
-
mockRepository
public static <T extends AbstractJpaEntityRepository<E>,E extends AbstractJpaEntity<E,?>> T mockRepository(Class<T> repoType, org.silverpeas.kernel.util.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:
- a mocked repository.
-
mockJPA
public static <T extends Entity<T,?>> void mockJPA(org.silverpeas.kernel.util.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.
-
-