RequestScopedMdc { public static void copy(RequestContext ctx, String key) { requireNonNull(ctx, "ctx"); requireNonNull(key, "key"); checkState(delegate != null, ERROR_MESSAGE); put(ctx, key, delegate.get(key)); } private  RequestScopedMdc(); @Nullable static String get(RequestContext ctx, String key); static Map<String, String> getAll(RequestContext ctx); static void put(RequestContext ctx, String key, @Nullable String value); static void putAll(RequestContext ctx, Map<String, String> map); static void copy(RequestContext ctx, String key); static void copyAll(RequestContext ctx); static void remove(RequestContext ctx, String key); static void clear(RequestContext ctx);  }
@Test void copy() { final ServiceRequestContext ctx = newContext(); MDC.put("foo", "1"); MDC.put("bar", "2"); RequestScopedMdc.copy(ctx, "foo"); assertThat(RequestScopedMdc.getAll(ctx)).containsOnly(Maps.immutableEntry("foo", "1")); }