public SearchResults<GroupInformation> search(DbSession dbSession, GroupSearchRequest groupSearchRequest) {
    GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession);
    GroupQuery query = toGroupQuery(groupSearchRequest);

    int limit = dbClient.groupDao().countByQuery(dbSession, query);
    if (groupSearchRequest.page() == 0) {
      return new SearchResults<>(List.of(), limit);
    }

    List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, query, groupSearchRequest.page(), groupSearchRequest.pageSize());
    List<String> groupUuids = extractGroupUuids(groups);
    Map<String, Boolean> groupUuidToIsManaged = managedInstanceService.getGroupUuidToManaged(dbSession, new HashSet<>(groupUuids));

    List<GroupInformation> results = groups.stream()
      .map(groupDto -> toGroupInformation(groupDto, defaultGroup.getUuid(), groupUuidToIsManaged))
      .toList();

    return new SearchResults<>(results, limit);
  }
@Test
  public void search_whenSeveralGroupFound_returnsThem() {
    GroupDto groupDto1 = mockGroupDto("1");
    GroupDto groupDto2 = mockGroupDto("2");
    GroupDto defaultGroup = mockDefaultGroup();

    when(dbClient.groupDao().selectByQuery(eq(dbSession), queryCaptor.capture(), eq(5), eq(24)))
      .thenReturn(List.of(groupDto1, groupDto2, defaultGroup));

    Map<String, Boolean> groupUuidToManaged = Map.of(
      groupDto1.getUuid(), false,
      groupDto2.getUuid(), true,
      defaultGroup.getUuid(), false);
    when(managedInstanceService.getGroupUuidToManaged(dbSession, groupUuidToManaged.keySet())).thenReturn(groupUuidToManaged);

    when(dbClient.groupDao().countByQuery(eq(dbSession), any())).thenReturn(300);

    SearchResults<GroupInformation> searchResults = groupService.search(dbSession, new GroupSearchRequest("query", null, 5, 24));
    assertThat(searchResults.total()).isEqualTo(300);

    Map<String, GroupInformation> uuidToGroupInformation = searchResults.searchResults().stream()
      .collect(Collectors.toMap(groupInformation -> groupInformation.groupDto().getUuid(), identity()));
    assertGroupInformation(uuidToGroupInformation, groupDto1, false, false);
    assertGroupInformation(uuidToGroupInformation, groupDto2, true, false);
    assertGroupInformation(uuidToGroupInformation, defaultGroup, false, true);

    assertThat(queryCaptor.getValue().getSearchText()).isEqualTo("%QUERY%");
    assertThat(queryCaptor.getValue().getIsManagedSqlClause()).isNull();
  }