@Test public void TimestampedAnnotation_forCurrentTime_works_as_expected() { // given String value = UUID.randomUUID().toString(); // when long beforeMillis = System.currentTimeMillis(); TimestampedAnnotation result = TimestampedAnnotation.forCurrentTime(value); long afterMillis = System.currentTimeMillis(); // then long beforeMicros = TimeUnit.MILLISECONDS.toMicros(beforeMillis); long afterMicros = TimeUnit.MILLISECONDS.toMicros(afterMillis); assertThat(result.getTimestampEpochMicros()).isBetween(beforeMicros, afterMicros); assertThat(result.getValue()).isEqualTo(value); }
TimestampedAnnotation extraAnnotation = TimestampedAnnotation.forCurrentTime(UUID.randomUUID().toString()); List<TimestampedAnnotation> evenMoreAnnotations = Arrays.asList( TimestampedAnnotation.forCurrentTime(UUID.randomUUID().toString()), TimestampedAnnotation.forCurrentTime(UUID.randomUUID().toString()) );
@Test public void equals_returns_false_and_hashCode_different_if_annotations_are_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); fullSpan1.addTimestampedAnnotation(TimestampedAnnotation.forCurrentTime("foo")); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@UseDataProvider("badJsonScenarioDataProvider") @Test public void fromJson_should_return_null_for_garbage_input(BadJsonScenario scenario) { // given: garbage input String garbageInput = scenario.generateBadJson( Span.newBuilder("foo", SpanPurpose.CLIENT) .withTag("footag", "bar") .withTimestampedAnnotations(Arrays.asList( TimestampedAnnotation.forCurrentTime("fooAnnotation"), TimestampedAnnotation.forCurrentTime("barAnnotation") )) .build() ); // when: fromJson is called Span spanFromJson = SpanParser.fromJSON(garbageInput); // then: the return value should be null assertThat(spanFromJson).isNull(); }