Skip to content

Commit

Permalink
add missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Dec 8, 2022
1 parent 11f609e commit e235600
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
7 changes: 7 additions & 0 deletions instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
testImplementation(project(":testing-common"))
testImplementation("io.opentelemetry:opentelemetry-sdk-metrics")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
testImplementation("org.junit-pioneer:junit-pioneer")

jmhImplementation(project(":instrumentation-api-semconv"))
}
Expand All @@ -35,4 +36,10 @@ tasks {
isEnabled.set(false)
}
}

withType<Test>().configureEach {
// required on jdk17
jvmArgs("--add-opens=java.base/java.util=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.internal;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetEnvironmentVariable;
import org.junitpioneer.jupiter.SetSystemProperty;

class ConfigPropertiesUtilTest {

@SetEnvironmentVariable(key = "TEST_PROPERTY_STRING", value = "env")
@SetSystemProperty(key = "test.property.string", value = "sys")
@Test
void getString_systemProperty() {
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isEqualTo("sys");
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_STRING", value = "env")
@Test
void getString_environmentVariable() {
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isEqualTo("env");
}

@Test
void getString_none() {
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isNull();
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_INT", value = "12")
@SetSystemProperty(key = "test.property.int", value = "42")
@Test
void getInt_systemProperty() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(42);
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_INT", value = "12")
@Test
void getInt_environmentVariable() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(12);
}

@Test
void getInt_none() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(-1);
}

@SetSystemProperty(key = "test.property.int", value = "not a number")
@Test
void getInt_invalidNumber() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(-1);
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_BOOLEAN", value = "false")
@SetSystemProperty(key = "test.property.boolean", value = "true")
@Test
void getBoolean_systemProperty() {
assertThat(ConfigPropertiesUtil.getBoolean("test.property.boolean", false)).isTrue();
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_BOOLEAN", value = "true")
@Test
void getBoolean_environmentVariable() {
assertThat(ConfigPropertiesUtil.getBoolean("test.property.boolean", false)).isTrue();
}

@Test
void getBoolean_none() {
assertThat(ConfigPropertiesUtil.getBoolean("test.property.boolean", false)).isFalse();
}
}

0 comments on commit e235600

Please sign in to comment.