Skip to content

Commit 4dbf0a2

Browse files
trasklaurit
andauthored
Add a test (#48)
Co-authored-by: Lauri Tulmin <[email protected]>
1 parent c09ec44 commit 4dbf0a2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ dependencies {
4444
compileOnly("io.grpc:grpc-api:$grpcVersion")
4545
compileOnly("io.grpc:grpc-protobuf:$grpcVersion")
4646
compileOnly("io.grpc:grpc-stub:$grpcVersion")
47+
48+
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
49+
testImplementation("org.assertj:assertj-core:3.27.3")
4750
}
4851

4952
protobuf {
@@ -76,6 +79,10 @@ var protoVersion = if (properties.contains(
7679
val protoArchive = file("$buildDir/archives/opentelemetry-proto-$protoVersion.zip")
7780

7881
tasks {
82+
test {
83+
useJUnitPlatform()
84+
}
85+
7986
val downloadProtoArchive by registering(Download::class) {
8087
onlyIf { !protoArchive.exists() }
8188
src("https://github.com/open-telemetry/opentelemetry-proto/archive/v$protoVersion.zip")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.proto;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
import static org.assertj.core.api.Assertions.fail;
10+
11+
import java.lang.reflect.Field;
12+
import org.junit.jupiter.api.Test;
13+
14+
/** A placeholder test which verifies that the generated classes compile and can load. */
15+
public class AvailabilityTest {
16+
17+
@Test
18+
void available() {
19+
isValidClass("io.opentelemetry.proto.trace.v1.Span");
20+
isValidClass("io.opentelemetry.proto.metrics.v1.Metric");
21+
isValidClass("io.opentelemetry.proto.logs.v1.LogRecord");
22+
}
23+
24+
private static void isValidClass(String fqcn) {
25+
Class<?> clazz = null;
26+
try {
27+
clazz = Class.forName(fqcn);
28+
} catch (ClassNotFoundException e) {
29+
fail(e.getMessage());
30+
}
31+
Field[] declaredFields = clazz.getDeclaredFields();
32+
Class<?>[] declaredClasses = clazz.getDeclaredClasses();
33+
boolean hasFieldsOrInnerClasses =
34+
(declaredFields != null && declaredFields.length > 0)
35+
|| (declaredClasses != null && declaredClasses.length > 0);
36+
assertThat(hasFieldsOrInnerClasses).withFailMessage(() -> fqcn + " is empty").isTrue();
37+
}
38+
}

0 commit comments

Comments
 (0)