### Question:
ClientConnection extends AbstractBlobStoreConnection { @Override public Blob getBlob(URI blobId, Map<String, String> hints) throws IOException { ensureOpen(); return new ClientBlob(this, streamManager, remote.getBlob(blobId, hints)); } ClientConnection(BlobStore store, StreamManager strMgr, RemoteConnection con); @Override void close(); @Override Blob getBlob(URI blobId, Map<String, String> hints); @Override Blob getBlob(InputStream in, long estimatedSize, Map<String, String> hints); @Override Iterator<URI> listBlobIds(String filterPrefix); @Override void sync(); static int ITERATOR_BATCH_SIZE; }### Answer:
@Test public void testGetBlobInputStreamLongMapOfStringString() throws IOException { InputStream in = new ByteArrayInputStream(new byte[0]); URI id = URI.create("foo:bar"); Map<String, String> hints = new HashMap<String, String>(); hints.put("try harder?", "yes, of course!"); Blob blob = createMock(Blob.class); expect(blob.getId()).andStubReturn(id); makeThreadSafe(blob, true); replay(blob); reset(con); expect(con.getBlob(isA(PipedInputStream.class), eq(42L), eq(hints))).andReturn(blob); expect(con.getBlob(isA(PipedInputStream.class), eq(-1L), eq(hints))) .andThrow(new UnsupportedOperationException()); makeThreadSafe(con, true); replay(con); Blob cb = cc.getBlob(in, 42L, hints); assertTrue(cb instanceof ClientBlob); assertEquals(blob.getId(), cb.getId()); try { cc.getBlob(in, -1L, hints); fail("Failed to rcv expected exception"); } catch (UnsupportedOperationException e) { } verify(con); }
@Test public void testGetBlobURIMapOfStringString() throws IOException { URI id = URI.create("foo:bar"); Map<String, String> hints = new HashMap<String, String>(); hints.put("try harder?", "yes, of course!"); Blob blob = createMock(Blob.class); expect(blob.getId()).andStubReturn(id); makeThreadSafe(blob, true); replay(blob); reset(con); expect(con.getBlob(id, hints)).andReturn(blob); expect(con.getBlob(id, hints)).andThrow(new UnsupportedIdException(id)); makeThreadSafe(con, true); replay(con); Blob rb = cc.getBlob(id, hints); assertTrue(rb instanceof ClientBlob); assertEquals(blob.getId(), rb.getId()); try { cc.getBlob(id, hints); fail("Failed to rcv expected exception"); } catch (UnsupportedIdException e) { assertEquals(id, e.getBlobId()); } verify(con); }