@Test public void find_with_paging() { GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(3).pageSize(10).build(); finder.find(query); ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class); verify(groupMembershipDao) .selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture()); assertThat(argumentOffset.getValue()).isEqualTo(20); assertThat(argumentLimit.getValue()).isEqualTo(11); }
@Test public void find_with_paging_having_more_results() { GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(1).pageSize(2).build(); when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())) .thenReturn( newArrayList( new GroupMembershipDto().setId(1L).setName("group1"), new GroupMembershipDto().setId(2L).setName("group2"), new GroupMembershipDto().setId(3L).setName("group3"))); GroupMembershipFinder.Membership result = finder.find(query); ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class); verify(groupMembershipDao) .selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture()); assertThat(argumentOffset.getValue()).isEqualTo(0); assertThat(argumentLimit.getValue()).isEqualTo(3); assertThat(result.hasMoreResults()).isTrue(); }
@Test public void find() { GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").build(); when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())) .thenReturn( newArrayList( new GroupMembershipDto() .setId(1L) .setName("users") .setDescription("Users group") .setUserId(100L))); GroupMembershipFinder.Membership result = finder.find(query); assertThat(result.groups()).hasSize(1); assertThat(result.hasMoreResults()).isFalse(); GroupMembership group = result.groups().get(0); assertThat(group.id()).isEqualTo(1); assertThat(group.name()).isEqualTo("users"); assertThat(group.description()).isEqualTo("Users group"); assertThat(group.isMember()).isTrue(); }
public GroupMembershipQueryResult find(Map<String, Object> params) { return finder.find(parseQuery(params)); }