@Override
    public Optional<ServiceInstance> choose(String serviceName, List<ServiceInstance> instances) {
        if (instances == null || instances.isEmpty()) {
            return Optional.empty();
        }
        if (instances.size() == 1) {
            return Optional.ofNullable(instances.get(0));
        }
        return Optional.ofNullable(doChoose(serviceName, instances));
    }
@Test
    public void choose() {
        final AbstractLoadbalancer roundRobinLoadbalancer = new RoundRobinLoadbalancer();
        final Optional<ServiceInstance> choose = roundRobinLoadbalancer.choose(null, null);
        Assert.assertFalse(choose.isPresent());

        // Test an instance
        final List<ServiceInstance> serviceInstances = Collections.singletonList(build());
        final Optional<ServiceInstance> test = roundRobinLoadbalancer.choose("test", serviceInstances);
        Assert.assertTrue(test.isPresent());
        Assert.assertEquals(test.get(), serviceInstances.get(0));

        // Test multiple instances
        final List<ServiceInstance> serviceInstances1 = Arrays.asList(build(), build());
        final Optional<ServiceInstance> instance = roundRobinLoadbalancer.choose("name", serviceInstances1);
        Assert.assertTrue(instance.isPresent());
        Assert.assertTrue(serviceInstances1.contains(instance.get()));
    }