Tag { public final void tag(I input, ScopedSpan span) { if (input == null) throw new NullPointerException("input == null"); if (span == null) throw new NullPointerException("span == null"); if (span.isNoop()) return; tag(span, input, span.context()); } protected  Tag(String key); final String key(); @Nullable String value(@Nullable I input, @Nullable TraceContext context); final void tag(I input, ScopedSpan span); final void tag(I input, Span span); final void tag(I input, @Nullable TraceContext context, SpanCustomizer span); final void tag(I input, SpanCustomizer span); final void tag(I input, @Nullable TraceContext context, MutableSpan span); @Override String toString();  }
@Test public void tag_span() { when(parseValue.apply(input, context)).thenReturn("value"); tag.tag(input, span); verify(span).context(); verify(span).isNoop(); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verify(span).tag("key", "value"); verifyNoMoreInteractions(span); }
@Test public void tag_span_empty() { when(parseValue.apply(input, context)).thenReturn(""); tag.tag(input, span); verify(span).context(); verify(span).isNoop(); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verify(span).tag("key", ""); verifyNoMoreInteractions(span); }
@Test public void tag_span_ignoredErrorParsing() { when(parseValue.apply(input, context)).thenThrow(new Error()); tag.tag(input, span); verify(span).context(); verify(span).isNoop(); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verifyNoMoreInteractions(span); }
@Test public void tag_scopedSpan() { when(parseValue.apply(input, context)).thenReturn("value"); tag.tag(input, scopedSpan); verify(scopedSpan).isNoop(); verify(scopedSpan).context(); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verify(scopedSpan).tag("key", "value"); verifyNoMoreInteractions(scopedSpan); }
@Test public void tag_scopedSpan_empty() { when(parseValue.apply(input, context)).thenReturn(""); tag.tag(input, scopedSpan); verify(scopedSpan).isNoop(); verify(scopedSpan).context(); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verify(scopedSpan).tag("key", ""); verifyNoMoreInteractions(scopedSpan); }
@Test public void tag_scopedSpan_ignoredErrorParsing() { when(parseValue.apply(input, context)).thenThrow(new Error()); tag.tag(input, scopedSpan); verify(scopedSpan).isNoop(); verify(scopedSpan).context(); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verifyNoMoreInteractions(scopedSpan); }
@Test public void tag_customizer() { when(parseValue.apply(input, null)).thenReturn("value"); tag.tag(input, customizer); verify(parseValue).apply(input, null); verifyNoMoreInteractions(parseValue); verify(customizer).tag("key", "value"); verifyNoMoreInteractions(customizer); }
@Test public void tag_customizer_empty() { when(parseValue.apply(input, null)).thenReturn(""); tag.tag(input, customizer); verify(parseValue).apply(input, null); verifyNoMoreInteractions(parseValue); verify(customizer).tag("key", ""); verifyNoMoreInteractions(customizer); }
@Test public void tag_customizer_doesntParseNoop() { tag.tag(input, context, NoopSpanCustomizer.INSTANCE); verifyNoMoreInteractions(parseValue); }
@Test public void tag_customizer_ignoredErrorParsing() { when(parseValue.apply(input, null)).thenThrow(new Error()); tag.tag(input, customizer); verify(parseValue).apply(input, null); verifyNoMoreInteractions(parseValue); verifyNoMoreInteractions(customizer); }
@Test public void tag_customizer_withNullContext() { when(parseValue.apply(eq(input), isNull())).thenReturn("value"); tag.tag(input, null, customizer); verify(parseValue).apply(input, null); verifyNoMoreInteractions(parseValue); verify(customizer).tag("key", "value"); verifyNoMoreInteractions(customizer); }
@Test public void tag_customizer_withContext() { when(parseValue.apply(input, context)).thenReturn("value"); tag.tag(input, context, customizer); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verify(customizer).tag("key", "value"); verifyNoMoreInteractions(customizer); }
@Test public void tag_customizer_withContext_empty() { when(parseValue.apply(input, context)).thenReturn(""); tag.tag(input, context, customizer); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verify(customizer).tag("key", ""); verifyNoMoreInteractions(customizer); }
@Test public void tag_customizer_withContext_doesntParseNoop() { tag.tag(input, context, NoopSpanCustomizer.INSTANCE); verifyNoMoreInteractions(parseValue); }
@Test public void tag_customizer_withContext_ignoredErrorParsing() { when(parseValue.apply(input, context)).thenThrow(new Error()); tag.tag(input, context, customizer); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); verifyNoMoreInteractions(customizer); }
@Test public void tag_mutableSpan() { when(parseValue.apply(input, context)).thenReturn("value"); tag.tag(input, context, mutableSpan); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); MutableSpan expected = new MutableSpan(); expected.tag("key", "value"); assertThat(mutableSpan).isEqualTo(expected); }
@Test public void tag_mutableSpan_nullContext() { when(parseValue.apply(eq(input), isNull())).thenReturn("value"); tag.tag(input, null, mutableSpan); verify(parseValue).apply(input, null); verifyNoMoreInteractions(parseValue); MutableSpan expected = new MutableSpan(); expected.tag("key", "value"); assertThat(mutableSpan).isEqualTo(expected); }
@Test public void tag_mutableSpan_empty() { when(parseValue.apply(input, context)).thenReturn(""); tag.tag(input, context, mutableSpan); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); MutableSpan expected = new MutableSpan(); expected.tag("key", ""); assertThat(mutableSpan).isEqualTo(expected); }
@Test public void tag_mutableSpan_ignoredErrorParsing() { when(parseValue.apply(input, context)).thenThrow(new Error()); tag.tag(input, context, mutableSpan); verify(parseValue).apply(input, context); verifyNoMoreInteractions(parseValue); assertThat(mutableSpan.isEmpty()).isTrue(); }