Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ static AttributeAssertion create(
// suppressing here.
@SuppressWarnings("NullAway")
static AbstractAssert<?, ?> attributeValueAssertion(AttributeKey<?> key, @Nullable Object value) {
AbstractAssert<? extends AbstractAssert<?, ?>, ?> abstractAssert = makeAssertion(key, value);
String description = "%s attribute '%s'";
return abstractAssert.as(description, key.getType(), key.getKey());
}

private static AbstractAssert<? extends AbstractAssert<?, ?>, ?> makeAssertion(
AttributeKey<?> key, Object value) {
switch (key.getType()) {
case STRING:
return assertThat((String) value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.sdk.testing.assertj;

import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

import io.opentelemetry.api.common.AttributeKey;
import org.assertj.core.api.AbstractAssert;
import org.junit.jupiter.api.Test;

class AttributeAssertionTest {

@Test
void nullAttr_errorMessageContainsAttrName() {
AttributeKey<String> key = AttributeKey.stringKey("flib");

assertThatThrownBy(
() ->
AttributeAssertion.create(key, AbstractAssert::isNotNull)
.getAssertion()
.accept(AttributeAssertion.attributeValueAssertion(key, null)))
.isInstanceOf(AssertionError.class)
.hasMessage("[STRING attribute 'flib'] \nExpecting actual not to be null");
}
}