### Question:
TransactionHandlerInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { if (omegaContext != null) { String globalTxId = request.getHeader(GLOBAL_TX_ID_KEY); if (globalTxId == null) { LOG.debug("no such header: {}", GLOBAL_TX_ID_KEY); } else { omegaContext.setGlobalTxId(globalTxId); omegaContext.setLocalTxId(request.getHeader(LOCAL_TX_ID_KEY)); omegaContext.setCategory(request.getHeader(GLOBAL_TX_CATEGORY_KEY)); } } return true; } TransactionHandlerInterceptor(OmegaContext omegaContext); @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler); @Override void postHandle(HttpServletRequest request, HttpServletResponse response, Object o, ModelAndView mv); @Override void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object o, Exception e);  }### Answer:
@Test public void setUpOmegaContextInTransactionRequest() throws Exception { when(request.getHeader(OmegaContext.GLOBAL_TX_ID_KEY)).thenReturn(globalTxId); when(request.getHeader(OmegaContext.LOCAL_TX_ID_KEY)).thenReturn(localTxId); requestInterceptor.preHandle(request, response, null); assertThat(omegaContext.globalTxId(), is(globalTxId)); assertThat(omegaContext.localTxId(), is(localTxId)); }
@Test public void doNothingInNonTransactionRequest() throws Exception { when(request.getHeader(OmegaContext.GLOBAL_TX_ID_KEY)).thenReturn(null); when(request.getHeader(OmegaContext.LOCAL_TX_ID_KEY)).thenReturn(null); requestInterceptor.preHandle(request, response, null); assertThat(omegaContext.globalTxId(), is(nullValue())); assertThat(omegaContext.localTxId(), is(nullValue())); }