ModulesService { public boolean moduleHaveInstance(String moduleName) { Application application = discoveryClient.getApplication(moduleName.concat("-service").toUpperCase()); return application != null && !application.getInstances().isEmpty(); } ModulesService(EurekaClient discoveryClient); boolean moduleHaveInstance(String moduleName); List<Application> activeBusinessApplications(); String extractServiceName(String serviceName);  }
@Test public void moduleHaveInstance() { ReflectionTestUtils.setField(this.instanceInfo, "appName", "pes-service"); List<InstanceInfo> instances = new ArrayList<>(); instances.add(this.instanceInfo); given(discoveryClient.getApplication(matches("PES-SERVICE"))).willReturn(application); given(application.getInstances()).willReturn(instances); boolean moduleHaveInstance = modulesService.moduleHaveInstance("pes"); Assert.assertTrue(moduleHaveInstance); }
@Test public void moduleNotHaveInstance() { List<InstanceInfo> instances = new ArrayList<>(); given(discoveryClient.getApplication(matches("PES-SERVICE"))).willReturn(application); given(application.getInstances()).willReturn(instances); boolean moduleHaveInstance = modulesService.moduleHaveInstance("pes"); Assert.assertFalse(moduleHaveInstance); }