55
66package io .opentelemetry .contrib .jfr .connection ;
77
8- import static org .junit .jupiter .api .Assertions .assertEquals ;
9- import static org .junit .jupiter .api .Assertions .assertFalse ;
10- import static org .junit .jupiter .api .Assertions .assertNotEquals ;
11- import static org .junit .jupiter .api .Assertions .assertSame ;
12- import static org .junit .jupiter .api .Assertions .assertTrue ;
13- 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 .fail ;
1410
1511import com .google .errorprone .annotations .Keep ;
1612import java .io .FileInputStream ;
@@ -109,8 +105,8 @@ void tearDown() {
109105 @ Test
110106 void assertNewRecordingInitialValues () {
111107 try (Recording recording = flightRecorderConnection .newRecording (null , null )) {
112- assertEquals ( Recording . State . NEW , recording .getState ());
113- assertEquals (- 1 , recording .getId ());
108+ assertThat ( recording .getState ()). isEqualTo ( Recording . State . NEW );
109+ assertThat ( recording .getId ()). isEqualTo (- 1 );
114110 } catch (IOException | IllegalStateException | JfrConnectionException exception ) {
115111 fail ("assertNewRecordingInitialValues caught exception" , exception );
116112 }
@@ -120,8 +116,8 @@ void assertNewRecordingInitialValues() {
120116 void assertRecordingStartIdAndState () {
121117 try (Recording recording = flightRecorderConnection .newRecording (null , null )) {
122118 long id = recording .start ();
123- assertEquals ( id , recording .getId ());
124- assertEquals ( Recording . State . RECORDING , recording .getState ());
119+ assertThat ( recording .getId ()). isEqualTo ( id );
120+ assertThat ( recording .getState ()). isEqualTo ( Recording . State . RECORDING );
125121 } catch (IOException | IllegalStateException | JfrConnectionException e ) {
126122 fail ("assertRecordingStartIdAndState caught exception" , e );
127123 }
@@ -131,9 +127,9 @@ void assertRecordingStartIdAndState() {
131127 void assertRecordingStopState () {
132128 try (Recording recording = flightRecorderConnection .newRecording (null , null )) {
133129 long id = recording .start ();
134- assertEquals ( id , recording .getId ());
130+ assertThat ( recording .getId ()). isEqualTo ( id );
135131 recording .stop ();
136- assertEquals ( Recording . State . STOPPED , recording .getState ());
132+ assertThat ( recording .getState ()). isEqualTo ( Recording . State . STOPPED );
137133 } catch (IOException | IllegalStateException | JfrConnectionException e ) {
138134 fail ("assertRecordingStopState caught exception" , e );
139135 }
@@ -143,9 +139,9 @@ void assertRecordingStopState() {
143139 void assertRecordingCloseState () {
144140 try (Recording recording = flightRecorderConnection .newRecording (null , null )) {
145141 long id = recording .start ();
146- assertEquals ( id , recording .getId ());
142+ assertThat ( recording .getId ()). isEqualTo ( id );
147143 recording .close ();
148- assertEquals ( Recording . State . CLOSED , recording .getState ());
144+ assertThat ( recording .getState ()). isEqualTo ( Recording . State . CLOSED );
149145 } catch (IOException | IllegalStateException | JfrConnectionException e ) {
150146 fail ("assertRecordingCloseState caught exception" , e );
151147 }
@@ -255,7 +251,7 @@ void assertInvalidStateChangeThrowsIllegalStateException(
255251 try (Recording recording = flightRecorderConnection .newRecording (null , null )) {
256252 reflectivelyInvokeMethods (recording , args );
257253 } catch (InvocationTargetException invocationTargetException ) {
258- assertTrue (invocationTargetException .getCause () instanceof IllegalStateException );
254+ assertThat (invocationTargetException .getCause ()). isInstanceOf ( IllegalStateException . class );
259255 } catch (Exception e ) {
260256 fail ("Bad test code" , e );
261257 }
@@ -322,7 +318,7 @@ void assertRecordingOptionsAreSetInFlightRecorderMXBean(
322318 "getRecordingOptions" ,
323319 new Object [] {id },
324320 new String [] {long .class .getName ()});
325- assertFalse (flightRecorderMXBeanOptions .isEmpty ());
321+ assertThat (flightRecorderMXBeanOptions .isEmpty ()). isFalse ( );
326322 ((Collection <CompositeData >) flightRecorderMXBeanOptions .values ())
327323 .forEach (
328324 compositeData -> {
@@ -344,7 +340,7 @@ void assertRecordingOptionsAreSetInFlightRecorderMXBean(
344340 // and for destination since FlightRecorderMXBean returns null as default
345341 if (!("name" .equals (key ) && "" .equals (actual ))
346342 && !("destination" .equals (key ) && "" .equals (actual ))) {
347- assertEquals ( expected , actual , getter );
343+ assertThat ( actual ). as ( getter ). isEqualTo ( expected );
348344 }
349345 } catch (NoSuchMethodException
350346 | IllegalArgumentException
@@ -393,7 +389,7 @@ void assertFileExistsAfterRecordingDump() {
393389 recording .stop ();
394390 Path dumpFile = Paths .get (System .getProperty ("user.dir" ), "testRecordingDump_dumped.jfr" );
395391 recording .dump (dumpFile .toString ());
396- assertTrue (Files .exists (dumpFile ));
392+ assertThat (Files .exists (dumpFile )). isTrue ( );
397393 } catch (IllegalArgumentException badData ) {
398394 fail ("Issue in test data: " + badData .getMessage ());
399395 } catch (IOException ioe ) {
@@ -428,7 +424,7 @@ void assertFileExistsAfterRecordingStream() {
428424 fail (e .getMessage (), e );
429425 }
430426
431- assertTrue (Files .exists (streamedFile ));
427+ assertThat (Files .exists (streamedFile )). isTrue ( );
432428
433429 } catch (IllegalArgumentException badData ) {
434430 fail ("Issue in test data: " + badData .getMessage ());
@@ -502,9 +498,9 @@ void assertRecordingCloneState() {
502498 try (Recording recording = flightRecorderConnection .newRecording (recordingOptions , null )) {
503499 recording .start ();
504500 Recording clone = recording .clone (true );
505- assertSame (recording .getState (), Recording .State .RECORDING );
506- assertSame (clone .getState (), Recording .State .STOPPED );
507- assertNotEquals (recording .getId (), clone .getId ());
501+ assertThat (recording .getState ()). isSameAs ( Recording .State .RECORDING );
502+ assertThat (clone .getState ()). isSameAs ( Recording .State .STOPPED );
503+ assertThat (recording .getId ()). isNotEqualTo ( clone .getId ());
508504 recording .stop ();
509505 } catch (IOException ioe ) {
510506 // possible that this can be thrown, but should not happen in this context
0 commit comments