### Question:
ConcurrentPreloads extends ForwardingCollection<PreloadedData> { ConcurrentPreloads add(Future<PreloadedData> futureData) { tasks.add(futureData); return this; } ConcurrentPreloads();   ConcurrentPreloads(int size);   }### Answer:
@Test public void getDataWithRuntimeException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecution()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertSame(pe.getCause().getClass(), RuntimeException.class); } assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
@Test public void getDataWithPreloadException() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsExecutionWrapped()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); PreloadedData withError = iterator.next(); try { withError.toJson(); fail(); } catch (PreloadException pe) { assertNull(pe.getCause()); } assertEquals(TestFuture.expectedResult("foo"), iterator.next().toJson()); }
@Test(expected = RuntimeException.class) public void getDataThrowsInterruped() throws Exception{ ConcurrentPreloads preloads = new ConcurrentPreloads(); preloads.add(TestFuture.throwsInterrupted()); preloads.add(TestFuture.returnsNormal("foo")); assertEquals(2, preloads.size()); Iterator<PreloadedData> iterator = preloads.iterator(); iterator.next(); }