### Question:
CachedLibrarian implements ConnectionLibrarian<CachedConnection> { @Override public CachedConnection checkOut(final String username, final String password, final URI serverAddress) { final String id = idGenerator.buildKey(username, password, serverAddress); return retrieveCachedConnection(id, new UserPasswordCreator(username, password, serverAddress, this)); } CachedLibrarian(final IdentifierGenerator idGenerator, final Cache cache); @Override void checkIn(final CachedConnection connection); @Override CachedConnection checkOut(final String username, final String password, final URI serverAddress); @Override CachedConnection checkOut(final String username, final String salt, final URI privateKeyLocation,
            final URI serverAddress);  }### Answer:
@Test public void testCheckOutCached() { final CachedConnection cachedConnection = mock(CachedConnection.class); cachedConnections.add(cachedConnection); assertThat(librarian.checkOut(USERNAME, PASSWORD, SERVER_ADDRESS)).isEqualTo(cachedConnection); }
@Test public void testCheckOutNotCached() { assertThat(librarian.checkOut(USERNAME, PASSWORD, SERVER_ADDRESS)).isEqualTo(defaultConnection); }
@Test public void testCheckOutMultiple() { final CachedConnection cachedConnection = mock(CachedConnection.class); cachedConnections.add(cachedConnection); assertThat(librarian.checkOut(USERNAME, PASSWORD, SERVER_ADDRESS)).isEqualTo(cachedConnection); assertThat(librarian.checkOut(USERNAME, PASSWORD, SERVER_ADDRESS)).isEqualTo(defaultConnection); }