Skip to content

Commit ae99473

Browse files
Switched to JUnit 5 Assumptions for consistency. Minor code cleanup. (#9126)
1 parent 9519752 commit ae99473

File tree

6 files changed

+21
-26
lines changed

6 files changed

+21
-26
lines changed

dd-java-agent/agent-profiling/profiling-controller-ddprof/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ dependencies {
2929

3030
testImplementation libs.bundles.junit5
3131
testImplementation libs.bundles.mockito
32-
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
3332
testImplementation project(':dd-java-agent:agent-profiling')
3433
}
3534

dd-java-agent/agent-profiling/profiling-controller-ddprof/gradle.lockfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ org.codehaus.groovy:groovy:3.0.17=testCompileClasspath,testRuntimeClasspath
8585
org.codenarc:CodeNarc:2.2.0=codenarc
8686
org.dom4j:dom4j:2.1.3=spotbugs
8787
org.gmetrics:GMetrics:1.1=codenarc
88-
org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath
89-
org.hamcrest:hamcrest:2.2=testCompileClasspath,testRuntimeClasspath
9088
org.jacoco:org.jacoco.agent:0.8.5=jacocoAgent,jacocoAnt
9189
org.jacoco:org.jacoco.ant:0.8.5=jacocoAnt
9290
org.jacoco:org.jacoco.core:0.8.5=jacocoAnt

dd-java-agent/agent-profiling/profiling-controller-ddprof/src/test/java/com/datadog/profiling/controller/ddprof/DatadogProfilerControllerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import datadog.trace.api.profiling.RecordingData;
99
import datadog.trace.bootstrap.config.provider.ConfigProvider;
1010
import java.util.Properties;
11-
import org.junit.Assume;
11+
import org.junit.jupiter.api.Assumptions;
1212
import org.junit.jupiter.api.Test;
1313
import org.junit.jupiter.api.extension.ExtendWith;
1414
import org.mockito.junit.jupiter.MockitoExtension;
@@ -20,7 +20,7 @@ public class DatadogProfilerControllerTest {
2020

2121
@Test
2222
public void testCreateContinuousRecording() throws Exception {
23-
Assume.assumeTrue(OperatingSystem.isLinux());
23+
Assumptions.assumeTrue(OperatingSystem.isLinux());
2424
Properties props = new Properties();
2525
props.put(PROFILING_AUXILIARY_TYPE, "ddprof");
2626
ConfigProvider configProvider = ConfigProvider.withPropertiesOverride(props);

dd-java-agent/agent-profiling/profiling-controller-ddprof/src/test/java/com/datadog/profiling/controller/ddprof/DatadogProfilerOngoingRecordingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.datadog.profiling.ddprof.JavaProfilerLoader;
77
import datadog.trace.api.profiling.RecordingData;
88
import java.time.Instant;
9-
import org.junit.Assume;
109
import org.junit.jupiter.api.AfterEach;
10+
import org.junit.jupiter.api.Assumptions;
1111
import org.junit.jupiter.api.BeforeAll;
1212
import org.junit.jupiter.api.BeforeEach;
1313
import org.junit.jupiter.api.Test;
@@ -34,7 +34,7 @@ public class DatadogProfilerOngoingRecordingTest {
3434
public static void setupAll() {
3535
// If the profiler couldn't be loaded, the reason why is saved.
3636
// This test assumes the profiler could be loaded.
37-
Assume.assumeNoException("profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
37+
Assumptions.assumeTrue(JavaProfilerLoader.REASON_NOT_LOADED == null, "profiler not available");
3838
}
3939

4040
@BeforeEach

dd-java-agent/agent-profiling/profiling-ddprof/src/test/java/com/datadog/profiling/ddprof/DatadogProfilerRecordingTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import java.io.InputStream;
1111
import java.nio.file.Files;
1212
import java.time.Instant;
13-
import org.junit.Assume;
1413
import org.junit.jupiter.api.AfterEach;
14+
import org.junit.jupiter.api.Assumptions;
1515
import org.junit.jupiter.api.BeforeEach;
1616
import org.junit.jupiter.api.Test;
1717

@@ -21,17 +21,17 @@ class DatadogProfilerRecordingTest {
2121
private DatadogProfilerRecording recording;
2222

2323
@BeforeEach
24-
void setup() throws Exception {
25-
Assume.assumeTrue(OperatingSystem.isLinux());
26-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
24+
void setup() {
25+
Assumptions.assumeTrue(OperatingSystem.isLinux());
26+
Assumptions.assumeTrue(JavaProfilerLoader.REASON_NOT_LOADED == null, "Profiler not available");
2727
profiler = DatadogProfiler.newInstance(ConfigProvider.getInstance());
28-
Assume.assumeFalse(profiler.isActive());
28+
Assumptions.assumeFalse(profiler.isActive());
2929
recording = (DatadogProfilerRecording) profiler.start();
30-
Assume.assumeTrue(recording != null);
30+
Assumptions.assumeTrue(recording != null);
3131
}
3232

3333
@AfterEach
34-
void shutdown() throws Exception {
34+
void shutdown() {
3535
// Apparently, failed 'assume' does not prevent shutdown from running
3636
// Do a sanity check before invoking profiler methods
3737
if (profiler != null && recording != null) {
@@ -40,24 +40,24 @@ void shutdown() throws Exception {
4040
}
4141

4242
@Test
43-
void testClose() throws Exception {
44-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
43+
void testClose() {
44+
Assumptions.assumeTrue(JavaProfilerLoader.REASON_NOT_LOADED == null, "Profiler not available");
4545
assertTrue(Files.exists(recording.getRecordingFile()));
4646
recording.close();
4747
assertFalse(Files.exists(recording.getRecordingFile()));
4848
}
4949

5050
@Test
51-
void testStop() throws Exception {
52-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
51+
void testStop() {
52+
Assumptions.assumeTrue(JavaProfilerLoader.REASON_NOT_LOADED == null, "Profiler not available");
5353
RecordingData data = recording.stop();
5454
assertNotNull(data);
5555
assertTrue(Files.exists(recording.getRecordingFile()));
5656
}
5757

5858
@Test
5959
void testSnapshot() throws Exception {
60-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
60+
Assumptions.assumeTrue(JavaProfilerLoader.REASON_NOT_LOADED == null, "Profiler not available");
6161
RecordingData data = recording.snapshot(Instant.now());
6262
assertNotNull(data);
6363
assertTrue(Files.exists(recording.getRecordingFile()));

dd-java-agent/agent-profiling/profiling-ddprof/src/test/java/com/datadog/profiling/ddprof/DatadogProfilerTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static org.junit.jupiter.api.Assertions.assertTrue;
77

88
import com.datadog.profiling.controller.OngoingRecording;
9-
import com.datadog.profiling.controller.UnsupportedEnvironmentException;
109
import com.datadog.profiling.utils.ProfilingMode;
1110
import datadog.environment.OperatingSystem;
1211
import datadog.trace.api.config.ProfilingConfig;
@@ -21,7 +20,6 @@
2120
import java.util.UUID;
2221
import java.util.stream.IntStream;
2322
import java.util.stream.Stream;
24-
import org.junit.Assume;
2523
import org.junit.jupiter.api.Assumptions;
2624
import org.junit.jupiter.api.BeforeEach;
2725
import org.junit.jupiter.api.Test;
@@ -43,7 +41,7 @@ public void setup() {
4341

4442
@Test
4543
void test() throws Exception {
46-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
44+
Assumptions.assumeTrue(JavaProfilerLoader.REASON_NOT_LOADED == null, "Profiler not available");
4745
DatadogProfiler profiler = DatadogProfiler.newInstance(ConfigProvider.getInstance());
4846
assertFalse(profiler.enabledModes().isEmpty());
4947

@@ -75,8 +73,8 @@ void test() throws Exception {
7573

7674
@ParameterizedTest
7775
@MethodSource("profilingModes")
78-
void testStartCmd(boolean cpu, boolean wall, boolean alloc, boolean memleak) throws Exception {
79-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
76+
void testStartCmd(boolean cpu, boolean wall, boolean alloc, boolean memleak) {
77+
Assumptions.assumeTrue(JavaProfilerLoader.REASON_NOT_LOADED == null, "Profiler not available");
8078
DatadogProfiler profiler =
8179
DatadogProfiler.newInstance(configProvider(cpu, wall, alloc, memleak));
8280

@@ -105,7 +103,7 @@ private static Stream<Arguments> profilingModes() {
105103
}
106104

107105
@Test
108-
public void testContextRegistration() throws UnsupportedEnvironmentException {
106+
public void testContextRegistration() {
109107
// warning - the profiler is a process wide singleton and can't be reinitialised
110108
// so there is only one shot to test it here, 'foo,bar' need to be kept in the same
111109
// order whether in the list or the enum, and any other test which tries to register
@@ -121,7 +119,7 @@ public void testContextRegistration() throws UnsupportedEnvironmentException {
121119
DatadogProfilerContextSetter fooSetter = new DatadogProfilerContextSetter("foo", profiler);
122120
DatadogProfilerContextSetter barSetter = new DatadogProfilerContextSetter("bar", profiler);
123121
int[] snapshot0 = profiler.snapshot();
124-
try (ProfilingScope outer = new DatadogProfilingScope(profiler)) {
122+
try (ProfilingScope ignored = new DatadogProfilingScope(profiler)) {
125123
fooSetter.set("foo0");
126124
barSetter.set("bar0");
127125
int[] snapshot1 = profiler.snapshot();

0 commit comments

Comments
 (0)