### Question:
NacosServiceDiscovery { public List<ServiceInstance> getInstances(String serviceId) throws NacosException { String group = discoveryProperties.getGroup(); List<Instance> instances = namingService().selectInstances(serviceId, group, true); return hostToServiceInstanceList(instances, serviceId); } NacosServiceDiscovery(NacosDiscoveryProperties discoveryProperties,
			NacosServiceManager nacosServiceManager); List<ServiceInstance> getInstances(String serviceId); List<String> getServices(); static List<ServiceInstance> hostToServiceInstanceList(
			List<Instance> instances, String serviceId); static ServiceInstance hostToServiceInstance(Instance instance,
			String serviceId);  }### Answer:
@Test public void testGetInstances() throws NacosException { ArrayList<Instance> instances = new ArrayList<>(); HashMap<String, String> map = new HashMap<>(); map.put("test-key", "test-value"); map.put("secure", "true"); instances.add(serviceInstance(serviceName, true, host, port, map)); NacosDiscoveryProperties nacosDiscoveryProperties = mock( NacosDiscoveryProperties.class); NacosServiceManager nacosServiceManager = mock(NacosServiceManager.class); NamingService namingService = mock(NamingService.class); when(nacosServiceManager .getNamingService(nacosDiscoveryProperties.getNacosProperties())) .thenReturn(namingService); when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT"); when(namingService.selectInstances(eq(serviceName), eq("DEFAULT"), eq(true))) .thenReturn(instances); NacosServiceDiscovery serviceDiscovery = new NacosServiceDiscovery( nacosDiscoveryProperties, nacosServiceManager); List<ServiceInstance> serviceInstances = serviceDiscovery .getInstances(serviceName); assertThat(serviceInstances.size()).isEqualTo(1); ServiceInstance serviceInstance = serviceInstances.get(0); assertThat(serviceInstance.getServiceId()).isEqualTo(serviceName); assertThat(serviceInstance.getHost()).isEqualTo(host); assertThat(serviceInstance.getPort()).isEqualTo(port); assertThat(serviceInstance.isSecure()).isEqualTo(true); assertThat(serviceInstance.getUri().toString()) .isEqualTo(getUri(serviceInstance)); assertThat(serviceInstance.getMetadata().get("test-key")).isEqualTo("test-value"); }