@Test
  public void testFromCache() throws IOException {
    WSLoaderResult<ByteSource> res =
        new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true);
    when(wsLoader.loadSource(anyString())).thenReturn(res);
    MutableBoolean fromCache = new MutableBoolean();
    userRepo.load("", fromCache);
    assertThat(fromCache.booleanValue()).isTrue();

    fromCache.setValue(false);
    userRepo.load(ImmutableList.of("user"), fromCache);
    assertThat(fromCache.booleanValue()).isTrue();
  }
  @Test
  public void testLoadSingleUser() throws IOException {
    WSLoaderResult<ByteSource> res =
        new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true);
    when(wsLoader.loadSource("/batch/users?logins=fmallet")).thenReturn(res);

    assertThat(userRepo.load("fmallet").getName()).isEqualTo("Freddy Mallet");
  }
  @Test
  public void testLoad() throws IOException {
    Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet", "sbrandhof", "Simon");
    WSLoaderResult<ByteSource> res = new WSLoaderResult<>(createUsersMock(userMap), true);
    when(wsLoader.loadSource("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res);

    assertThat(userRepo.load(Arrays.asList("fmallet", "sbrandhof")))
        .extracting("login", "name")
        .containsOnly(tuple("fmallet", "Freddy Mallet"), tuple("sbrandhof", "Simon"));
  }
  @Test
  public void testInputStreamError() throws IOException {
    ByteSource source = mock(ByteSource.class);

    WSLoaderResult<ByteSource> res = new WSLoaderResult<>(source, true);

    when(wsLoader.loadSource("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res);

    InputStream errorInputStream = mock(InputStream.class);
    Mockito.doThrow(IOException.class).when(errorInputStream).read();
    when(source.openStream()).thenReturn(errorInputStream);

    exception.expect(IllegalStateException.class);
    exception.expectMessage("Unable to get user details from server");

    userRepo.load(Arrays.asList("fmallet", "sbrandhof"));
  }