Skip to content

Commit aaa1833

Browse files
committed
convert to java
1 parent 2e9eb2c commit aaa1833

File tree

2 files changed

+37
-39
lines changed

2 files changed

+37
-39
lines changed

javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/ConfigurationFileTest.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,28 @@
77

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

10+
import java.io.File;
11+
import java.io.FileWriter;
12+
import java.io.IOException;
13+
import java.util.Map;
1014
import org.junit.Rule;
1115
import org.junit.contrib.java.lang.system.EnvironmentVariables;
1216
import org.junit.jupiter.api.AfterEach;
1317
import org.junit.jupiter.api.BeforeEach;
1418
import org.junit.jupiter.api.Test;
1519
import org.junit.jupiter.api.io.TempDir;
1620

17-
import java.io.File;
18-
import java.io.FileWriter;
19-
import java.io.IOException;
20-
import java.util.Properties;
21-
2221
class ConfigurationFileTest {
2322

24-
@TempDir
25-
File tmpDir;
23+
@TempDir File tmpDir;
2624

27-
@Rule
28-
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
25+
@Rule public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
2926

3027
private String originalSystemProperty;
31-
private String originalEnvironmentVariable;
3228

3329
@BeforeEach
3430
void setUp() {
3531
originalSystemProperty = System.getProperty("otel.javaagent.configuration-file");
36-
originalEnvironmentVariable = System.getenv("OTEL_JAVAAGENT_CONFIGURATION_FILE");
3732
System.clearProperty("otel.javaagent.configuration-file");
3833
}
3934

@@ -49,47 +44,47 @@ void tearDown() {
4944
@Test
5045
void shouldUseEnvVar() throws IOException {
5146
String path = createFile("config", "property1=val-env");
52-
environmentVariables.set("OTEL_JAVAAGENT_CONFIGURATION_FILE", path)
47+
environmentVariables.set("OTEL_JAVAAGENT_CONFIGURATION_FILE", path);
5348

54-
Properties properties = ConfigurationFile.loadConfigFile();
49+
Map<String, String> properties = ConfigurationFile.loadConfigFile();
5550

56-
assertThat(properties.get("property1")).isEqualTo("val-env");
51+
assertThat(properties).containsEntry("property1", "val-env");
5752
}
5853

5954
@Test
6055
void shouldUseSystemProperty() throws IOException {
6156
String path = createFile("config", "property1=val-sys");
6257
System.setProperty("otel.javaagent.configuration-file", path);
6358

64-
Properties properties = ConfigurationFile.loadConfigFile();
59+
Map<String, String> properties = ConfigurationFile.loadConfigFile();
6560

66-
assertThat(properties.get("property1")).isEqualTo("val-sys");
61+
assertThat(properties).containsEntry("property1", "val-sys");
6762
}
6863

6964
@Test
7065
void shouldUseSystemPropertyOverEnvVar() throws IOException {
71-
def pathEnv = createFile("configEnv", "property1=val-env")
66+
String pathEnv = createFile("configEnv", "property1=val-env");
7267
String path = createFile("config", "property1=val-sys");
7368
System.setProperty("otel.javaagent.configuration-file", path);
74-
environmentVariables.set("OTEL_JAVAAGENT_CONFIGURATION_FILE", pathEnv)
69+
environmentVariables.set("OTEL_JAVAAGENT_CONFIGURATION_FILE", pathEnv);
7570

76-
Properties properties = ConfigurationFile.loadConfigFile();
71+
Map<String, String> properties = ConfigurationFile.loadConfigFile();
7772

78-
assertThat(properties.get("property1")).isEqualTo("val-sys");
73+
assertThat(properties).containsEntry("property1", "val-sys");
7974
}
8075

8176
@Test
8277
void shouldReturnEmptyPropertiesIfFileDoesNotExist() {
8378
System.setProperty("otel.javaagent.configuration-file", "somePath");
8479

85-
Properties properties = ConfigurationFile.loadConfigFile();
80+
Map<String, String> properties = ConfigurationFile.loadConfigFile();
8681

8782
assertThat(properties).isEmpty();
8883
}
8984

9085
@Test
9186
void shouldReturnEmptyPropertiesIfPropertyIsNotSet() {
92-
Properties properties = ConfigurationFile.loadConfigFile();
87+
Map<String, String> properties = ConfigurationFile.loadConfigFile();
9388

9489
assertThat(properties).isEmpty();
9590
}

javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParserTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
import static java.util.Collections.emptyMap;
99
import static org.assertj.core.api.Assertions.assertThat;
1010

11-
import org.junit.jupiter.params.ParameterizedTest;
12-
import org.junit.jupiter.params.provider.Arguments;
13-
import org.junit.jupiter.params.provider.MethodSource;
14-
1511
import java.util.Collections;
1612
import java.util.HashMap;
1713
import java.util.HashSet;
1814
import java.util.Map;
1915
import java.util.Set;
2016
import java.util.stream.Stream;
17+
import org.junit.jupiter.params.ParameterizedTest;
18+
import org.junit.jupiter.params.provider.Arguments;
19+
import org.junit.jupiter.params.provider.MethodSource;
2120

2221
class MethodsConfigurationParserTest {
2322

@@ -33,26 +32,30 @@ static Stream<Arguments> configurationTestData() {
3332
return Stream.of(
3433
Arguments.of(null, emptyMap()),
3534
Arguments.of(" ", emptyMap()),
36-
Arguments.of("some.package.ClassName",
37-
Collections.<String, Set<String>>singletonMap("some.package.ClassName",
38-
Collections.emptySet())),
35+
Arguments.of(
36+
"some.package.ClassName",
37+
Collections.<String, Set<String>>singletonMap(
38+
"some.package.ClassName", Collections.emptySet())),
3939
Arguments.of("some.package.ClassName[ , ]", emptyMap()),
4040
Arguments.of("some.package.ClassName[ , method]", emptyMap()),
41-
Arguments.of("some.package.Class$Name[ method , ]",
41+
Arguments.of(
42+
"some.package.Class$Name[ method , ]",
4243
Collections.singletonMap("some.package.Class$Name", createSet("method"))),
43-
Arguments.of("ClassName[ method1,]",
44-
Collections.singletonMap("ClassName", createSet("method1"))),
45-
Arguments.of("ClassName[method1 , method2]",
44+
Arguments.of(
45+
"ClassName[ method1,]", Collections.singletonMap("ClassName", createSet("method1"))),
46+
Arguments.of(
47+
"ClassName[method1 , method2]",
4648
Collections.singletonMap("ClassName", createSet("method1", "method2"))),
47-
Arguments.of("Class$1[method1 ] ; Class$2[ method2];",
49+
Arguments.of(
50+
"Class$1[method1 ] ; Class$2[ method2];",
4851
createTwoEntryMap("Class$1", createSet("method1"), "Class$2", createSet("method2"))),
49-
Arguments.of("Duplicate[method1] ; Duplicate[method2] ;Duplicate[method3];",
50-
Collections.singletonMap("Duplicate", createSet("method3")))
51-
);
52+
Arguments.of(
53+
"Duplicate[method1] ; Duplicate[method2] ;Duplicate[method3];",
54+
Collections.singletonMap("Duplicate", createSet("method3"))));
5255
}
5356

54-
private static Map<String, Set<String>> createTwoEntryMap(String key1, Set<String> value1,
55-
String key2, Set<String> value2) {
57+
private static Map<String, Set<String>> createTwoEntryMap(
58+
String key1, Set<String> value1, String key2, Set<String> value2) {
5659
Map<String, Set<String>> map = new HashMap<>();
5760
map.put(key1, value1);
5861
map.put(key2, value2);

0 commit comments

Comments
 (0)