@GetMapping("/apps/authorized")
  public List<OpenAppDTO> findAppsAuthorized(HttpServletRequest request) {
    long consumerId = this.consumerAuthUtil.retrieveConsumerId(request);

    Set<String> appIds = this.consumerService.findAppIdsAuthorizedByConsumerId(consumerId);

    return this.appOpenApiService.getAppsInfo(new ArrayList<>(appIds));
  }
@Test
  public void testFindAppsAuthorized() throws Exception {
    final long consumerId = 123456;
    Mockito.when(this.consumerAuthUtil.retrieveConsumerId(Mockito.any())).thenReturn(consumerId);

    final List<ConsumerRole> consumerRoles = Arrays.asList(
        generateConsumerRoleByRoleId(6),
        generateConsumerRoleByRoleId(7),
        generateConsumerRoleByRoleId(8)
    );
    Mockito.when(this.consumerRoleRepository.findByConsumerId(consumerId))
        .thenReturn(consumerRoles);

    Mockito.when(this.roleRepository.findAllById(Mockito.any())).thenAnswer(invocation -> {
      Set<Role> roles = new HashSet<>();
      Iterable<Long> roleIds = invocation.getArgument(0);
      for (Long roleId : roleIds) {
        if (roleId == 6) {
          roles.add(generateRoleByIdAndRoleName(6, "ModifyNamespace+app1+application+DEV"));
        }
        if (roleId == 7) {
          roles.add(generateRoleByIdAndRoleName(7, "ReleaseNamespace+app1+application+DEV"));
        }
        if (roleId == 8) {
          roles.add(generateRoleByIdAndRoleName(8, "Master+app2"));
        }
      }
      assertEquals(3, roles.size());
      return roles;
    });

    this.mockMvc.perform(MockMvcRequestBuilders.get("/openapi/v1/apps/authorized"))
        .andDo(MockMvcResultHandlers.print())
        .andExpect(MockMvcResultMatchers.status().is2xxSuccessful());

    Mockito.verify(this.consumerRoleRepository, Mockito.times(1)).findByConsumerId(consumerId);
    Mockito.verify(this.roleRepository, Mockito.times(1)).findAllById(Mockito.any());

    ArgumentCaptor<Set<String>> appIdsCaptor = ArgumentCaptor.forClass(Set.class);
    Mockito.verify(this.appService).findByAppIds(appIdsCaptor.capture());
    Set<String> appIds = appIdsCaptor.getValue();
    assertEquals(Sets.newHashSet("app1", "app2"), appIds);
  }