### Question:
ApimlLoadBalancer extends ZoneAwareLoadBalancer<T> { @Override public Server chooseServer(Object key) { Server server = super.chooseServer(key); if (server == null) { return null; } if (server instanceof DiscoveryEnabledServer) { RequestContextUtils.setInstanceInfo(((DiscoveryEnabledServer) server).getInstanceInfo()); RequestContextUtils.addDebugInfo("Load Balancer chooses: " + ((DiscoveryEnabledServer) server).getInstanceInfo()); } else { throw new IllegalStateException("Unexpected error, please contact Broadcom support"); } return server; } ApimlLoadBalancer(
        IClientConfig clientConfig,
        IRule rule,
        IPing ping,
        ServerList<T> serverList,
        ServerListFilter<T> filter,
        ServerListUpdater serverListUpdater,
        LoadBalancerRegistry loadBalancerRegistry
    ); @Override Server chooseServer(Object key); static final String LOADBALANCED_INSTANCE_INFO_KEY; }### Answer:
@Test void givenNoServerList_whenChooseServer_thenSetNothing() { underTest.chooseServer("anotherInstance"); RequestContext context = RequestContext.getCurrentContext(); assertThat(context.get(ApimlLoadBalancer.LOADBALANCED_INSTANCE_INFO_KEY), is(nullValue())); }
@Test void givenServerList_whenChooseServer_thenSetChosenInstanceInfoToRequestContext() { InstanceInfo info = InstanceInfo.Builder.newBuilder() .setAppName("appname") .setInstanceId("instance") .build(); underTest.addServer(new DiscoveryEnabledServer(info, true)); underTest.chooseServer("instance"); RequestContext context = RequestContext.getCurrentContext(); assertThat(context.get(ApimlLoadBalancer.LOADBALANCED_INSTANCE_INFO_KEY), is(info)); }
@Test void givenUnexpectedServerImplementation_whenChooseServer_thenFailFast() { underTest.addServer(new Server("localhost", 69)); assertThrows(IllegalStateException.class, () -> underTest.chooseServer("instance")); }