### Question:
RandomLoadBalancer implements LoadBalancer { @Override public ServerStats choose(List<ServerStats> availableServerStats) { int index = random.nextInt(availableServerStats.size()); return availableServerStats.get(index); }  @Override ServerStats choose(List<ServerStats> availableServerStats);  }### Answer:
@Test public void oneAvailableServerTest() { ServerInstance serverInstance = new ServerInstance("dummy","dummy","localhost",false,80,-1); serverInstance.setAvailable(true); ServerStats serverStats = new ServerStats(); serverStats.setServerInstance(serverInstance); RandomLoadBalancer lb = new RandomLoadBalancer(); ServerStats stat = lb.choose(Lists.newArrayList(serverStats)); Assert.assertEquals(stat,serverStats); Assert.assertTrue( stat.getServerInstance().getUrl().startsWith("http: }
@Test public void oneAvailableSecureServerTest() { ServerInstance serverInstance = new ServerInstance("dummy","dummy","localhost",true,80,-1); serverInstance.setAvailable(true); ServerStats serverStats = new ServerStats(); serverStats.setServerInstance(serverInstance); RandomLoadBalancer lb = new RandomLoadBalancer(); ServerStats stat = lb.choose(Lists.newArrayList(serverStats)); Assert.assertEquals(stat,serverStats); Assert.assertTrue( stat.getServerInstance().getUrl().startsWith("https: }
@Test public void oneAvailableWebSocketServerTest() { ServerInstance serverInstance = new ServerInstance("dummy","dummy","localhost",false,-1,81); serverInstance.setAvailable(true); ServerStats serverStats = new ServerStats(); serverStats.setServerInstance(serverInstance); RandomLoadBalancer lb = new RandomLoadBalancer(); ServerStats stat = lb.choose(Lists.newArrayList(serverStats)); Assert.assertEquals(stat,serverStats); }