### Question:
PackDubboProviderFilter implements Filter { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (omegaContext != null) { String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY); if (globalTxId == null) { LOG.debug("Cannot inject transaction ID, no such omega context global id: {}", GLOBAL_TX_ID_KEY); } else { omegaContext.setGlobalTxId(globalTxId); omegaContext.setLocalTxId(invocation.getAttachment(LOCAL_TX_ID_KEY)); LOG.debug("Added {} {} and {} {} to omegaContext", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(), LOCAL_TX_ID_KEY, omegaContext.localTxId()}); } invocation.getAttachments().put(GLOBAL_TX_ID_KEY, null); invocation.getAttachments().put(LOCAL_TX_ID_KEY, null); } else { LOG.debug("Cannot inject transaction ID, as the OmegaContext is null."); } try { if (invoker != null) { return invoker.invoke(invocation); } else { return null; } } finally { if (omegaContext != null) { omegaContext.clear(); } } }  void setOmegaContext(OmegaContext omegaContext); @Override Result invoke(Invoker<?> invoker, Invocation invocation);  }### Answer:
@Test public void setUpOmegaContextInTransactionRequest() { when(invocation.getAttachment(OmegaContext.GLOBAL_TX_ID_KEY)).thenReturn(globalTxId); when(invocation.getAttachment(OmegaContext.LOCAL_TX_ID_KEY)).thenReturn(localTxId); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { assertThat(omegaContext.globalTxId(), is(globalTxId)); assertThat(omegaContext.localTxId(), is(localTxId)); return null; } }).when(invoker).invoke(invocation); filter.invoke(invoker, invocation); assertThat(omegaContext.globalTxId(), is(nullValue())); assertThat(omegaContext.localTxId(), is(nullValue())); }
@Test public void doNothingInNonTransactionRequest() { when(invocation.getAttachment(OmegaContext.GLOBAL_TX_ID_KEY)).thenReturn(null); when(invocation.getAttachment(OmegaContext.LOCAL_TX_ID_KEY)).thenReturn(null); filter.invoke(invoker, invocation); assertThat(omegaContext.globalTxId(), is(nullValue())); assertThat(omegaContext.localTxId(), is(nullValue())); }