Migrate to assertj (#4512)
* migrate from junit/jupiter assertions to assertj in a few remaining places. * reorder
This commit is contained in:
parent
f10959cd85
commit
83bfb84d14
|
|
@ -6,7 +6,7 @@
|
|||
package io.opentelemetry.context.propagation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
@ -51,9 +51,8 @@ class MultiTextMapPropagatorTest {
|
|||
|
||||
@Test
|
||||
void addPropagator_null() {
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> new MultiTextMapPropagator((List<TextMapPropagator>) null));
|
||||
assertThatThrownBy(() -> new MultiTextMapPropagator((List<TextMapPropagator>) null))
|
||||
.isInstanceOf(NullPointerException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -82,7 +81,7 @@ class MultiTextMapPropagatorTest {
|
|||
when(propagator2.fields()).thenReturn(Arrays.asList("buggy", "bumpers"));
|
||||
TextMapPropagator prop = new MultiTextMapPropagator(propagator1, propagator2);
|
||||
Collection<String> fields = prop.fields();
|
||||
assertThrows(UnsupportedOperationException.class, () -> fields.add("hi"));
|
||||
assertThatThrownBy(() -> fields.add("hi")).isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ package io.opentelemetry.exporter.jaeger;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.linecorp.armeria.server.ServerBuilder;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.extension.trace.propagation;
|
|||
|
||||
import static io.opentelemetry.extension.trace.propagation.B3Propagator.DEBUG_CONTEXT_KEY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.opentelemetry.api.internal.StringUtils;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
|
|
@ -644,7 +643,7 @@ class B3PropagatorTest {
|
|||
.isEqualTo(
|
||||
SpanContext.createFromRemoteParent(
|
||||
TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()));
|
||||
assertTrue(context.get(DEBUG_CONTEXT_KEY));
|
||||
assertThat(context.get(DEBUG_CONTEXT_KEY)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -659,7 +658,7 @@ class B3PropagatorTest {
|
|||
.isEqualTo(
|
||||
SpanContext.createFromRemoteParent(
|
||||
TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()));
|
||||
assertTrue(context.get(DEBUG_CONTEXT_KEY));
|
||||
assertThat(context.get(DEBUG_CONTEXT_KEY)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -675,7 +674,7 @@ class B3PropagatorTest {
|
|||
.isEqualTo(
|
||||
SpanContext.createFromRemoteParent(
|
||||
TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()));
|
||||
assertTrue(context.get(DEBUG_CONTEXT_KEY));
|
||||
assertThat(context.get(DEBUG_CONTEXT_KEY)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -691,7 +690,7 @@ class B3PropagatorTest {
|
|||
.isEqualTo(
|
||||
SpanContext.createFromRemoteParent(
|
||||
TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()));
|
||||
assertTrue(context.get(DEBUG_CONTEXT_KEY));
|
||||
assertThat(context.get(DEBUG_CONTEXT_KEY)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@
|
|||
|
||||
package io.opentelemetry.sdk.autoconfigure;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
|
@ -39,8 +37,8 @@ public class SpiUtilTest {
|
|||
SpiUtilTest.class.getClassLoader(),
|
||||
mockFinder);
|
||||
|
||||
assertNotNull(spiProvider.getByName(SpiExampleProviderImplementation.NAME));
|
||||
assertNull(spiProvider.getByName("invalid-provider"));
|
||||
assertThat(spiProvider.getByName(SpiExampleProviderImplementation.NAME)).isNotNull();
|
||||
assertThat(spiProvider.getByName("invalid-provider")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -82,7 +80,7 @@ public class SpiUtilTest {
|
|||
|
||||
SpiExample first = spiProvider.getByName(SpiExampleProviderImplementation.NAME);
|
||||
SpiExample second = spiProvider.getByName(SpiExampleProviderImplementation.NAME);
|
||||
assertEquals(first, second);
|
||||
assertThat(second).isEqualTo(first);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -104,10 +102,9 @@ public class SpiUtilTest {
|
|||
SpiUtilTest.class.getClassLoader(),
|
||||
mockFinder);
|
||||
|
||||
assertThrows(
|
||||
RuntimeException.class,
|
||||
() -> spiProvider.getByName("init-failure-example"),
|
||||
exceptionMessage);
|
||||
assertThatThrownBy(() -> spiProvider.getByName("init-failure-example"))
|
||||
.withFailMessage(exceptionMessage)
|
||||
.isInstanceOf(RuntimeException.class);
|
||||
}
|
||||
|
||||
private interface SpiExampleProvider {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.extension.jfr;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.Tracer;
|
||||
|
|
@ -69,15 +69,14 @@ class JfrSpanProcessorTest {
|
|||
}
|
||||
|
||||
List<RecordedEvent> events = RecordingFile.readAllEvents(output);
|
||||
assertEquals(1, events.size());
|
||||
events.stream()
|
||||
.forEach(
|
||||
e -> {
|
||||
assertEquals(span.getSpanContext().getTraceId(), e.getValue("traceId"));
|
||||
assertEquals(span.getSpanContext().getSpanId(), e.getValue("spanId"));
|
||||
assertEquals(OPERATION_NAME, e.getValue("operationName"));
|
||||
});
|
||||
|
||||
assertThat(events).hasSize(1);
|
||||
assertThat(events)
|
||||
.extracting(e -> e.getValue("traceId"))
|
||||
.isEqualTo(span.getSpanContext().getTraceId());
|
||||
assertThat(events)
|
||||
.extracting(e -> e.getValue("spanId"))
|
||||
.isEqualTo(span.getSpanContext().getSpanId());
|
||||
assertThat(events).extracting(e -> e.getValue("operationName")).isEqualTo(OPERATION_NAME);
|
||||
} finally {
|
||||
Files.delete(output);
|
||||
}
|
||||
|
|
@ -109,16 +108,17 @@ class JfrSpanProcessorTest {
|
|||
}
|
||||
|
||||
List<RecordedEvent> events = RecordingFile.readAllEvents(output);
|
||||
assertEquals(2, events.size());
|
||||
events.stream()
|
||||
.forEach(
|
||||
e -> {
|
||||
assertEquals(span.getSpanContext().getTraceId(), e.getValue("traceId"));
|
||||
assertEquals(span.getSpanContext().getSpanId(), e.getValue("spanId"));
|
||||
if ("Span".equals(e.getEventType().getLabel())) {
|
||||
assertEquals(OPERATION_NAME, e.getValue("operationName"));
|
||||
}
|
||||
});
|
||||
assertThat(events).hasSize(2);
|
||||
assertThat(events)
|
||||
.extracting(e -> e.getValue("traceId"))
|
||||
.isEqualTo(span.getSpanContext().getTraceId());
|
||||
assertThat(events)
|
||||
.extracting(e -> e.getValue("spanId"))
|
||||
.isEqualTo(span.getSpanContext().getSpanId());
|
||||
assertThat(events)
|
||||
.filteredOn(e -> "Span".equals(e.getEventType().getLabel()))
|
||||
.extracting(e -> e.getValue("operationName"))
|
||||
.isEqualTo(OPERATION_NAME);
|
||||
|
||||
} finally {
|
||||
Files.delete(output);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.logs.data;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
@ -33,7 +32,7 @@ class LogDataBuilderTest {
|
|||
LogDataBuilder builder = LogDataBuilder.create(resource, scopeInfo, clock);
|
||||
|
||||
LogData result = builder.build();
|
||||
assertEquals(12L, result.getEpochNanos());
|
||||
assertThat(result.getEpochNanos()).isEqualTo(12L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -41,14 +40,14 @@ class LogDataBuilderTest {
|
|||
LogDataBuilder builder = LogDataBuilder.create(resource, scopeInfo);
|
||||
SpanContext spanContext = mock(SpanContext.class);
|
||||
LogData result = builder.setSpanContext(spanContext).build();
|
||||
assertSame(spanContext, result.getSpanContext());
|
||||
assertThat(result.getSpanContext()).isSameAs(spanContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setSpanContext_nullSafe() {
|
||||
LogDataBuilder builder = LogDataBuilder.create(resource, scopeInfo);
|
||||
LogData result = builder.setSpanContext(null).build();
|
||||
assertSame(SpanContext.getInvalid(), result.getSpanContext());
|
||||
assertThat(result.getSpanContext()).isSameAs(SpanContext.getInvalid());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -65,6 +64,6 @@ class LogDataBuilderTest {
|
|||
LogDataBuilder builder = LogDataBuilder.create(resource, scopeInfo);
|
||||
|
||||
LogData result = builder.setContext(context).build();
|
||||
assertSame(spanContext, result.getSpanContext());
|
||||
assertThat(result.getSpanContext()).isSameAs(spanContext);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ package io.opentelemetry.sdk.metrics.internal.aggregator;
|
|||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.internal.state.ExponentialCounterFactory;
|
||||
import io.opentelemetry.sdk.testing.assertj.MetricAssertions;
|
||||
|
|
@ -79,18 +77,18 @@ class DoubleExponentialHistogramBucketsTest {
|
|||
DoubleExponentialHistogramBuckets b = buckets.newBuckets();
|
||||
|
||||
assertThat(a).isNotNull();
|
||||
assertEquals(a, b);
|
||||
assertEquals(b, a);
|
||||
assertThat(b).isEqualTo(a);
|
||||
assertThat(a).isEqualTo(b);
|
||||
assertThat(a).hasSameHashCodeAs(b);
|
||||
|
||||
a.record(1);
|
||||
assertNotEquals(a, b);
|
||||
assertNotEquals(b, a);
|
||||
assertThat(a).isNotEqualTo(b);
|
||||
assertThat(b).isNotEqualTo(a);
|
||||
assertThat(a).doesNotHaveSameHashCodeAs(b);
|
||||
|
||||
b.record(1);
|
||||
assertEquals(a, b);
|
||||
assertEquals(b, a);
|
||||
assertThat(b).isEqualTo(a);
|
||||
assertThat(a).isEqualTo(b);
|
||||
assertThat(a).hasSameHashCodeAs(b);
|
||||
|
||||
// Now we start to play with altering offset, but having same effective counts.
|
||||
|
|
|
|||
Loading…
Reference in New Issue