-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mateusz Rzeszutek
committed
Dec 8, 2022
1 parent
11f609e
commit e235600
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...src/test/java/io/opentelemetry/instrumentation/api/internal/ConfigPropertiesUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |