Migrate assertThrows -> assertThatThrownBy (#2375)

This commit is contained in:
Anuraag Agrawal 2020-12-22 01:57:33 +09:00 committed by GitHub
parent 462f05ae1f
commit 70f665992e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 730 additions and 786 deletions

View File

@ -6,7 +6,7 @@
package io.opentelemetry.api; package io.opentelemetry.api;
import static org.assertj.core.api.Assertions.assertThat; 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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -101,7 +101,8 @@ class OpenTelemetryTest {
@Test @Test
void testTracerNotFound() { void testTracerNotFound() {
System.setProperty(TracerProviderFactory.class.getName(), "io.does.not.exists"); System.setProperty(TracerProviderFactory.class.getName(), "io.does.not.exists");
assertThrows(IllegalStateException.class, () -> GlobalOpenTelemetry.getTracer("testTracer")); assertThatThrownBy(() -> GlobalOpenTelemetry.getTracer("testTracer"))
.isInstanceOf(IllegalStateException.class);
} }
@Test @Test

View File

@ -6,8 +6,8 @@
package io.opentelemetry.api.baggage; package io.opentelemetry.api.baggage;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry; import static org.assertj.core.api.Assertions.entry;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.testing.EqualsTester; import com.google.common.testing.EqualsTester;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
@ -127,7 +127,8 @@ class ImmutableBaggageTest {
@Test @Test
void setParent_nullContext() { void setParent_nullContext() {
assertThrows(NullPointerException.class, () -> Baggage.builder().setParent(null)); assertThatThrownBy(() -> Baggage.builder().setParent(null))
.isInstanceOf(NullPointerException.class);
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.internal; package io.opentelemetry.api.internal;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -15,9 +15,8 @@ class UtilsTest {
@Test @Test
void checkArgument() { void checkArgument() {
Utils.checkArgument(true, TEST_MESSAGE); Utils.checkArgument(true, TEST_MESSAGE);
assertThrows( assertThatThrownBy(() -> Utils.checkArgument(false, TEST_MESSAGE))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> Utils.checkArgument(false, TEST_MESSAGE), .hasMessage(TEST_MESSAGE);
TEST_MESSAGE);
} }
} }

View File

@ -6,7 +6,7 @@
package io.opentelemetry.context.propagation; package io.opentelemetry.context.propagation;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey; import io.opentelemetry.context.ContextKey;
@ -21,7 +21,8 @@ class DefaultPropagatorsTest {
@Test @Test
void addTextMapPropagatorNull() { void addTextMapPropagatorNull() {
assertThrows(NullPointerException.class, () -> ContextPropagators.create(null)); assertThatThrownBy(() -> ContextPropagators.create(null))
.isInstanceOf(NullPointerException.class);
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -14,61 +14,58 @@ class BatchRecorderTest {
@Test @Test
void testNewBatchRecorder_WrongNumberOfLabels() { void testNewBatchRecorder_WrongNumberOfLabels() {
assertThrows(IllegalArgumentException.class, () -> meter.newBatchRecorder("key"), "key/value"); assertThatThrownBy(() -> meter.newBatchRecorder("key"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("key/value");
} }
@Test @Test
void testNewBatchRecorder_NullLabelKey() { void testNewBatchRecorder_NullLabelKey() {
assertThrows( assertThatThrownBy(() -> meter.newBatchRecorder(null, "value"))
NullPointerException.class, () -> meter.newBatchRecorder(null, "value"), "null keys"); .isInstanceOf(NullPointerException.class)
.hasMessageContaining("null keys");
} }
@Test @Test
void preventNull_MeasureLong() { void preventNull_MeasureLong() {
assertThrows( assertThatThrownBy(() -> meter.newBatchRecorder().put((LongValueRecorder) null, 5L).record())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.newBatchRecorder().put((LongValueRecorder) null, 5L).record(), .hasMessage("valueRecorder");
"valueRecorder");
} }
@Test @Test
void preventNull_MeasureDouble() { void preventNull_MeasureDouble() {
assertThrows( assertThatThrownBy(() -> meter.newBatchRecorder().put((DoubleValueRecorder) null, 5L).record())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.newBatchRecorder().put((DoubleValueRecorder) null, 5L).record(), .hasMessage("valueRecorder");
"valueRecorder");
} }
@Test @Test
void preventNull_LongCounter() { void preventNull_LongCounter() {
assertThrows( assertThatThrownBy(() -> meter.newBatchRecorder().put((LongCounter) null, 5L).record())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.newBatchRecorder().put((LongCounter) null, 5L).record(), .hasMessage("counter");
"counter");
} }
@Test @Test
void preventNull_DoubleCounter() { void preventNull_DoubleCounter() {
assertThrows( assertThatThrownBy(() -> meter.newBatchRecorder().put((DoubleCounter) null, 5L).record())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.newBatchRecorder().put((DoubleCounter) null, 5L).record(), .hasMessage("counter");
"counter");
} }
@Test @Test
void preventNull_LongUpDownCounter() { void preventNull_LongUpDownCounter() {
assertThrows( assertThatThrownBy(() -> meter.newBatchRecorder().put((LongUpDownCounter) null, 5L).record())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.newBatchRecorder().put((LongUpDownCounter) null, 5L).record(), .hasMessage("upDownCounter");
"upDownCounter");
} }
@Test @Test
void preventNull_DoubleUpDownCounter() { void preventNull_DoubleUpDownCounter() {
assertThrows( assertThatThrownBy(() -> meter.newBatchRecorder().put((DoubleUpDownCounter) null, 5L).record())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.newBatchRecorder().put((DoubleUpDownCounter) null, 5L).record(), .hasMessage("upDownCounter");
"upDownCounter");
} }
@Test @Test
@ -89,18 +86,18 @@ class BatchRecorderTest {
@Test @Test
void negativeValue_DoubleCounter() { void negativeValue_DoubleCounter() {
BatchRecorder batchRecorder = meter.newBatchRecorder(); BatchRecorder batchRecorder = meter.newBatchRecorder();
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> batchRecorder.put(meter.doubleCounterBuilder("doubleCounter").build(), -77.556d))
() -> batchRecorder.put(meter.doubleCounterBuilder("doubleCounter").build(), -77.556d), .isInstanceOf(IllegalArgumentException.class)
"Counters can only increase"); .hasMessage("Counters can only increase");
} }
@Test @Test
void negativeValue_LongCounter() { void negativeValue_LongCounter() {
BatchRecorder batchRecorder = meter.newBatchRecorder(); BatchRecorder batchRecorder = meter.newBatchRecorder();
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> batchRecorder.put(meter.longCounterBuilder("longCounter").build(), -44L))
() -> batchRecorder.put(meter.longCounterBuilder("longCounter").build(), -44L), .isInstanceOf(IllegalArgumentException.class)
"Counters can only increase"); .hasMessage("Counters can only increase");
} }
} }

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
@ -22,23 +22,23 @@ class DoubleCounterTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.doubleCounterBuilder(null), "name"); assertThatThrownBy(() -> meter.doubleCounterBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.doubleCounterBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleCounterBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.doubleCounterBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleCounterBuilder("\2").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -46,34 +46,30 @@ class DoubleCounterTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.doubleCounterBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleCounterBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> meter.doubleCounterBuilder("metric").setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleCounterBuilder("metric").setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.doubleCounterBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleCounterBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void add_preventNullLabels() { void add_preventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.doubleCounterBuilder("metric").build().add(1.0, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleCounterBuilder("metric").build().add(1.0, null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -88,18 +84,16 @@ class DoubleCounterTest {
void add_PreventNegativeValue() { void add_PreventNegativeValue() {
DoubleCounter doubleCounter = DoubleCounter doubleCounter =
meter.doubleCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build(); meter.doubleCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build();
assertThrows( assertThatThrownBy(() -> doubleCounter.add(-1.0, Labels.empty()))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> doubleCounter.add(-1.0, Labels.empty()), .hasMessage("Counters can only increase");
"Counters can only increase");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.doubleCounterBuilder("metric").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleCounterBuilder("metric").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -117,8 +111,9 @@ class DoubleCounterTest {
meter.doubleCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build(); meter.doubleCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build();
BoundDoubleCounter bound = doubleCounter.bind(Labels.empty()); BoundDoubleCounter bound = doubleCounter.bind(Labels.empty());
try { try {
assertThrows( assertThatThrownBy(() -> bound.add(-1.0))
IllegalArgumentException.class, () -> bound.add(-1.0), "Counters can only increase"); .isInstanceOf(IllegalArgumentException.class)
.hasMessage("Counters can only increase");
} finally { } finally {
bound.unbind(); bound.unbind();
} }

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
import java.util.Arrays; import java.util.Arrays;
@ -19,21 +19,22 @@ class DoubleSumObserverTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.doubleSumObserverBuilder(null), "name"); assertThatThrownBy(() -> meter.doubleSumObserverBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.doubleSumObserverBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleSumObserverBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.doubleSumObserverBuilder("\2").build())
IllegalArgumentException.class, () -> meter.doubleSumObserverBuilder("\2").build()); .isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
@ -41,34 +42,30 @@ class DoubleSumObserverTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.doubleSumObserverBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleSumObserverBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> meter.doubleSumObserverBuilder("metric").setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleSumObserverBuilder("metric").setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.doubleSumObserverBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleSumObserverBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void preventNull_Callback() { void preventNull_Callback() {
assertThrows( assertThatThrownBy(() -> meter.doubleSumObserverBuilder("metric").setUpdater(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleSumObserverBuilder("metric").setUpdater(null).build(), .hasMessage("callback");
"callback");
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
@ -22,23 +22,23 @@ class DoubleUpDownCounterTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.doubleUpDownCounterBuilder(null), "name"); assertThatThrownBy(() -> meter.doubleUpDownCounterBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownCounterBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleUpDownCounterBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownCounterBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleUpDownCounterBuilder("\2").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -46,34 +46,31 @@ class DoubleUpDownCounterTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownCounterBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleUpDownCounterBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> meter.doubleUpDownCounterBuilder("metric").setDescription(null).build())
() -> meter.doubleUpDownCounterBuilder("metric").setDescription(null).build(), .isInstanceOf(NullPointerException.class)
"description"); .hasMessage("description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownCounterBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleUpDownCounterBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void add_preventNullLabels() { void add_preventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownCounterBuilder("metric").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleUpDownCounterBuilder("metric").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -88,10 +85,9 @@ class DoubleUpDownCounterTest {
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownCounterBuilder("metric").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleUpDownCounterBuilder("metric").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
import java.util.Arrays; import java.util.Arrays;
@ -20,22 +20,22 @@ class DoubleUpDownSumObserverTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownSumObserverBuilder(null))
NullPointerException.class, () -> meter.doubleUpDownSumObserverBuilder(null), "name"); .isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownSumObserverBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleUpDownSumObserverBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownSumObserverBuilder("\2").build())
IllegalArgumentException.class, () -> meter.doubleUpDownSumObserverBuilder("\2").build()); .isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
@ -43,34 +43,32 @@ class DoubleUpDownSumObserverTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownSumObserverBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleUpDownSumObserverBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> meter.doubleUpDownSumObserverBuilder("metric").setDescription(null).build())
() -> meter.doubleUpDownSumObserverBuilder("metric").setDescription(null).build(), .isInstanceOf(NullPointerException.class)
"description"); .hasMessage("description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.doubleUpDownSumObserverBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleUpDownSumObserverBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void preventNull_Callback() { void preventNull_Callback() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> meter.doubleUpDownSumObserverBuilder("metric").setUpdater(null).build())
() -> meter.doubleUpDownSumObserverBuilder("metric").setUpdater(null).build(), .isInstanceOf(NullPointerException.class)
"callback"); .hasMessage("callback");
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
import java.util.Arrays; import java.util.Arrays;
@ -20,21 +20,22 @@ class DoubleValueObserverTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.doubleValueObserverBuilder(null), "name"); assertThatThrownBy(() -> meter.doubleValueObserverBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueObserverBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleValueObserverBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueObserverBuilder("\2").build())
IllegalArgumentException.class, () -> meter.doubleValueObserverBuilder("\2").build()); .isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
@ -42,34 +43,31 @@ class DoubleValueObserverTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.doubleValueObserverBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleValueObserverBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> meter.doubleValueObserverBuilder("metric").setDescription(null).build())
() -> meter.doubleValueObserverBuilder("metric").setDescription(null).build(), .isInstanceOf(NullPointerException.class)
"description"); .hasMessage("description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueObserverBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleValueObserverBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void preventNull_Callback() { void preventNull_Callback() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueObserverBuilder("metric").setUpdater(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleValueObserverBuilder("metric").setUpdater(null).build(), .hasMessage("callback");
"callback");
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
import io.opentelemetry.api.metrics.DoubleValueRecorder.BoundDoubleValueRecorder; import io.opentelemetry.api.metrics.DoubleValueRecorder.BoundDoubleValueRecorder;
@ -21,23 +21,23 @@ class DoubleValueRecorderTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.doubleValueRecorderBuilder(null), "name"); assertThatThrownBy(() -> meter.doubleValueRecorderBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueRecorderBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleValueRecorderBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueRecorderBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleValueRecorderBuilder("\2").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -45,34 +45,31 @@ class DoubleValueRecorderTest {
char[] chars = new char[256]; char[] chars = new char[256];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.doubleValueRecorderBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.doubleValueRecorderBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> meter.doubleValueRecorderBuilder("metric").setDescription(null).build())
() -> meter.doubleValueRecorderBuilder("metric").setDescription(null).build(), .isInstanceOf(NullPointerException.class)
"description"); .hasMessage("description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueRecorderBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleValueRecorderBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void record_PreventNullLabels() { void record_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueRecorderBuilder("metric").build().record(1.0, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleValueRecorderBuilder("metric").build().record(1.0, null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -87,10 +84,9 @@ class DoubleValueRecorderTest {
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.doubleValueRecorderBuilder("metric").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.doubleValueRecorderBuilder("metric").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
@ -22,23 +22,23 @@ class LongCounterTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.longCounterBuilder(null), "name"); assertThatThrownBy(() -> meter.longCounterBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.longCounterBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longCounterBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.longCounterBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longCounterBuilder("\2").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -46,34 +46,30 @@ class LongCounterTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.longCounterBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longCounterBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> meter.longCounterBuilder("metric").setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longCounterBuilder("metric").setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.longCounterBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longCounterBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void add_PreventNullLabels() { void add_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.longCounterBuilder("metric").build().add(1, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longCounterBuilder("metric").build().add(1, null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -88,18 +84,16 @@ class LongCounterTest {
void add_PreventNegativeValue() { void add_PreventNegativeValue() {
LongCounter longCounter = LongCounter longCounter =
meter.longCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build(); meter.longCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build();
assertThrows( assertThatThrownBy(() -> longCounter.add(-1, Labels.empty()))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> longCounter.add(-1, Labels.empty()), .hasMessage("Counters can only increase");
"Counters can only increase");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.longCounterBuilder("metric").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longCounterBuilder("metric").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -117,8 +111,9 @@ class LongCounterTest {
meter.longCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build(); meter.longCounterBuilder(NAME).setDescription(DESCRIPTION).setUnit(UNIT).build();
BoundLongCounter bound = longCounter.bind(Labels.empty()); BoundLongCounter bound = longCounter.bind(Labels.empty());
try { try {
assertThrows( assertThatThrownBy(() -> bound.add(-1))
IllegalArgumentException.class, () -> bound.add(-1), "Counters can only increase"); .isInstanceOf(IllegalArgumentException.class)
.hasMessage("Counters can only increase");
} finally { } finally {
bound.unbind(); bound.unbind();
} }

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
import java.util.Arrays; import java.util.Arrays;
@ -20,23 +20,23 @@ class LongSumObserverTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.longSumObserverBuilder(null), "name"); assertThatThrownBy(() -> meter.longSumObserverBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.longSumObserverBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longSumObserverBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.longSumObserverBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longSumObserverBuilder("\2").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -44,34 +44,30 @@ class LongSumObserverTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.longSumObserverBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longSumObserverBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> meter.longSumObserverBuilder("metric").setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longSumObserverBuilder("metric").setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.longSumObserverBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longSumObserverBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void preventNull_Callback() { void preventNull_Callback() {
assertThrows( assertThatThrownBy(() -> meter.longSumObserverBuilder("metric").setUpdater(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longSumObserverBuilder("metric").setUpdater(null).build(), .hasMessage("callback");
"callback");
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
@ -22,23 +22,23 @@ class LongUpDownCounterTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.longUpDownCounterBuilder(null), "name"); assertThatThrownBy(() -> meter.longUpDownCounterBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownCounterBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longUpDownCounterBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownCounterBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longUpDownCounterBuilder("\2").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -46,34 +46,30 @@ class LongUpDownCounterTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.longUpDownCounterBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longUpDownCounterBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownCounterBuilder("metric").setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longUpDownCounterBuilder("metric").setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownCounterBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longUpDownCounterBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void add_PreventNullLabels() { void add_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownCounterBuilder("metric").build().add(1, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longUpDownCounterBuilder("metric").build().add(1, null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -88,10 +84,9 @@ class LongUpDownCounterTest {
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownCounterBuilder("metric").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longUpDownCounterBuilder("metric").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test

View File

@ -5,7 +5,7 @@
package io.opentelemetry.api.metrics; package io.opentelemetry.api.metrics;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
import java.util.Arrays; import java.util.Arrays;
@ -20,24 +20,23 @@ class LongUpDownSumObserverTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownSumObserverBuilder(null))
NullPointerException.class, () -> meter.longUpDownSumObserverBuilder(null), "name"); .isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownSumObserverBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longUpDownSumObserverBuilder("").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownSumObserverBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longUpDownSumObserverBuilder("\2").build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -45,34 +44,31 @@ class LongUpDownSumObserverTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.longUpDownSumObserverBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longUpDownSumObserverBuilder(longName).build(), .hasMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
DefaultMeter.ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> meter.longUpDownSumObserverBuilder("metric").setDescription(null).build())
() -> meter.longUpDownSumObserverBuilder("metric").setDescription(null).build(), .isInstanceOf(NullPointerException.class)
"description"); .hasMessage("description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownSumObserverBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longUpDownSumObserverBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void preventNull_Callback() { void preventNull_Callback() {
assertThrows( assertThatThrownBy(() -> meter.longUpDownSumObserverBuilder("metric").setUpdater(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longUpDownSumObserverBuilder("metric").setUpdater(null).build(), .hasMessage("callback");
"callback");
} }
@Test @Test

View File

@ -8,7 +8,7 @@ package io.opentelemetry.api.metrics;
import static io.opentelemetry.api.internal.StringUtils.METRIC_NAME_MAX_LENGTH; import static io.opentelemetry.api.internal.StringUtils.METRIC_NAME_MAX_LENGTH;
import static io.opentelemetry.api.metrics.DefaultMeter.ERROR_MESSAGE_INVALID_NAME; import static io.opentelemetry.api.metrics.DefaultMeter.ERROR_MESSAGE_INVALID_NAME;
import static java.util.Arrays.fill; import static java.util.Arrays.fill;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -22,23 +22,23 @@ class LongValueObserverTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.longValueObserverBuilder(null), "name"); assertThatThrownBy(() -> meter.longValueObserverBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.longValueObserverBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longValueObserverBuilder("").build(), .hasMessage(ERROR_MESSAGE_INVALID_NAME);
ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows( assertThatThrownBy(() -> meter.longValueObserverBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longValueObserverBuilder("\2").build(), .hasMessage(ERROR_MESSAGE_INVALID_NAME);
ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -46,34 +46,30 @@ class LongValueObserverTest {
char[] chars = new char[METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[METRIC_NAME_MAX_LENGTH + 1];
fill(chars, 'a'); fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.longValueObserverBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longValueObserverBuilder(longName).build(), .hasMessage(ERROR_MESSAGE_INVALID_NAME);
ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> meter.longValueObserverBuilder("metric").setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longValueObserverBuilder("metric").setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.longValueObserverBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longValueObserverBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void preventNull_Callback() { void preventNull_Callback() {
assertThrows( assertThatThrownBy(() -> meter.longValueObserverBuilder("metric").setUpdater(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longValueObserverBuilder("metric").setUpdater(null).build(), .hasMessage("callback");
"callback");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.api.metrics;
import static io.opentelemetry.api.metrics.DefaultMeter.ERROR_MESSAGE_INVALID_NAME; import static io.opentelemetry.api.metrics.DefaultMeter.ERROR_MESSAGE_INVALID_NAME;
import static java.util.Arrays.fill; import static java.util.Arrays.fill;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.assertj.core.api.Assertions.assertThatThrownBy;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
import io.opentelemetry.api.metrics.LongValueRecorder.BoundLongValueRecorder; import io.opentelemetry.api.metrics.LongValueRecorder.BoundLongValueRecorder;
@ -23,23 +23,23 @@ public final class LongValueRecorderTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> meter.longValueRecorderBuilder(null), "name"); assertThatThrownBy(() -> meter.longValueRecorderBuilder(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows( assertThatThrownBy(() -> meter.longValueRecorderBuilder("").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longValueRecorderBuilder("").build(), .hasMessage(ERROR_MESSAGE_INVALID_NAME);
ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNonPrintableMeasureName() { void preventNonPrintableMeasureName() {
assertThrows( assertThatThrownBy(() -> meter.longValueRecorderBuilder("\2").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longValueRecorderBuilder("\2").build(), .hasMessage(ERROR_MESSAGE_INVALID_NAME);
ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
@ -47,34 +47,30 @@ public final class LongValueRecorderTest {
char[] chars = new char[256]; char[] chars = new char[256];
fill(chars, 'a'); fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> meter.longValueRecorderBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> meter.longValueRecorderBuilder(longName).build(), .hasMessage(ERROR_MESSAGE_INVALID_NAME);
ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> meter.longValueRecorderBuilder("metric").setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longValueRecorderBuilder("metric").setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> meter.longValueRecorderBuilder("metric").setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longValueRecorderBuilder("metric").setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test
void record_PreventNullLabels() { void record_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.longValueRecorderBuilder("metric").build().record(1, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longValueRecorderBuilder("metric").build().record(1, null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -89,10 +85,9 @@ public final class LongValueRecorderTest {
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> meter.longValueRecorderBuilder("metric").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> meter.longValueRecorderBuilder("metric").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.api.trace;
import static java.nio.CharBuffer.wrap; import static java.nio.CharBuffer.wrap;
import static org.assertj.core.api.Assertions.assertThat; 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 java.nio.CharBuffer; import java.nio.CharBuffer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -56,10 +56,10 @@ class BigendianEncodingTest {
@Test @Test
void longToByteArray_Fails() { void longToByteArray_Fails() {
// These contain bytes not in the decoding. // These contain bytes not in the decoding.
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> BigendianEncoding.longToByteArray(123, new byte[BigendianEncoding.LONG_BYTES], 1))
() -> BigendianEncoding.longToByteArray(123, new byte[BigendianEncoding.LONG_BYTES], 1), .isInstanceOf(IllegalArgumentException.class)
"array too small"); .hasMessage("array too small");
} }
@Test @Test
@ -81,10 +81,10 @@ class BigendianEncodingTest {
@Test @Test
void longFromByteArray_ArrayToSmall() { void longFromByteArray_ArrayToSmall() {
// These contain bytes not in the decoding. // These contain bytes not in the decoding.
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> BigendianEncoding.longFromByteArray(new byte[BigendianEncoding.LONG_BYTES], 1))
() -> BigendianEncoding.longFromByteArray(new byte[BigendianEncoding.LONG_BYTES], 1), .isInstanceOf(IllegalArgumentException.class)
"array too small"); .hasMessage("array too small");
} }
@Test @Test
@ -127,21 +127,20 @@ class BigendianEncodingTest {
@Test @Test
void longFromBase16String_InputTooSmall() { void longFromBase16String_InputTooSmall() {
// Valid base16 strings always have an even length. // Valid base16 strings always have an even length.
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () ->
() -> BigendianEncoding.longFromBase16String(
BigendianEncoding.longFromBase16String( wrap(new char[BigendianEncoding.LONG_BASE16]), 1))
wrap(new char[BigendianEncoding.LONG_BASE16]), 1), .isInstanceOf(IllegalArgumentException.class)
"chars too small"); .hasMessage("chars too small");
} }
@Test @Test
void longFromBase16String_UnrecognizedCharacters() { void longFromBase16String_UnrecognizedCharacters() {
// These contain bytes not in the decoding. // These contain bytes not in the decoding.
assertThrows( assertThatThrownBy(() -> BigendianEncoding.longFromBase16String("0123456789gbcdef", 0))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> BigendianEncoding.longFromBase16String("0123456789gbcdef", 0), .hasMessage("invalid character g");
"invalid character g");
} }
@Test @Test

View File

@ -6,7 +6,7 @@
package io.opentelemetry.api.trace; package io.opentelemetry.api.trace;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -30,7 +30,8 @@ class DefaultTracerTest {
@Test @Test
void spanBuilderWithName_NullName() { void spanBuilderWithName_NullName() {
assertThrows(NullPointerException.class, () -> defaultTracer.spanBuilder(null)); assertThatThrownBy(() -> defaultTracer.spanBuilder(null))
.isInstanceOf(NullPointerException.class);
} }
@Test @Test
@ -66,8 +67,8 @@ class DefaultTracerTest {
@Test @Test
void testSpanContextPropagation_nullContext() { void testSpanContextPropagation_nullContext() {
assertThrows( assertThatThrownBy(() -> defaultTracer.spanBuilder(SPAN_NAME).setParent(null))
NullPointerException.class, () -> defaultTracer.spanBuilder(SPAN_NAME).setParent(null)); .isInstanceOf(NullPointerException.class);
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.api.trace;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind; import io.opentelemetry.api.trace.Span.Kind;
@ -42,15 +42,14 @@ class SpanBuilderTest {
@Test @Test
void setParent_NullContext() { void setParent_NullContext() {
SpanBuilder spanBuilder = tracer.spanBuilder("MySpanName"); SpanBuilder spanBuilder = tracer.spanBuilder("MySpanName");
assertThrows(NullPointerException.class, () -> spanBuilder.setParent(null)); assertThatThrownBy(() -> spanBuilder.setParent(null)).isInstanceOf(NullPointerException.class);
} }
@Test @Test
void setStartTimestamp_Negative() { void setStartTimestamp_Negative() {
SpanBuilder spanBuilder = tracer.spanBuilder("MySpanName"); SpanBuilder spanBuilder = tracer.spanBuilder("MySpanName");
assertThrows( assertThatThrownBy(() -> spanBuilder.setStartTimestamp(-1, TimeUnit.NANOSECONDS))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> spanBuilder.setStartTimestamp(-1, TimeUnit.NANOSECONDS), .hasMessage("Negative startTimestamp");
"Negative startTimestamp");
} }
} }

View File

@ -6,7 +6,7 @@
package io.opentelemetry.extension.trace.propagation; package io.opentelemetry.extension.trace.propagation;
import static org.assertj.core.api.Assertions.assertThat; 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 org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -27,7 +27,8 @@ class StringUtilsTest {
@Test @Test
void padLeft_throws_for_null_value() { void padLeft_throws_for_null_value() {
assertThrows(NullPointerException.class, () -> StringUtils.padLeft(null, 10)); assertThatThrownBy(() -> StringUtils.padLeft(null, 10))
.isInstanceOf(NullPointerException.class);
} }
@Test @Test

View File

@ -6,7 +6,7 @@
package io.opentelemetry.extension.trace.propagation; package io.opentelemetry.extension.trace.propagation;
import static org.assertj.core.api.Assertions.assertThat; 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.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -60,8 +60,8 @@ class TraceMultiPropagatorTest {
@Test @Test
void addPropagator_null() { void addPropagator_null() {
assertThrows( assertThatThrownBy(() -> TraceMultiPropagator.create((TextMapPropagator) null))
NullPointerException.class, () -> TraceMultiPropagator.create((TextMapPropagator) null)); .isInstanceOf(NullPointerException.class);
} }
@Test @Test
@ -92,7 +92,7 @@ class TraceMultiPropagatorTest {
new EmptyPropagator("foo", "bar"), new EmptyPropagator("hello", "world")); new EmptyPropagator("foo", "bar"), new EmptyPropagator("hello", "world"));
Collection<String> fields = prop.fields(); Collection<String> fields = prop.fields();
assertThrows(UnsupportedOperationException.class, () -> fields.add("hi")); assertThatThrownBy(() -> fields.add("hi")).isInstanceOf(UnsupportedOperationException.class);
} }
@Test @Test

View File

@ -5,8 +5,8 @@
package io.opentelemetry.opencensusshim; package io.opentelemetry.opencensusshim;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import io.opencensus.trace.SpanContext; import io.opencensus.trace.SpanContext;
import io.opencensus.trace.SpanId; import io.opencensus.trace.SpanId;
@ -57,7 +57,9 @@ class OpenTelemetryBinaryFormatImplTest {
@Test @Test
void toBinaryValue_NullSpanContext() { void toBinaryValue_NullSpanContext() {
assertThrows(NullPointerException.class, () -> binaryFormat.toByteArray(null), "spanContext"); assertThatThrownBy(() -> binaryFormat.toByteArray(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("spanContext");
} }
@Test @Test
@ -76,56 +78,59 @@ class OpenTelemetryBinaryFormatImplTest {
@Test @Test
void fromBinaryValue_NullInput() { void fromBinaryValue_NullInput() {
assertThrows(NullPointerException.class, () -> binaryFormat.toByteArray(null), "spanContext"); assertThatThrownBy(() -> binaryFormat.toByteArray(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("spanContext");
} }
@Test @Test
void fromBinaryValue_EmptyInput() { void fromBinaryValue_EmptyInput() {
assertThrows( assertThatThrownBy(() -> binaryFormat.fromByteArray(new byte[0]))
SpanContextParseException.class, .isInstanceOf(SpanContextParseException.class)
() -> binaryFormat.fromByteArray(new byte[0]), .hasMessage("Unsupported version.");
"Unsupported version.");
} }
@Test @Test
void fromBinaryValue_UnsupportedVersionId() { void fromBinaryValue_UnsupportedVersionId() {
assertThrows( assertThatThrownBy(
SpanContextParseException.class, () ->
() -> binaryFormat.fromByteArray(
binaryFormat.fromByteArray( new byte[] {
new byte[] { 66, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 97, 98,
66, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 97, 98, 99, 99, 100, 101, 102, 103, 104, 1
100, 101, 102, 103, 104, 1 }))
}), .isInstanceOf(SpanContextParseException.class)
"Unsupported version."); .hasMessage("Unsupported version.");
} }
@Test @Test
void fromBinaryValue_UnsupportedFieldIdFirst() { void fromBinaryValue_UnsupportedFieldIdFirst() {
assertThrows( assertThatThrownBy(
SpanContextParseException.class, () ->
() -> binaryFormat.fromByteArray(
binaryFormat.fromByteArray( new byte[] {
new byte[] { 0, 4, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97,
0, 4, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 98, 99, 100, 101, 102, 103, 104, 2, 1
99, 100, 101, 102, 103, 104, 2, 1 }))
}), .isInstanceOf(SpanContextParseException.class)
"Invalid input: expected trace ID at offset " .hasMessage(
+ OpenTelemetryBinaryFormatImpl.TRACE_ID_FIELD_ID_OFFSET); "Invalid input: expected trace ID at offset "
+ OpenTelemetryBinaryFormatImpl.TRACE_ID_FIELD_ID_OFFSET);
} }
@Test @Test
void fromBinaryValue_UnsupportedFieldIdSecond() { void fromBinaryValue_UnsupportedFieldIdSecond() {
assertThrows( assertThatThrownBy(
SpanContextParseException.class, () ->
() -> binaryFormat.fromByteArray(
binaryFormat.fromByteArray( new byte[] {
new byte[] { 0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 3, 97,
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 3, 97, 98, 98, 99, 100, 101, 102, 103, 104, 2, 1
99, 100, 101, 102, 103, 104, 2, 1 }))
}), .isInstanceOf(SpanContextParseException.class)
"Invalid input: expected span ID at offset " .hasMessage(
+ OpenTelemetryBinaryFormatImpl.SPAN_ID_FIELD_ID_OFFSET); "Invalid input: expected span ID at offset "
+ OpenTelemetryBinaryFormatImpl.SPAN_ID_FIELD_ID_OFFSET);
} }
@Test @Test
@ -143,33 +148,33 @@ class OpenTelemetryBinaryFormatImplTest {
@Test @Test
void fromBinaryValue_ShorterTraceId() { void fromBinaryValue_ShorterTraceId() {
assertThrows( assertThatThrownBy(
SpanContextParseException.class, () ->
() -> binaryFormat.fromByteArray(
binaryFormat.fromByteArray( new byte[] {0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76}))
new byte[] {0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76}), .isInstanceOf(SpanContextParseException.class)
"Invalid input: truncated"); .hasMessage("Invalid input: truncated");
} }
@Test @Test
void fromBinaryValue_ShorterSpanId() { void fromBinaryValue_ShorterSpanId() {
assertThrows( assertThatThrownBy(
SpanContextParseException.class, () -> binaryFormat.fromByteArray(new byte[] {0, 1, 97, 98, 99, 100, 101, 102, 103}))
() -> binaryFormat.fromByteArray(new byte[] {0, 1, 97, 98, 99, 100, 101, 102, 103}), .isInstanceOf(SpanContextParseException.class)
"Invalid input: truncated"); .hasMessage("Invalid input: truncated");
} }
@Test @Test
void fromBinaryValue_ShorterTraceOptions() { void fromBinaryValue_ShorterTraceOptions() {
assertThrows( assertThatThrownBy(
SpanContextParseException.class, () ->
() -> binaryFormat.fromByteArray(
binaryFormat.fromByteArray( new byte[] {
new byte[] { 0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97,
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 98, 99, 100, 101, 102, 103, 104, 2
99, 100, 101, 102, 103, 104, 2 }))
}), .isInstanceOf(SpanContextParseException.class)
"Invalid input: truncated"); .hasMessage("Invalid input: truncated");
} }
@Test @Test

View File

@ -5,6 +5,8 @@
package io.opentelemetry.sdk.common; package io.opentelemetry.sdk.common;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.api.trace.Tracer;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -28,6 +30,7 @@ public abstract class InstrumentationLibraryInfo {
* @return the new instance * @return the new instance
*/ */
public static InstrumentationLibraryInfo create(String name, @Nullable String version) { public static InstrumentationLibraryInfo create(String name, @Nullable String version) {
requireNonNull(name, "name");
return new AutoValue_InstrumentationLibraryInfo(name, version); return new AutoValue_InstrumentationLibraryInfo(name, version);
} }

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.common; package io.opentelemetry.sdk.common;
import static org.assertj.core.api.Assertions.assertThat; 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 org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -21,7 +21,8 @@ class InstrumentationLibraryInfoTest {
@Test @Test
void nullName() { void nullName() {
assertThrows( assertThatThrownBy(() -> InstrumentationLibraryInfo.create(null, "1.0.0"))
NullPointerException.class, () -> InstrumentationLibraryInfo.create(null, "1.0.0"), "name"); .isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
} }

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.internal; package io.opentelemetry.sdk.internal;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -21,7 +21,9 @@ class ComponentRegistryTest {
@Test @Test
void libraryName_MustNotBeNull() { void libraryName_MustNotBeNull() {
assertThrows(NullPointerException.class, () -> registry.get(null, "version"), "name"); assertThatThrownBy(() -> registry.get(null, "version"))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.resources; package io.opentelemetry.sdk.resources;
import static org.assertj.core.api.Assertions.assertThat; 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 com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -21,9 +21,10 @@ class ResourcesConfigTest {
@Test @Test
void updateResourcesConfig_NullDisabledResourceProviders() { void updateResourcesConfig_NullDisabledResourceProviders() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () ->
() -> ResourcesConfig.getDefault().toBuilder().setDisabledResourceProviders(null).build()); ResourcesConfig.getDefault().toBuilder().setDisabledResourceProviders(null).build())
.isInstanceOf(NullPointerException.class);
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.sdk.metrics.AbstractInstrument.Builder.ERROR_MESSAGE_INVALID_NAME; import static io.opentelemetry.sdk.metrics.AbstractInstrument.Builder.ERROR_MESSAGE_INVALID_NAME;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.internal.StringUtils; import io.opentelemetry.api.internal.StringUtils;
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
@ -28,12 +28,16 @@ class AbstractInstrumentBuilderTest {
@Test @Test
void preventNull_Name() { void preventNull_Name() {
assertThrows(NullPointerException.class, () -> new TestInstrumentBuilder(null).build(), "name"); assertThatThrownBy(() -> new TestInstrumentBuilder(null).build())
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
} }
@Test @Test
void preventEmpty_Name() { void preventEmpty_Name() {
assertThrows(IllegalArgumentException.class, () -> new TestInstrumentBuilder(""), "Name"); assertThatThrownBy(() -> new TestInstrumentBuilder(""))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Name");
} }
@Test @Test
@ -42,15 +46,15 @@ class AbstractInstrumentBuilderTest {
new TestInstrumentBuilder("METRIC_name"); new TestInstrumentBuilder("METRIC_name");
new TestInstrumentBuilder("metric.name_01"); new TestInstrumentBuilder("metric.name_01");
new TestInstrumentBuilder("metric_name.01"); new TestInstrumentBuilder("metric_name.01");
assertThrows( assertThatThrownBy(() -> new TestInstrumentBuilder("01.metric_name_01"))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> new TestInstrumentBuilder("01.metric_name_01"), .hasMessageContaining("Name");
"Name");
} }
@Test @Test
void preventNonPrintableName() { void preventNonPrintableName() {
assertThrows(IllegalArgumentException.class, () -> new TestInstrumentBuilder("\2").build()); assertThatThrownBy(() -> new TestInstrumentBuilder("\2").build())
.isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
@ -58,26 +62,23 @@ class AbstractInstrumentBuilderTest {
char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1]; char[] chars = new char[StringUtils.METRIC_NAME_MAX_LENGTH + 1];
Arrays.fill(chars, 'a'); Arrays.fill(chars, 'a');
String longName = String.valueOf(chars); String longName = String.valueOf(chars);
assertThrows( assertThatThrownBy(() -> new TestInstrumentBuilder(longName).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> new TestInstrumentBuilder(longName).build(), .hasMessage(ERROR_MESSAGE_INVALID_NAME);
ERROR_MESSAGE_INVALID_NAME);
} }
@Test @Test
void preventNull_Description() { void preventNull_Description() {
assertThrows( assertThatThrownBy(() -> new TestInstrumentBuilder(NAME).setDescription(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> new TestInstrumentBuilder(NAME).setDescription(null).build(), .hasMessage("description");
"description");
} }
@Test @Test
void preventNull_Unit() { void preventNull_Unit() {
assertThrows( assertThatThrownBy(() -> new TestInstrumentBuilder(NAME).setUnit(null).build())
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> new TestInstrumentBuilder(NAME).setUnit(null).build(), .hasMessage("unit");
"unit");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -37,10 +37,9 @@ class BatchRecorderSdkTest {
@Test @Test
void batchRecorder_badLabelSet() { void batchRecorder_badLabelSet() {
assertThrows( assertThatThrownBy(() -> testSdk.newBatchRecorder("key").record())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.newBatchRecorder("key").record(), .hasMessageContaining("key/value");
"key/value");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -38,18 +38,16 @@ class DoubleCounterSdkTest {
@Test @Test
void add_PreventNullLabels() { void add_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> testSdk.doubleCounterBuilder("testCounter").build().add(1.0, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> testSdk.doubleCounterBuilder("testCounter").build().add(1.0, null), .hasMessage("labels");
"labels");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> testSdk.doubleCounterBuilder("testCounter").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> testSdk.doubleCounterBuilder("testCounter").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -181,15 +179,16 @@ class DoubleCounterSdkTest {
void doubleCounterAdd_Monotonicity() { void doubleCounterAdd_Monotonicity() {
DoubleCounterSdk doubleCounter = testSdk.doubleCounterBuilder("testCounter").build(); DoubleCounterSdk doubleCounter = testSdk.doubleCounterBuilder("testCounter").build();
assertThrows(IllegalArgumentException.class, () -> doubleCounter.add(-45.77d, Labels.empty())); assertThatThrownBy(() -> doubleCounter.add(-45.77d, Labels.empty()))
.isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
void boundDoubleCounterAdd_Monotonicity() { void boundDoubleCounterAdd_Monotonicity() {
DoubleCounterSdk doubleCounter = testSdk.doubleCounterBuilder("testCounter").build(); DoubleCounterSdk doubleCounter = testSdk.doubleCounterBuilder("testCounter").build();
assertThrows( assertThatThrownBy(() -> doubleCounter.bind(Labels.empty()).add(-9.3))
IllegalArgumentException.class, () -> doubleCounter.bind(Labels.empty()).add(-9.3)); .isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -39,18 +39,18 @@ class DoubleUpDownCounterSdkTest {
@Test @Test
void add_PreventNullLabels() { void add_PreventNullLabels() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> testSdk.doubleUpDownCounterBuilder("testUpDownCounter").build().add(1.0, null))
() -> testSdk.doubleUpDownCounterBuilder("testUpDownCounter").build().add(1.0, null), .isInstanceOf(NullPointerException.class)
"labels"); .hasMessage("labels");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> testSdk.doubleUpDownCounterBuilder("testUpDownCounter").build().bind(null))
() -> testSdk.doubleUpDownCounterBuilder("testUpDownCounter").build().bind(null), .isInstanceOf(NullPointerException.class)
"labels"); .hasMessage("labels");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -42,18 +42,17 @@ class DoubleValueRecorderSdkTest {
@Test @Test
void record_PreventNullLabels() { void record_PreventNullLabels() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> testSdk.doubleValueRecorderBuilder("testRecorder").build().record(1.0, null))
() -> testSdk.doubleValueRecorderBuilder("testRecorder").build().record(1.0, null), .isInstanceOf(NullPointerException.class)
"labels"); .hasMessage("labels");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> testSdk.doubleValueRecorderBuilder("testRecorder").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> testSdk.doubleValueRecorderBuilder("testRecorder").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.metrics; package io.opentelemetry.sdk.metrics;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor; import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
@ -50,13 +50,13 @@ class InstrumentRegistryTest {
assertThat(meterSharedState.getInstrumentRegistry().register(testInstrument)) assertThat(meterSharedState.getInstrumentRegistry().register(testInstrument))
.isSameAs(testInstrument); .isSameAs(testInstrument);
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () ->
() -> meterSharedState
meterSharedState .getInstrumentRegistry()
.getInstrumentRegistry() .register(new TestInstrument(OTHER_INSTRUMENT_DESCRIPTOR)))
.register(new TestInstrument(OTHER_INSTRUMENT_DESCRIPTOR)), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -67,13 +67,13 @@ class InstrumentRegistryTest {
assertThat(meterSharedState.getInstrumentRegistry().register(testInstrument)) assertThat(meterSharedState.getInstrumentRegistry().register(testInstrument))
.isSameAs(testInstrument); .isSameAs(testInstrument);
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () ->
() -> meterSharedState
meterSharedState .getInstrumentRegistry()
.getInstrumentRegistry() .register(new OtherTestInstrument(INSTRUMENT_DESCRIPTOR)))
.register(new OtherTestInstrument(INSTRUMENT_DESCRIPTOR)), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
} }
private static final class TestInstrument extends AbstractInstrument { private static final class TestInstrument extends AbstractInstrument {

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -39,18 +39,16 @@ class LongCounterSdkTest {
@Test @Test
void add_PreventNullLabels() { void add_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> testSdk.longCounterBuilder("testCounter").build().add(1, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> testSdk.longCounterBuilder("testCounter").build().add(1, null), .hasMessage("labels");
"labels");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> testSdk.longCounterBuilder("testCounter").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> testSdk.longCounterBuilder("testCounter").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test
@ -172,14 +170,16 @@ class LongCounterSdkTest {
void longCounterAdd_MonotonicityCheck() { void longCounterAdd_MonotonicityCheck() {
LongCounterSdk longCounter = testSdk.longCounterBuilder("testCounter").build(); LongCounterSdk longCounter = testSdk.longCounterBuilder("testCounter").build();
assertThrows(IllegalArgumentException.class, () -> longCounter.add(-45, Labels.empty())); assertThatThrownBy(() -> longCounter.add(-45, Labels.empty()))
.isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
void boundLongCounterAdd_MonotonicityCheck() { void boundLongCounterAdd_MonotonicityCheck() {
LongCounterSdk longCounter = testSdk.longCounterBuilder("testCounter").build(); LongCounterSdk longCounter = testSdk.longCounterBuilder("testCounter").build();
assertThrows(IllegalArgumentException.class, () -> longCounter.bind(Labels.empty()).add(-9)); assertThatThrownBy(() -> longCounter.bind(Labels.empty()).add(-9))
.isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -39,18 +39,17 @@ class LongUpDownCounterSdkTest {
@Test @Test
void add_PreventNullLabels() { void add_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> testSdk.longUpDownCounterBuilder("testCounter").build().add(1, null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> testSdk.longUpDownCounterBuilder("testCounter").build().add(1, null), .hasMessage("labels");
"labels");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> testSdk.longUpDownCounterBuilder("testUpDownCounter").build().bind(null))
() -> testSdk.longUpDownCounterBuilder("testUpDownCounter").build().bind(null), .isInstanceOf(NullPointerException.class)
"labels"); .hasMessage("labels");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -42,18 +42,17 @@ class LongValueRecorderSdkTest {
@Test @Test
void record_PreventNullLabels() { void record_PreventNullLabels() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () -> testSdk.longValueRecorderBuilder("testRecorder").build().record(1, null))
() -> testSdk.longValueRecorderBuilder("testRecorder").build().record(1, null), .isInstanceOf(NullPointerException.class)
"labels"); .hasMessage("labels");
} }
@Test @Test
void bound_PreventNullLabels() { void bound_PreventNullLabels() {
assertThrows( assertThatThrownBy(() -> testSdk.longValueRecorderBuilder("testRecorder").build().bind(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> testSdk.longValueRecorderBuilder("testRecorder").build().bind(null), .hasMessage("labels");
"labels");
} }
@Test @Test

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.metrics; package io.opentelemetry.sdk.metrics;
import static org.assertj.core.api.Assertions.assertThat; 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.mock;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -37,14 +37,16 @@ class SdkMeterRegistryTest {
@Test @Test
void builder_NullClock() { void builder_NullClock() {
assertThrows( assertThatThrownBy(() -> SdkMeterProvider.builder().setClock(null))
NullPointerException.class, () -> SdkMeterProvider.builder().setClock(null), "clock"); .isInstanceOf(NullPointerException.class)
.hasMessage("clock");
} }
@Test @Test
void builder_NullResource() { void builder_NullResource() {
assertThrows( assertThatThrownBy(() -> SdkMeterProvider.builder().setResource(null))
NullPointerException.class, () -> SdkMeterProvider.builder().setResource(null), "resource"); .isInstanceOf(NullPointerException.class)
.hasMessage("resource");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.metrics;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Labels; import io.opentelemetry.api.common.Labels;
@ -56,14 +56,12 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(longCounter); .isSameAs(longCounter);
assertThrows( assertThatThrownBy(() -> testSdk.longCounterBuilder("testLongCounter").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longCounterBuilder("testLongCounter").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(() -> testSdk.longCounterBuilder("testLongCounter".toUpperCase()).build())
assertThrows( .isInstanceOf(IllegalArgumentException.class)
IllegalArgumentException.class, .hasMessage("Instrument with same name and different descriptor already created.");
() -> testSdk.longCounterBuilder("testLongCounter".toUpperCase()).build(),
"Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -84,14 +82,13 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(longUpDownCounter); .isSameAs(longUpDownCounter);
assertThrows( assertThatThrownBy(() -> testSdk.longUpDownCounterBuilder("testLongUpDownCounter").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longUpDownCounterBuilder("testLongUpDownCounter").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () -> testSdk.longUpDownCounterBuilder("testLongUpDownCounter".toUpperCase()).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longUpDownCounterBuilder("testLongUpDownCounter".toUpperCase()).build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -112,14 +109,13 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(longValueRecorder); .isSameAs(longValueRecorder);
assertThrows( assertThatThrownBy(() -> testSdk.longValueRecorderBuilder("testLongValueRecorder").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longValueRecorderBuilder("testLongValueRecorder").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () -> testSdk.longValueRecorderBuilder("testLongValueRecorder".toUpperCase()).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longValueRecorderBuilder("testLongValueRecorder".toUpperCase()).build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -140,14 +136,13 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(longValueObserver); .isSameAs(longValueObserver);
assertThrows( assertThatThrownBy(() -> testSdk.longValueObserverBuilder("longValueObserver").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longValueObserverBuilder("longValueObserver").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () -> testSdk.longValueObserverBuilder("longValueObserver".toUpperCase()).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longValueObserverBuilder("longValueObserver".toUpperCase()).build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -168,15 +163,14 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(longObserver); .isSameAs(longObserver);
assertThrows( assertThatThrownBy(() -> testSdk.longSumObserverBuilder("testLongSumObserver").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.longSumObserverBuilder("testLongSumObserver").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created.");
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> testSdk.longSumObserverBuilder("testLongSumObserver".toUpperCase()).build())
() -> testSdk.longSumObserverBuilder("testLongSumObserver".toUpperCase()).build(), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -197,16 +191,18 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(longObserver); .isSameAs(longObserver);
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> testSdk.longUpDownSumObserverBuilder("testLongUpDownSumObserver").build())
() -> testSdk.longUpDownSumObserverBuilder("testLongUpDownSumObserver").build(), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () ->
() -> testSdk
testSdk.longUpDownSumObserverBuilder("testLongUpDownSumObserver".toUpperCase()).build(), .longUpDownSumObserverBuilder("testLongUpDownSumObserver".toUpperCase())
"Instrument with same name and different descriptor already created."); .build())
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -227,14 +223,13 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(doubleCounter); .isSameAs(doubleCounter);
assertThrows( assertThatThrownBy(() -> testSdk.doubleCounterBuilder("testDoubleCounter").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleCounterBuilder("testDoubleCounter").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () -> testSdk.doubleCounterBuilder("testDoubleCounter".toUpperCase()).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleCounterBuilder("testDoubleCounter".toUpperCase()).build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -255,14 +250,14 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(doubleUpDownCounter); .isSameAs(doubleUpDownCounter);
assertThrows( assertThatThrownBy(() -> testSdk.doubleUpDownCounterBuilder("testDoubleUpDownCounter").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleUpDownCounterBuilder("testDoubleUpDownCounter").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () ->
IllegalArgumentException.class, testSdk.doubleUpDownCounterBuilder("testDoubleUpDownCounter".toUpperCase()).build())
() -> testSdk.doubleUpDownCounterBuilder("testDoubleUpDownCounter".toUpperCase()).build(), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -283,14 +278,14 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(doubleValueRecorder); .isSameAs(doubleValueRecorder);
assertThrows( assertThatThrownBy(() -> testSdk.doubleValueRecorderBuilder("testDoubleValueRecorder").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleValueRecorderBuilder("testDoubleValueRecorder").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () ->
IllegalArgumentException.class, testSdk.doubleValueRecorderBuilder("testDoubleValueRecorder".toUpperCase()).build())
() -> testSdk.doubleValueRecorderBuilder("testDoubleValueRecorder".toUpperCase()).build(), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -311,14 +306,13 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(doubleObserver); .isSameAs(doubleObserver);
assertThrows( assertThatThrownBy(() -> testSdk.doubleSumObserverBuilder("testDoubleSumObserver").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleSumObserverBuilder("testDoubleSumObserver").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () -> testSdk.doubleSumObserverBuilder("testDoubleSumObserver".toUpperCase()).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleSumObserverBuilder("testDoubleSumObserver".toUpperCase()).build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -339,17 +333,17 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(doubleObserver); .isSameAs(doubleObserver);
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> testSdk.doubleUpDownSumObserverBuilder("testDoubleUpDownSumObserver").build())
() -> testSdk.doubleUpDownSumObserverBuilder("testDoubleUpDownSumObserver").build(), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () ->
() -> testSdk
testSdk .doubleUpDownSumObserverBuilder("testDoubleUpDownSumObserver".toUpperCase())
.doubleUpDownSumObserverBuilder("testDoubleUpDownSumObserver".toUpperCase()) .build())
.build(), .isInstanceOf(IllegalArgumentException.class)
"Instrument with same name and different descriptor already created."); .hasMessage("Instrument with same name and different descriptor already created.");
} }
@Test @Test
@ -370,14 +364,13 @@ class SdkMeterTest {
.build()) .build())
.isSameAs(doubleValueObserver); .isSameAs(doubleValueObserver);
assertThrows( assertThatThrownBy(() -> testSdk.doubleValueObserverBuilder("doubleValueObserver").build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleValueObserverBuilder("doubleValueObserver").build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created."); assertThatThrownBy(
assertThrows( () -> testSdk.doubleValueObserverBuilder("doubleValueObserver".toUpperCase()).build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class)
() -> testSdk.doubleValueObserverBuilder("doubleValueObserver".toUpperCase()).build(), .hasMessage("Instrument with same name and different descriptor already created.");
"Instrument with same name and different descriptor already created.");
} }
@Test @Test

View File

@ -7,7 +7,7 @@ package io.opentelemetry.sdk.testing.trace;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span.Kind; import io.opentelemetry.api.trace.Span.Kind;
@ -44,16 +44,17 @@ class TestSpanDataTest {
void unmodifiableLinks() { void unmodifiableLinks() {
SpanData spanData = createSpanDataWithMutableCollections(); SpanData spanData = createSpanDataWithMutableCollections();
assertThrows(UnsupportedOperationException.class, () -> spanData.getLinks().add(emptyLink())); assertThatThrownBy(() -> spanData.getLinks().add(emptyLink()))
.isInstanceOf(UnsupportedOperationException.class);
} }
@Test @Test
void unmodifiableTimedEvents() { void unmodifiableTimedEvents() {
SpanData spanData = createSpanDataWithMutableCollections(); SpanData spanData = createSpanDataWithMutableCollections();
assertThrows( assertThatThrownBy(
UnsupportedOperationException.class, () -> spanData.getEvents().add(Event.create(1234, "foo", Attributes.empty())))
() -> spanData.getEvents().add(Event.create(1234, "foo", Attributes.empty()))); .isInstanceOf(UnsupportedOperationException.class);
} }
@Test @Test

View File

@ -5,13 +5,14 @@
package io.opentelemetry.sdk.trace; package io.opentelemetry.sdk.trace;
import static java.util.Objects.requireNonNull;
import io.opentelemetry.sdk.common.Clock; import io.opentelemetry.sdk.common.Clock;
import io.opentelemetry.sdk.internal.SystemClock; import io.opentelemetry.sdk.internal.SystemClock;
import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.config.TraceConfig; import io.opentelemetry.sdk.trace.config.TraceConfig;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** Builder of {@link SdkTracerProvider}. */ /** Builder of {@link SdkTracerProvider}. */
public final class SdkTracerProviderBuilder { public final class SdkTracerProviderBuilder {
@ -29,7 +30,7 @@ public final class SdkTracerProviderBuilder {
* @return this * @return this
*/ */
public SdkTracerProviderBuilder setClock(Clock clock) { public SdkTracerProviderBuilder setClock(Clock clock) {
Objects.requireNonNull(clock, "clock"); requireNonNull(clock, "clock");
this.clock = clock; this.clock = clock;
return this; return this;
} }
@ -42,7 +43,7 @@ public final class SdkTracerProviderBuilder {
* @return this * @return this
*/ */
public SdkTracerProviderBuilder setIdGenerator(IdGenerator idGenerator) { public SdkTracerProviderBuilder setIdGenerator(IdGenerator idGenerator) {
Objects.requireNonNull(idGenerator, "idGenerator"); requireNonNull(idGenerator, "idGenerator");
this.idsGenerator = idGenerator; this.idsGenerator = idGenerator;
return this; return this;
} }
@ -54,7 +55,7 @@ public final class SdkTracerProviderBuilder {
* @return this * @return this
*/ */
public SdkTracerProviderBuilder setResource(Resource resource) { public SdkTracerProviderBuilder setResource(Resource resource) {
Objects.requireNonNull(resource, "resource"); requireNonNull(resource, "resource");
this.resource = resource; this.resource = resource;
return this; return this;
} }
@ -65,8 +66,8 @@ public final class SdkTracerProviderBuilder {
* @return this * @return this
*/ */
public SdkTracerProviderBuilder setTraceConfig(TraceConfig traceConfig) { public SdkTracerProviderBuilder setTraceConfig(TraceConfig traceConfig) {
requireNonNull(traceConfig, "traceConfig");
this.traceConfig = traceConfig; this.traceConfig = traceConfig;
Objects.requireNonNull(traceConfig);
return this; return this;
} }

View File

@ -14,7 +14,7 @@ import static io.opentelemetry.api.common.AttributeKey.longKey;
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey; import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
@ -182,9 +182,8 @@ class RecordEventsReadableSpanTest {
RecordEventsReadableSpan span = createTestSpan(Kind.INTERNAL); RecordEventsReadableSpan span = createTestSpan(Kind.INTERNAL);
SpanData spanData = span.toSpanData(); SpanData spanData = span.toSpanData();
assertThrows( assertThatThrownBy(() -> spanData.getLinks().add(Link.create(SpanContext.getInvalid())))
UnsupportedOperationException.class, .isInstanceOf(UnsupportedOperationException.class);
() -> spanData.getLinks().add(Link.create(SpanContext.getInvalid())));
} }
@Test @Test
@ -192,9 +191,9 @@ class RecordEventsReadableSpanTest {
RecordEventsReadableSpan span = createTestSpan(Kind.INTERNAL); RecordEventsReadableSpan span = createTestSpan(Kind.INTERNAL);
SpanData spanData = span.toSpanData(); SpanData spanData = span.toSpanData();
assertThrows( assertThatThrownBy(
UnsupportedOperationException.class, () -> spanData.getEvents().add(Event.create(1000, "test", Attributes.empty())))
() -> spanData.getEvents().add(Event.create(1000, "test", Attributes.empty()))); .isInstanceOf(UnsupportedOperationException.class);
} }
@Test @Test

View File

@ -15,7 +15,7 @@ import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
@ -72,14 +72,14 @@ class SdkSpanBuilderTest {
@Test @Test
void setSpanKind_null() { void setSpanKind_null() {
assertThrows( assertThatThrownBy(() -> sdkTracer.spanBuilder(SPAN_NAME).setSpanKind(null))
NullPointerException.class, () -> sdkTracer.spanBuilder(SPAN_NAME).setSpanKind(null)); .isInstanceOf(NullPointerException.class);
} }
@Test @Test
void setParent_null() { void setParent_null() {
assertThrows( assertThatThrownBy(() -> sdkTracer.spanBuilder(SPAN_NAME).setParent(null))
NullPointerException.class, () -> sdkTracer.spanBuilder(SPAN_NAME).setParent(null)); .isInstanceOf(NullPointerException.class);
} }
@Test @Test
@ -175,21 +175,22 @@ class SdkSpanBuilderTest {
@Test @Test
void addLinkSpanContext_null() { void addLinkSpanContext_null() {
assertThrows(NullPointerException.class, () -> sdkTracer.spanBuilder(SPAN_NAME).addLink(null)); assertThatThrownBy(() -> sdkTracer.spanBuilder(SPAN_NAME).addLink(null))
.isInstanceOf(NullPointerException.class);
} }
@Test @Test
void addLinkSpanContextAttributes_nullContext() { void addLinkSpanContextAttributes_nullContext() {
assertThrows( assertThatThrownBy(() -> sdkTracer.spanBuilder(SPAN_NAME).addLink(null, Attributes.empty()))
NullPointerException.class, .isInstanceOf(NullPointerException.class);
() -> sdkTracer.spanBuilder(SPAN_NAME).addLink(null, Attributes.empty()));
} }
@Test @Test
void addLinkSpanContextAttributes_nullAttributes() { void addLinkSpanContextAttributes_nullAttributes() {
assertThrows( assertThatThrownBy(
NullPointerException.class, () ->
() -> sdkTracer.spanBuilder(SPAN_NAME).addLink(Span.getInvalid().getSpanContext(), null)); sdkTracer.spanBuilder(SPAN_NAME).addLink(Span.getInvalid().getSpanContext(), null))
.isInstanceOf(NullPointerException.class);
} }
@Test @Test
@ -825,10 +826,10 @@ class SdkSpanBuilderTest {
@Test @Test
void startTimestamp_null() { void startTimestamp_null() {
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> sdkTracer.spanBuilder(SPAN_NAME).setStartTimestamp(-1, TimeUnit.NANOSECONDS))
() -> sdkTracer.spanBuilder(SPAN_NAME).setStartTimestamp(-1, TimeUnit.NANOSECONDS), .isInstanceOf(IllegalArgumentException.class)
"Negative startTimestamp"); .hasMessage("Negative startTimestamp");
} }
@Test @Test

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.trace; package io.opentelemetry.sdk.trace;
import static org.assertj.core.api.Assertions.assertThat; 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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -55,32 +55,30 @@ class SdkTracerProviderTest {
@Test @Test
void builder_NullTraceConfig() { void builder_NullTraceConfig() {
assertThrows( assertThatThrownBy(() -> SdkTracerProvider.builder().setTraceConfig(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> SdkTracerProvider.builder().setTraceConfig(null), .hasMessage("traceConfig");
"traceConfig");
} }
@Test @Test
void builder_NullClock() { void builder_NullClock() {
assertThrows( assertThatThrownBy(() -> SdkTracerProvider.builder().setClock(null))
NullPointerException.class, () -> SdkTracerProvider.builder().setClock(null), "clock"); .isInstanceOf(NullPointerException.class)
.hasMessage("clock");
} }
@Test @Test
void builder_NullResource() { void builder_NullResource() {
assertThrows( assertThatThrownBy(() -> SdkTracerProvider.builder().setResource(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> SdkTracerProvider.builder().setResource(null), .hasMessage("resource");
"resource");
} }
@Test @Test
void builder_NullIdsGenerator() { void builder_NullIdsGenerator() {
assertThrows( assertThatThrownBy(() -> SdkTracerProvider.builder().setIdGenerator(null))
NullPointerException.class, .isInstanceOf(NullPointerException.class)
() -> SdkTracerProvider.builder().setIdGenerator(null), .hasMessage("idGenerator");
"idsGenerator");
} }
@Test @Test

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.trace.config; package io.opentelemetry.sdk.trace.config;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.Sampler;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@ -50,48 +50,42 @@ public class TraceConfigSystemPropertiesTest {
@Test @Test
void updateTraceConfig_InvalidSamplerProbability() { void updateTraceConfig_InvalidSamplerProbability() {
System.setProperty("otel.config.sampler.probability", "-1"); System.setProperty("otel.config.sampler.probability", "-1");
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build());
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfAttributes() { void updateTraceConfig_NonPositiveMaxNumberOfAttributes() {
System.setProperty("otel.span.attribute.count.limit", "-5"); System.setProperty("otel.span.attribute.count.limit", "-5");
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build());
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfEvents() { void updateTraceConfig_NonPositiveMaxNumberOfEvents() {
System.setProperty("otel.span.event.count.limit", "-6"); System.setProperty("otel.span.event.count.limit", "-6");
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build());
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfLinks() { void updateTraceConfig_NonPositiveMaxNumberOfLinks() {
System.setProperty("otel.span.link.count.limit", "-9"); System.setProperty("otel.span.link.count.limit", "-9");
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build());
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerEvent() { void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerEvent() {
System.setProperty("otel.config.max.event.attrs", "-7"); System.setProperty("otel.config.max.event.attrs", "-7");
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build());
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerLink() { void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerLink() {
System.setProperty("otel.config.max.link.attrs", "-10"); System.setProperty("otel.config.max.link.attrs", "-10");
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build())
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().readSystemProperties().build());
} }
} }

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.trace.config; package io.opentelemetry.sdk.trace.config;
import static org.assertj.core.api.Assertions.assertThat; 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 io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.Sampler;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -26,57 +26,52 @@ class TraceConfigTest {
@Test @Test
void updateTraceConfig_NullSampler() { void updateTraceConfig_NullSampler() {
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().setSampler(null))
NullPointerException.class, () -> TraceConfig.getDefault().toBuilder().setSampler(null)); .isInstanceOf(NullPointerException.class);
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfAttributes() { void updateTraceConfig_NonPositiveMaxNumberOfAttributes() {
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfAttributes(0))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfAttributes(0));
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfEvents() { void updateTraceConfig_NonPositiveMaxNumberOfEvents() {
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfEvents(0))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfEvents(0));
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfLinks() { void updateTraceConfig_NonPositiveMaxNumberOfLinks() {
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfLinks(0))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfLinks(0));
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerEvent() { void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerEvent() {
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> TraceConfig.getDefault().toBuilder().setMaxNumberOfAttributesPerEvent(0))
() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfAttributesPerEvent(0)); .isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerLink() { void updateTraceConfig_NonPositiveMaxNumberOfAttributesPerLink() {
assertThrows( assertThatThrownBy(
IllegalArgumentException.class, () -> TraceConfig.getDefault().toBuilder().setMaxNumberOfAttributesPerLink(0))
() -> TraceConfig.getDefault().toBuilder().setMaxNumberOfAttributesPerLink(0)); .isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test
void updateTraceConfig_InvalidTraceIdRatioBased() { void updateTraceConfig_InvalidTraceIdRatioBased() {
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().setTraceIdRatioBased(2))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().setTraceIdRatioBased(2));
} }
@Test @Test
void updateTraceConfig_NegativeTraceIdRatioBased() { void updateTraceConfig_NegativeTraceIdRatioBased() {
assertThrows( assertThatThrownBy(() -> TraceConfig.getDefault().toBuilder().setTraceIdRatioBased(-1))
IllegalArgumentException.class, .isInstanceOf(IllegalArgumentException.class);
() -> TraceConfig.getDefault().toBuilder().setTraceIdRatioBased(-1));
} }
@Test @Test