1111import org .junit .jupiter .api .BeforeEach ;
1212import org .junit .jupiter .api .Named ;
1313import org .junit .jupiter .api .extension .RegisterExtension ;
14+ import org .junit .jupiter .api .function .ThrowingSupplier ;
1415import org .junit .jupiter .params .provider .Arguments ;
16+ import org .opentest4j .TestAbortedException ;
1517
1618public abstract class BaseClientTest extends BaseTest {
1719
@@ -68,63 +70,27 @@ protected static Stream<Arguments> serverAndKeyProvider() {
6870 }
6971
7072 protected static TestConfig getMastercardConfig () {
71- try {
72- return TestConfig .getMastercardApiConfig ();
73- } catch (IllegalStateException e ) {
74- throw e ;
75- } catch (Exception e ) {
76- throw new IllegalStateException (e );
77- }
73+ return runOrWrap (TestConfig ::getMastercardApiConfig );
7874 }
7975
8076 private static TestConfig getMastercardConfigWithEcKey () {
81- try {
82- return TestConfig .getMastercardApiConfig (StaticKeys .EC_KEY_PAIR );
83- } catch (IllegalStateException e ) {
84- throw e ;
85- } catch (Exception e ) {
86- throw new IllegalStateException (e );
87- }
77+ return runOrWrap (() -> TestConfig .getMastercardApiConfig (StaticKeys .EC_KEY_PAIR ));
8878 }
8979
9080 private static TestConfig getMastercardConfigWithRsaKey () {
91- try {
92- return TestConfig .getMastercardApiConfig (StaticKeys .RSA_KEY_PAIR );
93- } catch (IllegalStateException e ) {
94- throw e ;
95- } catch (Exception e ) {
96- throw new IllegalStateException (e );
97- }
81+ return runOrWrap (() -> TestConfig .getMastercardApiConfig (StaticKeys .RSA_KEY_PAIR ));
9882 }
9983
10084 protected static TestConfig getFakeConfig () {
101- try {
102- return TestConfig .getFakeApiConfig (authorizationServer , resourceServer );
103- } catch (IllegalStateException e ) {
104- throw e ;
105- } catch (Exception e ) {
106- throw new IllegalStateException (e );
107- }
85+ return runOrWrap (() -> TestConfig .getFakeApiConfig (authorizationServer , resourceServer ));
10886 }
10987
11088 private static TestConfig getFakeConfigWithEcKey () {
111- try {
112- return TestConfig .getFakeApiConfig (authorizationServer , resourceServer , StaticKeys .EC_KEY_PAIR );
113- } catch (IllegalStateException e ) {
114- throw e ;
115- } catch (Exception e ) {
116- throw new IllegalStateException (e );
117- }
89+ return runOrWrap (() -> TestConfig .getFakeApiConfig (authorizationServer , resourceServer , StaticKeys .EC_KEY_PAIR ));
11890 }
11991
12092 private static TestConfig getFakeConfigWithRsaKey () {
121- try {
122- return TestConfig .getFakeApiConfig (authorizationServer , resourceServer , StaticKeys .RSA_KEY_PAIR );
123- } catch (IllegalStateException e ) {
124- throw e ;
125- } catch (Exception e ) {
126- throw new IllegalStateException (e );
127- }
93+ return runOrWrap (() -> TestConfig .getFakeApiConfig (authorizationServer , resourceServer , StaticKeys .RSA_KEY_PAIR ));
12894 }
12995
13096 private static Arguments createConfigArgument (String name , Supplier <TestConfig > configSupplier ) {
@@ -135,4 +101,14 @@ protected static String readResourceId(String resource) throws OAuth2ClientJsonE
135101 Map <String , Object > jsonMap = JsonProvider .getInstance ().parse (resource );
136102 return (String ) jsonMap .get ("id" );
137103 }
104+
105+ private static <T > T runOrWrap (ThrowingSupplier <T > action ) {
106+ try {
107+ return action .get ();
108+ } catch (TestAbortedException | IllegalStateException e ) {
109+ throw e ;
110+ } catch (Throwable e ) {
111+ throw new IllegalStateException (e );
112+ }
113+ }
138114}
0 commit comments