CompositeCodec implements Codec<T> { @Override public JaegerSpanContext extract(T carrier) { for (Codec<T> codec : codecs) { JaegerSpanContext context = codec.extract(carrier); if (context != null) { return context; } } return null; } CompositeCodec(List<Codec<T>> codecs); @Override void inject(JaegerSpanContext spanContext, T carrier); @Override JaegerSpanContext extract(T carrier); @Override String toString();  }
@Test public void testExtractFromFirstCodec() { when(mockCodec1.extract(mockCarrier)).thenReturn(mockContext); CompositeCodec<TextMap> composite = new CompositeCodec<TextMap>(Arrays.asList(mockCodec1, mockCodec2)); assertEquals(mockContext, composite.extract(mockCarrier)); verify(mockCodec1, times(1)).extract(mockCarrier); verify(mockCodec2, times(0)).extract(mockCarrier); }
@Test public void testExtractFromSecondCodec() { when(mockCodec2.extract(mockCarrier)).thenReturn(mockContext); CompositeCodec<TextMap> composite = new CompositeCodec<TextMap>(Arrays.asList(mockCodec1, mockCodec2)); assertEquals(mockContext, composite.extract(mockCarrier)); verify(mockCodec1, times(1)).extract(mockCarrier); verify(mockCodec2, times(1)).extract(mockCarrier); }
@Test public void testExtractFromNoCodec() { CompositeCodec<TextMap> composite = new CompositeCodec<TextMap>(Arrays.asList(mockCodec1, mockCodec2)); assertNull(composite.extract(mockCarrier)); verify(mockCodec1, times(1)).extract(mockCarrier); verify(mockCodec2, times(1)).extract(mockCarrier); }