Skip to content

Commit 3c2ade7

Browse files
committed
boos test coverage
1 parent 295c5f3 commit 3c2ade7

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/LogAssertionsTest.java

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
package io.opentelemetry.sdk.testing.assertj;
77

8+
import static io.opentelemetry.api.common.AttributeKey.booleanArrayKey;
9+
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
10+
import static io.opentelemetry.api.common.AttributeKey.doubleArrayKey;
11+
import static io.opentelemetry.api.common.AttributeKey.doubleKey;
12+
import static io.opentelemetry.api.common.AttributeKey.longArrayKey;
13+
import static io.opentelemetry.api.common.AttributeKey.longKey;
14+
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
15+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
816
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
917
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
1018
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
@@ -40,7 +48,7 @@ public class LogAssertionsTest {
4048
private static final String TRACE_ID = "00000000000000010000000000000002";
4149
private static final String SPAN_ID = "0000000000000003";
4250

43-
private static final AttributeKey<String> DOG = AttributeKey.stringKey("dog");
51+
private static final AttributeKey<String> DOG = stringKey("dog");
4452
private static final Attributes ATTRIBUTES =
4553
Attributes.builder()
4654
.put("bear", "mya")
@@ -86,7 +94,7 @@ void passing() {
8694
attributes ->
8795
assertThat(attributes)
8896
.hasSize(2)
89-
.containsEntry(AttributeKey.stringKey("dog"), "bark")
97+
.containsEntry(stringKey("dog"), "bark")
9098
.hasEntrySatisfying(DOG, value -> assertThat(value).hasSize(4))
9199
.hasEntrySatisfying(
92100
AttributeKey.booleanKey("dog is cute"),
@@ -125,14 +133,13 @@ void passing() {
125133
attributes ->
126134
OpenTelemetryAssertions.assertThat(attributes)
127135
.hasSize(8)
128-
.containsEntry(AttributeKey.stringKey("bear"), "mya")
129-
.hasEntrySatisfying(
130-
AttributeKey.stringKey("bear"), value -> assertThat(value).hasSize(3))
136+
.containsEntry(stringKey("bear"), "mya")
137+
.hasEntrySatisfying(stringKey("bear"), value -> assertThat(value).hasSize(3))
131138
.containsEntry("bear", "mya")
132139
.containsEntry("warm", true)
133140
.containsEntry("temperature", 30)
134-
.containsEntry(AttributeKey.longKey("temperature"), 30L)
135-
.containsEntry(AttributeKey.longKey("temperature"), 30)
141+
.containsEntry(longKey("temperature"), 30L)
142+
.containsEntry(longKey("temperature"), 30)
136143
.containsEntry("length", 1.2)
137144
.containsEntry("colors", "red", "blue")
138145
.containsEntryWithStringValuesOf("colors", Arrays.asList("red", "blue"))
@@ -142,7 +149,7 @@ void passing() {
142149
.containsEntryWithLongValuesOf("scores", Arrays.asList(0L, 1L))
143150
.containsEntry("coins", 0.01, 0.05, 0.1)
144151
.containsEntryWithDoubleValuesOf("coins", Arrays.asList(0.01, 0.05, 0.1))
145-
.containsKey(AttributeKey.stringKey("bear"))
152+
.containsKey(stringKey("bear"))
146153
.containsKey("bear")
147154
.containsOnly(
148155
attributeEntry("bear", "mya"),
@@ -154,12 +161,12 @@ void passing() {
154161
attributeEntry("scores", 0L, 1L),
155162
attributeEntry("coins", 0.01, 0.05, 0.1)))
156163
.hasAttributesSatisfying(
157-
equalTo(AttributeKey.stringKey("bear"), "mya"),
164+
equalTo(stringKey("bear"), "mya"),
158165
equalTo(AttributeKey.booleanArrayKey("conditions"), Arrays.asList(false, true)))
159166
.hasAttributesSatisfyingExactly(
160-
equalTo(AttributeKey.stringKey("bear"), "mya"),
167+
equalTo(stringKey("bear"), "mya"),
161168
equalTo(AttributeKey.booleanKey("warm"), true),
162-
equalTo(AttributeKey.longKey("temperature"), 30L),
169+
equalTo(longKey("temperature"), 30L),
163170
equalTo(AttributeKey.doubleKey("length"), 1.2),
164171
equalTo(AttributeKey.stringArrayKey("colors"), Arrays.asList("red", "blue")),
165172
equalTo(AttributeKey.booleanArrayKey("conditions"), Arrays.asList(false, true)),
@@ -235,7 +242,7 @@ void failure() {
235242
.hasAttributesSatisfying(
236243
attributes ->
237244
OpenTelemetryAssertions.assertThat(attributes)
238-
.containsKey(AttributeKey.stringKey("cat"))))
245+
.containsKey(stringKey("cat"))))
239246
.isInstanceOf(AssertionError.class);
240247
assertThatThrownBy(
241248
() ->
@@ -263,21 +270,18 @@ void failure() {
263270
attributes ->
264271
OpenTelemetryAssertions.assertThat(attributes)
265272
.hasEntrySatisfying(
266-
AttributeKey.stringKey("bear"),
267-
value -> assertThat(value).hasSize(2))))
273+
stringKey("bear"), value -> assertThat(value).hasSize(2))))
268274
.isInstanceOf(AssertionError.class);
269275
assertThatThrownBy(
270-
() ->
271-
assertThat(LOG_DATA)
272-
.hasAttributesSatisfying(equalTo(AttributeKey.stringKey("bear"), "moo")))
276+
() -> assertThat(LOG_DATA).hasAttributesSatisfying(equalTo(stringKey("bear"), "moo")))
273277
.isInstanceOf(AssertionError.class);
274278
assertThatThrownBy(
275279
() ->
276280
assertThat(LOG_DATA)
277281
.hasAttributesSatisfyingExactly(
278-
equalTo(AttributeKey.stringKey("bear"), "mya"),
282+
equalTo(stringKey("bear"), "mya"),
279283
equalTo(AttributeKey.booleanKey("warm"), true),
280-
equalTo(AttributeKey.longKey("temperature"), 30L),
284+
equalTo(longKey("temperature"), 30L),
281285
equalTo(AttributeKey.doubleKey("length"), 1.2)))
282286
.isInstanceOf(AssertionError.class);
283287
assertThatThrownBy(() -> assertThat(LOG_DATA).hasTotalAttributeCount(11))
@@ -296,25 +300,41 @@ void eventBodyAssertions() {
296300
.builder("foo")
297301
.put("foostr", "bar")
298302
.put("foobool", true)
299-
.put("foolong", 12)
303+
.put("foolong", 12L)
300304
.put("foodbl", 12.0)
301305
.put("foostra", "bar", "baz", "buzz")
302306
.put("foolonga", 9, 0, 2, 1, 0)
303307
.put("foodbla", 9.1, 0.2, 2.3, 1.4, 0.5)
304308
.put("fooboola", true, true, true, false)
305309
.put("fooany", AnyValue.of("grim"))
310+
.put(stringKey("ak_str"), "bar")
311+
.put(booleanKey("ak_bool"), true)
312+
.put(longKey("ak_long"), 12L)
313+
.put(doubleKey("ak_dbl"), 12.0)
314+
.put(stringArrayKey("ak_stra"), Arrays.asList("bar", "baz", "buzz"))
315+
.put(longArrayKey("ak_longa"), Arrays.asList(9L, 0L, 2L, 1L, 0L))
316+
.put(doubleArrayKey("ak_dbla"), Arrays.asList(9.1, 0.2, 2.3, 1.4, 0.5))
317+
.put(booleanArrayKey("ak_boola"), Arrays.asList(true, true, true, false))
306318
.emit();
307319
List<LogRecordData> logs = exporter.getFinishedLogRecordItems();
308320
assertThat(logs).hasSize(1);
309321
assertThat(logs.get(0))
310322
.hasBodyField("foostr", "bar")
311323
.hasBodyField("foobool", true)
312-
.hasBodyField("foolong", 12)
324+
.hasBodyField("foolong", 12L)
313325
.hasBodyField("foodbl", 12.0)
314326
.hasBodyField("foostra", "bar", "baz", "buzz")
315327
.hasBodyField("foolonga", 9, 0, 2, 1, 0)
316328
.hasBodyField("foodbla", 9.1, 0.2, 2.3, 1.4, 0.5)
317329
.hasBodyField("fooboola", true, true, true, false)
318-
.hasBodyField("fooany", AnyValue.of("grim"));
330+
.hasBodyField("fooany", AnyValue.of("grim"))
331+
.hasBodyField(stringKey("ak_str"), "bar")
332+
.hasBodyField(booleanKey("ak_bool"), true)
333+
.hasBodyField(longKey("ak_long"), 12L)
334+
.hasBodyField(doubleKey("ak_dbl"), 12.0)
335+
.hasBodyField(stringArrayKey("ak_stra"), Arrays.asList("bar", "baz", "buzz"))
336+
.hasBodyField(longArrayKey("ak_longa"), Arrays.asList(9L, 0L, 2L, 1L, 0L))
337+
.hasBodyField(doubleArrayKey("ak_dbla"), Arrays.asList(9.1, 0.2, 2.3, 1.4, 0.5))
338+
.hasBodyField(booleanArrayKey("ak_boola"), Arrays.asList(true, true, true, false));
319339
}
320340
}

0 commit comments

Comments
 (0)