Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class ResourceController<T extends RESTResource<T>> extends MainController {
- @Autowired
- protected RESTRepository<T> itemRepository;
- public Page<T> listAll(T search, Pageable pageable) {
- return itemRepository.findAll(search, pageable);
- }
- }
- @NoRepositoryBean
- public interface RESTRepository<T> extends PagingAndSortingRepository<T,
- String>, JpaSpecificationExecutor<T> {
- }
- @RunWith(SpringRunner.class)
- @ContextConfiguration
- public class ResourceControllerTest {
- @MockBean(classes = ResourceController.class, answer = CALLS_REAL_METHODS)
- private ResourceController ressourceControler;
- @MockBean(classes = RESTResource.class)
- private RESTResource search;
- @MockBean
- protected RESTRepository itemRepository;
- @MockBean
- private Pageable pageable;
- @Before
- public void initMocks(){
- MockitoAnnotations.initMocks(this);
- }
- @Test
- public void testListAll() throws Exception {
- // Given
- Page page = new PageImpl(new ArrayList());
- when(itemRepository.findAll(search, pageable)).thenReturn(page);
- // When
- Object obj = ressourceControler.listAll(search, pageable);
- //Then
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement