### Question:
NewRelicTokenInjectorFilter implements WebFilter { @Override @Trace(async = true) public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { return chain.filter(exchange) .subscriberContext(context -> { Transaction transaction = agent.getTransaction(); transaction.getTracedMethod().setMetricName("Reactor"); Token token = transaction.getToken(); token.link(); Context updatedContext = context .put(TRANSACTION_CONTEXT_KEY, transaction) .put(TOKEN_CONTEXT_KEY, token); return updatedContext; }); } NewRelicTokenInjectorFilter(Agent agent); @Override @Trace(async = true) Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain); static Optional<Token> getToken(Context context); static Optional<Transaction> getTransaction(Context context); static final String TRANSACTION_CONTEXT_KEY; static final String TOKEN_CONTEXT_KEY; }### Answer:
@Test public void filter() { NewRelicTokenInjectorFilter uut = new NewRelicTokenInjectorFilter(agent); when(chain.filter(exchange)).thenReturn(Mono.just("Void").then()); when(agent.getTransaction()).thenReturn(transaction); when(transaction.getToken()).thenReturn(token); when(transaction.getTracedMethod()).thenReturn(tracedMethod); Mono<Void> source = uut.filter(exchange, chain); StepVerifier.create(source) .expectAccessibleContext() .contains(NewRelicTokenInjectorFilter.TRANSACTION_CONTEXT_KEY, transaction) .contains(NewRelicTokenInjectorFilter.TOKEN_CONTEXT_KEY, token) .then() .expectComplete() .verify(); verify(chain).filter(exchange); verify(agent).getTransaction(); verify(transaction).getToken(); verify(transaction).getTracedMethod(); verify(tracedMethod).setMetricName("Reactor"); verify(token).link(); }