Source:
public void testFindAll() { String entityTypeId = "MyEntityType"; Selection filter = Selection.FULL_SELECTION; Selection expand = Selection.EMPTY_SELECTION; Attribute idAttribute = mock(Attribute.class); EntityType entityType = mock(EntityType.class); Repository<Entity> repository = mock(Repository.class); when(repository.getEntityType()).thenReturn(entityType); Entity entity1 = mock(Entity.class); Entity entity2 = mock(Entity.class); Sort sort = Sort.create("field", Direction.ASC); Fetch fetch = new Fetch().field("id", new Fetch().field("refAttr")); Query q = Query.builder().setOperator(Operator.MATCHES).setValue("value").build(); org.molgenis.data.Query<Entity> findAllQuery = mock(org.molgenis.data.Query.class); org.molgenis.data.Sort dataSort = mock(org.molgenis.data.Sort.class); org.molgenis.data.Query<Entity> findQuery = new QueryImpl(findAllQuery); findQuery.fetch(fetch); findQuery.offset(10); findQuery.pageSize(10); findQuery.sort(dataSort); org.molgenis.data.Query<Entity> countQuery = new QueryImpl(findAllQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); when(repository.findAll(findQuery)).thenReturn(Stream.of(entity1, entity2)); when(repository.count(countQuery)).thenReturn(100L); when(queryMapperV3.map(q, repository)).thenReturn(findAllQuery).thenReturn(countQuery); when(sortMapperV3.map(sort)).thenReturn(dataSort); when(metaDataService.getRepository(entityTypeId)).thenReturn(Optional.of(repository)); Entities actual = dataServiceV3Impl.findAll(entityTypeId, q, filter, expand, sort, 10, 1); assertEquals( actual, Entities.builder().setEntities(asList(entity1, entity2)).setTotal(100).build()); }

Target:
public void testFindAll() { String entityTypeId = "MyEntityType"; Selection filter = Selection.FULL_SELECTION; Selection expand = Selection.EMPTY_SELECTION; Attribute idAttribute = mock(Attribute.class); EntityType entityType = mock(EntityType.class); Repository<Entity> repository = mock(Repository.class); when(repository.getEntityType()).thenReturn(entityType); Entity entity1 = mock(Entity.class); Entity entity2 = mock(Entity.class); Sort sort = Sort.create("field", Direction.ASC); Fetch fetch = new Fetch().field("id", new Fetch().field("refAttr")); Query q = Query.builder().setOperator(Operator.MATCHES).setValue("value").build(); org.molgenis.data.Query<Entity> findAllQuery = mock(org.molgenis.data.Query.class); org.molgenis.data.Sort dataSort = mock(org.molgenis.data.Sort.class); org.molgenis.data.Query<Entity> findQuery = new QueryImpl<>(findAllQuery); findQuery.fetch(fetch); findQuery.offset(10); findQuery.pageSize(10); findQuery.sort(dataSort); org.molgenis.data.Query<Entity> countQuery = new QueryImpl<>(findAllQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); when(repository.findAll(findQuery)).thenReturn(Stream.of(entity1, entity2)); when(repository.count(countQuery)).thenReturn(100L); when(queryMapperV3.map(q, repository)).thenReturn(findAllQuery).thenReturn(countQuery); when(sortMapperV3.map(sort)).thenReturn(dataSort); when(metaDataService.getRepository(entityTypeId)).thenReturn(Optional.of(repository)); Entities actual = dataServiceV3Impl.findAll(entityTypeId, q, filter, expand, sort, 10, 1); assertEquals( actual, Entities.builder().setEntities(asList(entity1, entity2)).setTotal(100).build()); }