### Question:
CachedLibrarian implements ConnectionLibrarian<CachedConnection> { @Override public void checkIn(final CachedConnection connection) { if (!checkedOut.containsKey(connection)) { throw new IllegalArgumentException( "The given connection is either unknown to this librarian or has already been checked in."); } final String cacheKey = checkedOut.get(connection); final Set<Connection> connections = cast(cache.get(cacheKey).getObjectValue()); checkedOut.remove(connection); connections.add(connection); } 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(expected = IllegalArgumentException.class) public void testCheckInNotCheckedOut() { librarian.checkIn(mock(CachedConnection.class)); }
@Test public void testCheckIn() throws Exception { final CachedConnection conn = librarian.checkOut(USERNAME, PASSWORD, SERVER_ADDRESS); librarian.checkIn(conn); assertThat(cachedConnections).contains(conn); }