### Question:
ContextExecutorService { protected List<Future<?>> getFuturesOfContext(UUID contextUuid) { List<Future<?>> futures = tasks.get(contextUuid); if (futures == null) { synchronized (tasks) { futures = tasks.get(contextUuid); if (futures == null) { futures = new ArrayList<Future<?>>(); tasks.put(contextUuid, futures); } } } return futures; }  Future<T> runWithContext(UUID contextUuid, final Callable<T> callable); void cancelContext(UUID contextUuid);  }### Answer:
@Test public void getFuturesOfContext_contextExist_expectedList(){ final UUID contextUuid = UUID.randomUUID(); final ArrayList<Future<?>> expectedRsult = new ArrayList<Future<?>>(); doReturn(expectedRsult).when(tasks).get(contextUuid); final List<Future<?>> result = spy.getFuturesOfContext(contextUuid); assertSame(result, expectedRsult); }
@Test public void getFuturesOfContext_noContext_newList(){ final UUID contextUuid = UUID.randomUUID(); doReturn(null).when(tasks).get(contextUuid); final List<Future<?>> result = spy.getFuturesOfContext(contextUuid); assertNotNull(result); assertTrue(result.isEmpty()); verify(tasks).put(contextUuid, result); }