### Question:
ContextsManager { public Object executeQueryForMetadata(UUID uuid, final Object query) { jrsBeanValidator.validate(query); final ContextDataPair contextDataPair = contextDataStorage.get(uuid); final Object context = contextDataPair.getContext(); final ContextQueryExecutor<Object, Object> queryExecutor = getQueryExecutor(query, context); return callAndGet(uuid, new Callable<Object>() { @Override public Object call() throws Exception { if(log.isDebugEnabled())log.debug("Starting of query execution for metadata. Context " + context.toString()); final Object result = queryExecutor.executeQueryForMetadata(query, context, contextDataPair.getData()); if(log.isDebugEnabled())log.debug("Query execution for metadata is completed. Context " + context.toString()); return result; } }); }  Class<?> getContextDescriptionClass(String contextType); Class<?> getQueryClass(String queryType); Class<?> getMetadataParamsClass(String paramsType); UUID createContext(Object contextDescription); boolean isMetadataSupported(Object contextDescription, String metadataClientType); String getMetadataClientResourceType(Object contextDescription); Object getContext(UUID uuid, Map<String, String[]> additionalProperties); void removeContext(UUID uuid); @SuppressWarnings("unchecked") Object getContextMetadata(UUID uuid, final Map<String, String[]> options); Object getContextMetadata(UUID uuid, Object metadataParams); Object executeQuery(UUID uuid, final Object query, final Map<String, String[]> queryParameters); Object executeQueryForMetadata(UUID uuid, final Object query); @PostConstruct void afterPropertiesSet(); @PostConstruct void initMetadataParamsTypes();  }### Answer:
@Test public void executeQueryForMetadata() throws Exception { final UUID uuid = UUID.randomUUID(); final Object query = new Object(); final Object context = new Object(); final HashMap<String, Object> data = new HashMap<String, Object>(); when(contextDataStorage.get(uuid)).thenReturn(new ContextDataPair(context, data)); final ContextQueryExecutor queryExecutor = mock(ContextQueryExecutor.class); doReturn(queryExecutor).when(spy).getQueryExecutor(query, context); final Object queryExecutorResult = new Object(); doReturn(queryExecutorResult).when(queryExecutor).executeQueryForMetadata(query, context, data); final ArgumentCaptor<Callable> callableCaptor = ArgumentCaptor.forClass(Callable.class); final Object expectedResult = new Object(); doReturn(expectedResult).when(spy).callAndGet(same(uuid), callableCaptor.capture()); final Object result = spy.executeQueryForMetadata(uuid, query); assertSame(result, expectedResult); verify(jrsBeanValidator).validate(query); verify(queryExecutor, never()).executeQueryForMetadata(anyObject(), anyObject(), anyMap()); final Callable callable = callableCaptor.getValue(); assertSame(callable.call(), queryExecutorResult); }