Repository: SAP/cloud-security-xsuaa-integration
Pull request #816 (2022-02-07 16:44:48)

Fix mvn Test Run with System Stubs
- [spring-xsuaa] fixes mvn test run, by using another System Stub and jupiter
- [spring-security] formats jwtDecoderBuilder


Patch:
diff --git a/spring-security/src/main/java/com/sap/cloud/security/spring/token/authentication/JwtDecoderBuilder.java b/spring-security/src/main/java/com/sap/cloud/security/spring/token/authentication/JwtDecoderBuilder.java
index d3ff61a4..073de9bc 100644
--- a/spring-security/src/main/java/com/sap/cloud/security/spring/token/authentication/JwtDecoderBuilder.java
+++ b/spring-security/src/main/java/com/sap/cloud/security/spring/token/authentication/JwtDecoderBuilder.java
@@ -138,7 +138,6 @@ public class JwtDecoderBuilder {
 		return new IasJwtDecoder(iasValidatorBuilder.build()); // lgtm [java/dereferenced-value-may-be-null] - line 136
 	}
 
-
 	private JwtValidatorBuilder initializeBuilder(OAuth2ServiceConfiguration config) {
 		JwtValidatorBuilder builder = JwtValidatorBuilder.getInstance(config)
 				.withCacheConfiguration(tokenKeyCacheConfiguration)
diff --git a/spring-xsuaa/pom.xml b/spring-xsuaa/pom.xml
index eeb5f09c..9911c974 100644
--- a/spring-xsuaa/pom.xml
+++ b/spring-xsuaa/pom.xml
@@ -156,9 +156,9 @@
 			<scope>test</scope>
 		</dependency>
 		<dependency>
-			<groupId>com.github.stefanbirkner</groupId>
-			<artifactId>system-rules</artifactId>
-			<version>1.19.0</version>
+			<groupId>uk.org.webcompere</groupId>
+			<artifactId>system-stubs-jupiter</artifactId>
+			<version>1.2.0</version>
 			<scope>test</scope>
 		</dependency>
 	</dependencies>


Test patch:
diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationFromEnvTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationFromEnvTest.java
index 94bc8653..05ca6e03 100644
--- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationFromEnvTest.java
+++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationFromEnvTest.java
@@ -1,37 +1,30 @@
 package com.sap.cloud.security.xsuaa;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.contrib.java.lang.system.EnvironmentVariables;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
+import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
 
 import static com.sap.cloud.security.config.cf.CFConstants.CLIENT_ID;
 import static com.sap.cloud.security.config.cf.CFConstants.VCAP_SERVICES;
 import static com.sap.cloud.security.config.cf.CFConstants.XSUAA.*;
 import static org.assertj.core.api.Assertions.assertThat;
 
-public class XsuaaServiceConfigurationFromEnvTest {
+@ExtendWith(SystemStubsExtension.class)
+class XsuaaServiceConfigurationFromEnvTest {
 	XsuaaServiceConfigurationDefault cut;
+	String vcapServiceCredentials = "{\"xsuaa\":[{\"credentials\":{\"apiurl\":\"https://api.mydomain.com\",\"tenantid\":\"tenant-id\",\"subaccountid\":\"subaccount-id\",\"clientid\":\"client-id\"},\"tags\":[\"xsuaa\"]}]}";
 
-	@Rule
-	public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
 
-	@BeforeAll
-	public void setup() {
-		environmentVariables.set(VCAP_SERVICES,
-				"{\"xsuaa\":[{\"credentials\":{\"apiurl\":\"https://api.mydomain.com\",\"tenantid\":\"tenant-id\",\"subaccountid\":\"subaccount-id\",\"clientid\":\"client-id\"},\"tags\":[\"xsuaa\"]}]}");
+	@BeforeEach
+	void setup(EnvironmentVariables environmentVariables) {
 		cut = new XsuaaServiceConfigurationDefault();
-	}
-
-	@AfterAll
-	public void teardown() {
-		environmentVariables.set(VCAP_SERVICES, "");
+		environmentVariables.set(VCAP_SERVICES, vcapServiceCredentials);
 	}
 
 	@Test
-	public void getProperty() {
+	void getProperty() {
 		assertThat(cut.getProperty(API_URL)).isEqualTo("https://api.mydomain.com");
 		assertThat(cut.getProperty(SUBACCOUNT_ID)).isEqualTo("subaccount-id");
 		assertThat(cut.getProperty(TENANT_ID)).isEqualTo("tenant-id");
@@ -40,7 +33,7 @@ public class XsuaaServiceConfigurationFromEnvTest {
 	}
 
 	@Test
-	public void hasProperty() {
+	void hasProperty() {
 		assertThat(cut.hasProperty(API_URL)).isTrue();
 		assertThat(cut.hasProperty(SUBACCOUNT_ID)).isTrue();
 		assertThat(cut.hasProperty("unknownProp")).isFalse();