### Question:
PackDubboConsumerFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (omegaContext != null) { invocation.getAttachments().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId()); invocation.getAttachments().put(LOCAL_TX_ID_KEY, omegaContext.localTxId()); } if (omegaContext != null && omegaContext.globalTxId() != null) { LOG.debug("Added {} {} and {} {} to dubbo invocation", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(), LOCAL_TX_ID_KEY, omegaContext.localTxId()}); } else { LOG.debug("Cannot inject transaction ID, as the OmegaContext is null or cannot get the globalTxId."); } if (invoker != null) { return invoker.invoke(invocation); } return null; }  void setOmegaContext(OmegaContext omegaContext); Result invoke(Invoker<?> invoker, Invocation invocation);  }### Answer:
@Test public void keepHeaderUnchangedIfContextAbsent() { when(invocation.getAttachment(OmegaContext.GLOBAL_TX_ID_KEY)).thenReturn(null); when(invocation.getAttachment(OmegaContext.LOCAL_TX_ID_KEY)).thenReturn(null); filter.invoke(null, invocation); assertThat(invocation.getAttachments().isEmpty(), is(true)); }
@Test public void interceptTransactionIdInHeaderIfContextPresent() { omegaContext.setGlobalTxId(globalTxId); omegaContext.setLocalTxId(localTxId); Map<String, String> attachMents = new HashMap<>(); when(invocation.getAttachments()).thenReturn(attachMents); filter.invoke(null, invocation); assertThat(invocation.getAttachments().get(OmegaContext.GLOBAL_TX_ID_KEY), is(globalTxId)); assertThat(invocation.getAttachments().get(OmegaContext.LOCAL_TX_ID_KEY), is(localTxId)); }