1616
1717package org .springframework .pulsar .function ;
1818
19+ import static com .github .stefanbirkner .systemlambda .SystemLambda .tapSystemErrAndOutNormalized ;
1920import static org .assertj .core .api .Assertions .assertThat ;
2021import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2122import static org .assertj .core .api .Assertions .catchThrowableOfType ;
3536import org .junit .jupiter .api .BeforeEach ;
3637import org .junit .jupiter .api .Nested ;
3738import org .junit .jupiter .api .Test ;
38- import org .junit .jupiter .api .extension .ExtendWith ;
3939import org .junit .jupiter .params .ParameterizedTest ;
4040import org .junit .jupiter .params .provider .ValueSource ;
4141import org .mockito .InOrder ;
4242import org .mockito .Mockito ;
4343
4444import org .springframework .beans .factory .support .StaticListableBeanFactory ;
45- import org .springframework .boot .test .system .CapturedOutput ;
46- import org .springframework .boot .test .system .OutputCaptureExtension ;
4745import org .springframework .pulsar .PulsarException ;
4846import org .springframework .pulsar .core .PulsarAdministration ;
4947import org .springframework .pulsar .function .PulsarFunctionAdministration .PulsarFunctionException ;
@@ -339,7 +337,6 @@ void allProcessedFunctionsFail() throws PulsarAdminException {
339337 }
340338
341339 @ Nested
342- @ ExtendWith (OutputCaptureExtension .class )
343340 class WithPropagationDisabled {
344341
345342 @ BeforeEach
@@ -351,18 +348,18 @@ void disablePropagationOnFunctionAdmin() {
351348 }
352349
353350 @ Test
354- void createAdminClientFails (CapturedOutput output ) throws PulsarClientException {
351+ void createAdminClientFails () throws Exception {
355352 beanFactory .addBean ("function1" , function1 );
356353 when (springPulsarAdmin .createAdminClient ()).thenThrow (new PulsarClientException ("NOPE" ));
357- functionAdmin .createOrUpdateUserDefinedFunctions ();
354+ String output = tapSystemErrAndOutNormalized (() -> functionAdmin .createOrUpdateUserDefinedFunctions () );
358355 assertThat (output ).contains ("Unable to create/update functions - could not create PulsarAdmin: NOPE" );
359356 }
360357
361358 @ Test
362- void processedFunctionFails (CapturedOutput output ) throws PulsarAdminException {
359+ void processedFunctionFails () throws Exception {
363360 beanFactory .addBean ("function1" , function1 );
364361 when (function1 .functionExists (pulsarAdmin )).thenThrow (new PulsarAdminException ("BOOM" ));
365- functionAdmin .createOrUpdateUserDefinedFunctions ();
362+ String output = tapSystemErrAndOutNormalized (() -> functionAdmin .createOrUpdateUserDefinedFunctions () );
366363 assertThat (output ).contains ("Encountered 1 error(s) creating/updating functions:" ,
367364 "PulsarAdminException: BOOM" );
368365 }
@@ -507,7 +504,6 @@ void allProcessedFunctionsFail() {
507504 }
508505
509506 @ Nested
510- @ ExtendWith (OutputCaptureExtension .class )
511507 class WithPropagationDisabled {
512508
513509 @ BeforeEach
@@ -519,19 +515,21 @@ void disableStopPropagationOnFunctionAdmin() {
519515 }
520516
521517 @ Test
522- void createAdminClientFails (CapturedOutput output ) throws PulsarClientException {
518+ void createAdminClientFails () throws Exception {
523519 functionAdmin .getProcessedFunctions ().add (function1 );
524520 when (springPulsarAdmin .createAdminClient ()).thenThrow (new PulsarClientException ("NOPE" ));
525- functionAdmin .enforceStopPolicyOnUserDefinedFunctions ();
521+ String output = tapSystemErrAndOutNormalized (
522+ () -> functionAdmin .enforceStopPolicyOnUserDefinedFunctions ());
526523 assertThat (output )
527524 .contains ("Unable to enforce stop policy on functions - could not create PulsarAdmin: NOPE" );
528525 }
529526
530527 @ Test
531- void processedFunctionFails (CapturedOutput output ) {
528+ void processedFunctionFails () throws Exception {
532529 functionAdmin .getProcessedFunctions ().add (function1 );
533530 doThrow (new PulsarException ("BOOM" )).when (function1 ).stop (pulsarAdmin );
534- functionAdmin .enforceStopPolicyOnUserDefinedFunctions ();
531+ String output = tapSystemErrAndOutNormalized (
532+ () -> functionAdmin .enforceStopPolicyOnUserDefinedFunctions ());
535533 assertThat (output ).contains ("Encountered 1 error(s) enforcing stop policy on functions:" ,
536534 "PulsarException: BOOM" );
537535 }
0 commit comments