class RightsService {

    public List<String> getRights() {
        List<String> rights = new ArrayList<>();

        modulesService.activeBusinessApplications().forEach(application -> {
            InstanceInfo instanceInfo = application.getInstances().get(0);
            String serviceName = modulesService.extractServiceName(application.getName());
            try {
                String[] response =
                        restTemplate.getForObject(this.buildRightsEndpointUrl(serviceName), String[].class);
                rights.addAll(Arrays.asList(Objects.requireNonNull(response)));
            } catch(RestClientException e) {
                LOGGER.warn("[getRights] An error occured in module {} : {}", application.getName(), e.getMessage());
            }
        });

        return rights;
    }

}

class RightsServiceTest {

    @SpyBean
    private RightsService rightsService;
    @MockBean
    private ModulesService modulesService;
    @MockBean
    private DiscoveryUtils discoveryUtils;
    @MockBean
    private EurekaClient discoveryClient;
    @Mock
    private InstanceInfo instanceInfo;
    @Mock
    private InstanceInfo instanceInfo1;
    @Mock
    private Application application;
    @Rule
    public WireMockRule wireMockRule;

    @Test
    public void getRights() {

        InstanceInfo instanceInfoActe = this.instanceInfo("acte", "acte-service", "BUSINESS");
        InstanceInfo instanceInfoPes = this.instanceInfo("pes", "pes-service", "BUSINESS");
        InstanceInfo instanceInfoConvocation = this.instanceInfo("convocation", "convocation-service", "BUSINESS");

        Application applicationActe = this.application(instanceInfoActe, "acte-service");
        Application applicationPes = this.application(instanceInfoPes, "pes-service");
        Application applicationConvocation = this.application(instanceInfoConvocation, "convocation-service");


        List<Application> applications = new ArrayList<>();

        applications.add(applicationActe);
        applications.add(applicationPes);
        applications.add(applicationConvocation);

        given(modulesService.activeBusinessApplications()).willReturn(applications);

        List<String> rights = rightsService.getRights();

        Assert.assertEquals(6, rights.size());
    }

}