Skip to content

Commit 8be88a9

Browse files
Copilottrask
andcommitted
Convert JUnit assertions to AssertJ in jfr-connection module
Co-authored-by: trask <[email protected]>
1 parent 6bf3844 commit 8be88a9

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

jfr-connection/src/test/java/io/opentelemetry/contrib/jfr/connection/FlightRecorderDiagnosticCommandConnectionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
package io.opentelemetry.contrib.jfr.connection;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
import static org.junit.jupiter.api.Assertions.assertThrows;
10-
import static org.junit.jupiter.api.Assertions.fail;
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
10+
import static org.assertj.core.api.Assertions.fail;
1111
import static org.mockito.ArgumentMatchers.any;
1212
import static org.mockito.ArgumentMatchers.anyString;
1313
import static org.mockito.Mockito.mock;

jfr-connection/src/test/java/io/opentelemetry/contrib/jfr/connection/RecordingConfigurationTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
package io.opentelemetry.contrib.jfr.connection;
77

8-
import static org.junit.jupiter.api.Assertions.assertNotNull;
9-
import static org.junit.jupiter.api.Assertions.assertThrows;
10-
import static org.junit.jupiter.api.Assertions.assertTrue;
11-
import static org.junit.jupiter.api.Assertions.fail;
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
10+
import static org.assertj.core.api.Assertions.fail;
1211

1312
import java.io.IOException;
1413
import java.nio.file.Files;
@@ -44,18 +43,20 @@ void tearDown() {
4443

4544
@Test
4645
void nullConfigThrows() {
47-
assertThrows(IllegalArgumentException.class, () -> new JfcFileConfiguration(null));
46+
assertThatThrownBy(() -> new JfcFileConfiguration(null))
47+
.isInstanceOf(IllegalArgumentException.class);
4848
}
4949

5050
@Test
5151
void brokenJfcConfigFileThrowsError() {
52-
assertThrows(RuntimeMBeanException.class, () -> executeRecording("brokenJfcFile.jfc"));
52+
assertThatThrownBy(() -> executeRecording("brokenJfcFile.jfc"))
53+
.isInstanceOf(RuntimeMBeanException.class);
5354
}
5455

5556
@Test
5657
void jfcFileFromInputStreamCanBeRead() {
5758
IItemCollection recordingContent = executeRecording("sampleJfcFile.jfc");
58-
assertTrue(containsEvent(recordingContent, "jdk.ThreadAllocationStatistics"));
59+
assertThat(containsEvent(recordingContent, "jdk.ThreadAllocationStatistics")).isTrue();
5960
}
6061

6162
@Test
@@ -68,9 +69,9 @@ void mapConfiguration() {
6869
RecordingConfiguration recordingConfiguration = new MapConfiguration(recordingConfigAsMap);
6970

7071
IItemCollection recordingContent = excecuteRecordingWithConfig(recordingConfiguration);
71-
assertNotNull(recordingContent, "excecuteRecordingWithConfig returned null");
72-
assertTrue(containsEvent(recordingContent, "jdk.ObjectAllocationInNewTLAB"));
73-
assertTrue(containsEvent(recordingContent, "jdk.ObjectAllocationOutsideTLAB"));
72+
assertThat(recordingContent).as("excecuteRecordingWithConfig returned null").isNotNull();
73+
assertThat(containsEvent(recordingContent, "jdk.ObjectAllocationInNewTLAB")).isTrue();
74+
assertThat(containsEvent(recordingContent, "jdk.ObjectAllocationOutsideTLAB")).isTrue();
7475
}
7576

7677
private static boolean containsEvent(IItemCollection recordingContent, String eventName) {
@@ -110,7 +111,7 @@ private IItemCollection excecuteRecordingWithConfig(RecordingConfiguration confi
110111
}
111112
recording.stop();
112113
recording.dump(dumpFile.toString());
113-
assertTrue(Files.exists(dumpFile));
114+
assertThat(Files.exists(dumpFile)).isTrue();
114115

115116
try {
116117
return JfrLoaderToolkit.loadEvents(dumpFile.toFile());

jfr-connection/src/test/java/io/opentelemetry/contrib/jfr/connection/RecordingOptionsTest.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ private static Stream<Arguments> testGetName() {
3333
@MethodSource
3434
void testGetName(String testValue, String expected) {
3535
RecordingOptions opts = new RecordingOptions.Builder().name(testValue).build();
36-
assertEquals(expected, opts.getName());
36+
assertThat(opts.getName()).isEqualTo(expected);
3737
}
3838

3939
@Test
4040
void testGetNameDefault() {
4141
String expected = "";
4242
RecordingOptions opts = new RecordingOptions.Builder().build();
43-
assertEquals(expected, opts.getName());
43+
assertThat(opts.getName()).isEqualTo(expected);
4444
}
4545

4646
@Keep
@@ -64,14 +64,14 @@ static Stream<Arguments> testGetMaxAge() {
6464
@MethodSource
6565
void testGetMaxAge(String testValue, String expected) {
6666
RecordingOptions opts = new RecordingOptions.Builder().maxAge(testValue).build();
67-
assertEquals(expected, opts.getMaxAge());
67+
assertThat(opts.getMaxAge()).isEqualTo(expected);
6868
}
6969

7070
@Test
7171
void testGetMaxAgeDefault() {
7272
String expected = "0";
7373
RecordingOptions opts = new RecordingOptions.Builder().build();
74-
assertEquals(expected, opts.getMaxAge());
74+
assertThat(opts.getMaxAge()).isEqualTo(expected);
7575
}
7676

7777
@Keep
@@ -91,9 +91,9 @@ private static Stream<Arguments> testGetMaxAgeNegative() {
9191
@ParameterizedTest
9292
@MethodSource
9393
void testGetMaxAgeNegative(String badValue) {
94-
assertThrows(
95-
IllegalArgumentException.class,
96-
() -> new RecordingOptions.Builder().maxAge(badValue).build());
94+
assertThatThrownBy(
95+
() -> new RecordingOptions.Builder().maxAge(badValue).build())
96+
.isInstanceOf(IllegalArgumentException.class);
9797
}
9898

9999
@Keep
@@ -113,14 +113,14 @@ private static Stream<Arguments> testGetMaxSize() {
113113
@MethodSource
114114
void testGetMaxSize(String testValue, String expected) {
115115
RecordingOptions opts = new RecordingOptions.Builder().maxSize(testValue).build();
116-
assertEquals(expected, opts.getMaxSize());
116+
assertThat(opts.getMaxSize()).isEqualTo(expected);
117117
}
118118

119119
@Test
120120
void testGetMaxSizeDefault() {
121121
String expected = "0";
122122
RecordingOptions opts = new RecordingOptions.Builder().build();
123-
assertEquals(expected, opts.getMaxSize());
123+
assertThat(opts.getMaxSize()).isEqualTo(expected);
124124
}
125125

126126
@Keep
@@ -135,30 +135,30 @@ private static Stream<Arguments> testGetMaxSizeNegative() {
135135
@ParameterizedTest
136136
@MethodSource
137137
void testGetMaxSizeNegative(String badValue) {
138-
assertThrows(
139-
IllegalArgumentException.class,
140-
() -> new RecordingOptions.Builder().maxSize(badValue).build());
138+
assertThatThrownBy(
139+
() -> new RecordingOptions.Builder().maxSize(badValue).build())
140+
.isInstanceOf(IllegalArgumentException.class);
141141
}
142142

143143
@Test
144144
void testGetDumpOnExit() {
145145
String expected = "true";
146146
RecordingOptions opts = new RecordingOptions.Builder().dumpOnExit(expected).build();
147-
assertEquals(expected, opts.getDumpOnExit());
147+
assertThat(opts.getDumpOnExit()).isEqualTo(expected);
148148
}
149149

150150
@Test
151151
void testGetDumpOnExitDefault() {
152152
String expected = "false";
153153
RecordingOptions opts = new RecordingOptions.Builder().build();
154-
assertEquals(expected, opts.getDumpOnExit());
154+
assertThat(opts.getDumpOnExit()).isEqualTo(expected);
155155
}
156156

157157
@Test
158158
void testGetDumpOnExitBadValue() {
159159
String expected = "false";
160160
RecordingOptions opts = new RecordingOptions.Builder().dumpOnExit("BAD_VALUE").build();
161-
assertEquals(expected, opts.getDumpOnExit());
161+
assertThat(opts.getDumpOnExit()).isEqualTo(expected);
162162
}
163163

164164
@Keep
@@ -175,35 +175,35 @@ private static Stream<Arguments> testGetDestination() {
175175
@MethodSource
176176
void testGetDestination(String testValue, String expected) {
177177
RecordingOptions opts = new RecordingOptions.Builder().destination(testValue).build();
178-
assertEquals(expected, opts.getDestination());
178+
assertThat(opts.getDestination()).isEqualTo(expected);
179179
}
180180

181181
@Test
182182
void testGetDestinationDefault() {
183183
String expected = "";
184184
RecordingOptions opts = new RecordingOptions.Builder().build();
185-
assertEquals(expected, opts.getDestination());
185+
assertThat(opts.getDestination()).isEqualTo(expected);
186186
}
187187

188188
@Test
189189
void testGetDisk() {
190190
String expected = "true";
191191
RecordingOptions opts = new RecordingOptions.Builder().disk(expected).build();
192-
assertEquals(expected, opts.getDisk());
192+
assertThat(opts.getDisk()).isEqualTo(expected);
193193
}
194194

195195
@Test
196196
void testGetDiskDefault() {
197197
String expected = "false";
198198
RecordingOptions opts = new RecordingOptions.Builder().build();
199-
assertEquals(expected, opts.getDisk());
199+
assertThat(opts.getDisk()).isEqualTo(expected);
200200
}
201201

202202
@Test
203203
void testGetDiskBadValue() {
204204
String expected = "false";
205205
RecordingOptions opts = new RecordingOptions.Builder().disk("BAD_VALUE").build();
206-
assertEquals(expected, opts.getDisk());
206+
assertThat(opts.getDisk()).isEqualTo(expected);
207207
}
208208

209209
@Keep
@@ -227,14 +227,14 @@ private static Stream<Arguments> testGetDuration() {
227227
@MethodSource
228228
void testGetDuration(String testValue, String expected) {
229229
RecordingOptions opts = new RecordingOptions.Builder().duration(testValue).build();
230-
assertEquals(expected, opts.getDuration());
230+
assertThat(opts.getDuration()).isEqualTo(expected);
231231
}
232232

233233
@Test
234234
void testGetDurationDefault() {
235235
String expected = "0";
236236
RecordingOptions opts = new RecordingOptions.Builder().build();
237-
assertEquals(expected, opts.getDuration());
237+
assertThat(opts.getDuration()).isEqualTo(expected);
238238
}
239239

240240
@Keep
@@ -254,9 +254,9 @@ private static Stream<Arguments> testGetDurationNegative() {
254254
@ParameterizedTest
255255
@MethodSource
256256
void testGetDurationNegative(String badValue) {
257-
assertThrows(
258-
IllegalArgumentException.class,
259-
() -> new RecordingOptions.Builder().duration(badValue).build());
257+
assertThatThrownBy(
258+
() -> new RecordingOptions.Builder().duration(badValue).build())
259+
.isInstanceOf(IllegalArgumentException.class);
260260
}
261261

262262
@Test
@@ -279,7 +279,7 @@ void testGetRecordingOptions() {
279279
.disk("true")
280280
.duration("120 s")
281281
.build();
282-
assertEquals(expected, opts.getRecordingOptions());
282+
assertThat(opts.getRecordingOptions()).isEqualTo(expected);
283283
}
284284

285285
@Test
@@ -289,6 +289,6 @@ void testGetRecordingOptionsDefaults() {
289289
// to insure consistent behaviour.
290290
expected.put("disk", "false");
291291
RecordingOptions opts = new RecordingOptions.Builder().build();
292-
assertEquals(expected, opts.getRecordingOptions());
292+
assertThat(opts.getRecordingOptions()).isEqualTo(expected);
293293
}
294294
}

0 commit comments

Comments
 (0)