Skip to content

Commit d54cef4

Browse files
authored
Merge pull request #1032 from AzureAD/avdunn/assertion-standardization
Improve assertion usage patterns
2 parents 91cc4a2 + 7746246 commit d54cef4

18 files changed

Lines changed: 163 additions & 162 deletions

msal4j-sdk/pom.xml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<dependency>
6161
<groupId>org.slf4j</groupId>
6262
<artifactId>slf4j-simple</artifactId>
63-
<version>1.6.2</version>
63+
<version>1.7.36</version>
6464
<scope>test</scope>
6565
</dependency>
6666
<dependency>
@@ -96,7 +96,7 @@
9696
<dependency>
9797
<groupId>net.bytebuddy</groupId>
9898
<artifactId>byte-buddy</artifactId>
99-
<version>1.14.5</version>
99+
<version>1.17.5</version>
100100
<scope>test</scope>
101101
</dependency>
102102
<dependency>
@@ -114,7 +114,19 @@
114114
<dependency>
115115
<groupId>org.seleniumhq.selenium</groupId>
116116
<artifactId>selenium-java</artifactId>
117-
<version>3.14.0</version>
117+
<version>4.13.0</version>
118+
<scope>test</scope>
119+
</dependency>
120+
<dependency>
121+
<groupId>com.squareup.okhttp3</groupId>
122+
<artifactId>okhttp</artifactId>
123+
<version>3.14.9</version>
124+
<scope>test</scope>
125+
</dependency>
126+
<dependency>
127+
<groupId>org.apache.httpcomponents</groupId>
128+
<artifactId>httpclient</artifactId>
129+
<version>4.5.14</version>
118130
<scope>test</scope>
119131
</dependency>
120132
<dependency>
@@ -126,7 +138,7 @@
126138
<dependency>
127139
<groupId>commons-io</groupId>
128140
<artifactId>commons-io</artifactId>
129-
<version>2.14.0</version>
141+
<version>2.22.0</version>
130142
<scope>test</scope>
131143
</dependency>
132144
<dependency>
@@ -169,7 +181,7 @@
169181
<plugin>
170182
<groupId>org.revapi</groupId>
171183
<artifactId>revapi-maven-plugin</artifactId>
172-
<version>0.15.0</version>
184+
<version>0.15.1</version>
173185
<configuration>
174186
<analysisConfiguration>
175187
<revapi.java>
@@ -183,7 +195,7 @@
183195
<dependency>
184196
<groupId>org.revapi</groupId>
185197
<artifactId>revapi-java</artifactId>
186-
<version>0.28.1</version>
198+
<version>0.28.4</version>
187199
</dependency>
188200
</dependencies>
189201
<executions>
@@ -199,7 +211,7 @@
199211
<plugin>
200212
<groupId>org.apache.maven.plugins</groupId>
201213
<artifactId>maven-jar-plugin</artifactId>
202-
<version>2.5</version>
214+
<version>3.5.0</version>
203215
<configuration>
204216
<archive>
205217
<manifest>
@@ -213,7 +225,7 @@
213225
<plugin>
214226
<groupId>org.apache.maven.plugins</groupId>
215227
<artifactId>maven-surefire-plugin</artifactId>
216-
<version>3.5.2</version>
228+
<version>3.5.6</version>
217229
<configuration>
218230
<argLine>@{argLine} -noverify</argLine>
219231
<skipTests>${skip.unit.tests}</skipTests>
@@ -222,7 +234,7 @@
222234
<plugin>
223235
<groupId>org.apache.maven.plugins</groupId>
224236
<artifactId>maven-javadoc-plugin</artifactId>
225-
<version>3.1.0</version>
237+
<version>3.12.0</version>
226238
<configuration>
227239
<sourcepath>src/main/java</sourcepath>
228240
</configuration>
@@ -238,7 +250,7 @@
238250
<plugin>
239251
<groupId>org.apache.maven.plugins</groupId>
240252
<artifactId>maven-source-plugin</artifactId>
241-
<version>2.2.1</version>
253+
<version>3.4.0</version>
242254
<executions>
243255
<execution>
244256
<id>attach-sources</id>
@@ -251,12 +263,12 @@
251263
<plugin>
252264
<groupId>com.github.spotbugs</groupId>
253265
<artifactId>spotbugs-maven-plugin</artifactId>
254-
<version>3.1.11</version>
266+
<version>4.2.3</version>
255267
</plugin>
256268
<plugin>
257269
<groupId>org.apache.maven.plugins</groupId>
258270
<artifactId>maven-compiler-plugin</artifactId>
259-
<version>3.7.0</version>
271+
<version>3.15.0</version>
260272
<configuration>
261273
<source>8</source>
262274
<target>8</target>
@@ -265,7 +277,7 @@
265277
<plugin>
266278
<groupId>org.codehaus.mojo</groupId>
267279
<artifactId>build-helper-maven-plugin</artifactId>
268-
<version>1.10</version>
280+
<version>3.6.0</version>
269281
<executions>
270282
<execution>
271283
<id>add-test-source</id>
@@ -284,7 +296,7 @@
284296
<plugin>
285297
<groupId>org.apache.maven.plugins</groupId>
286298
<artifactId>maven-failsafe-plugin</artifactId>
287-
<version>3.5.0</version>
299+
<version>3.5.6</version>
288300
<executions>
289301
<execution>
290302
<goals>
@@ -303,7 +315,7 @@
303315
<plugin>
304316
<groupId>biz.aQute.bnd</groupId>
305317
<artifactId>bnd-maven-plugin</artifactId>
306-
<version>5.2.0</version>
318+
<version>6.4.0</version>
307319
<executions>
308320
<execution>
309321
<goals>
@@ -315,7 +327,7 @@
315327
<plugin>
316328
<groupId>org.jacoco</groupId>
317329
<artifactId>jacoco-maven-plugin</artifactId>
318-
<version>0.8.12</version>
330+
<version>0.8.13</version>
319331
<executions>
320332
<execution>
321333
<goals>
@@ -360,7 +372,7 @@
360372
</plugin>
361373
<plugin>
362374
<artifactId>maven-dependency-plugin</artifactId>
363-
<version>3.1.2</version>
375+
<version>3.11.0</version>
364376
</plugin>
365377
</plugins>
366378
</build>

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/AcquireTokenSilentIT.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ void acquireTokenSilent_ConfidentialClient_acquireTokenSilent() throws Exception
107107
.build())
108108
.get();
109109

110-
assertNotNull(result);
111-
assertNotNull(result.accessToken());
110+
IntegrationTestHelper.assertAccessTokenNotNull(result);
112111

113112
String cachedAt = result.accessToken();
114113

@@ -133,8 +132,7 @@ void acquireTokenSilent_ConfidentialClient_acquireTokenSilentDifferentScopeThrow
133132
.build())
134133
.get();
135134

136-
assertNotNull(result);
137-
assertNotNull(result.accessToken());
135+
IntegrationTestHelper.assertAccessTokenNotNull(result);
138136

139137
//Acquiring token for different scope, expect exception to be thrown
140138
assertThrows(ExecutionException.class, () -> cca.acquireTokenSilently(SilentParameters

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/ClientCredentialsIT.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ void acquireTokenClientCredentials_Certificate_CiamCud() throws Exception {
7575
.build())
7676
.get();
7777

78-
assertNotNull(result);
79-
assertNotNull(result.accessToken());
78+
IntegrationTestHelper.assertAccessTokenNotNull(result);
8079
}
8180

8281
@Test
@@ -117,8 +116,7 @@ void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception {
117116
.build())
118117
.get();
119118

120-
assertNotNull(result1);
121-
assertNotNull(result1.accessToken());
119+
IntegrationTestHelper.assertAccessTokenNotNull(result1);
122120

123121
IAuthenticationResult result2 = cca.acquireToken(ClientCredentialParameters
124122
.builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE))
@@ -133,8 +131,7 @@ void acquireTokenClientCredentials_DefaultCacheLookup() throws Exception {
133131
.build())
134132
.get();
135133

136-
assertNotNull(result3);
137-
assertNotNull(result3.accessToken());
134+
IntegrationTestHelper.assertAccessTokenNotNull(result3);
138135
assertNotEquals(result2.accessToken(), result3.accessToken());
139136
}
140137

@@ -164,8 +161,7 @@ private void assertAcquireTokenCommon(String clientId, IClientCredential credent
164161
.build())
165162
.get();
166163

167-
assertNotNull(result);
168-
assertNotNull(result.accessToken());
164+
IntegrationTestHelper.assertAccessTokenNotNull(result);
169165
}
170166

171167
private void assertAcquireTokenCommon_withParameters(AppConfig app, IClientCredential credential, IClientCredential credentialParam) throws Exception {
@@ -180,8 +176,7 @@ private void assertAcquireTokenCommon_withParameters(AppConfig app, IClientCrede
180176
.build())
181177
.get();
182178

183-
assertNotNull(result);
184-
assertNotNull(result.accessToken());
179+
IntegrationTestHelper.assertAccessTokenNotNull(result);
185180
}
186181

187182
private void assertAcquireTokenCommon_withRegion(AppConfig app, IClientCredential credential, String region, String regionalAuthority) throws Exception {
@@ -202,8 +197,7 @@ private void assertAcquireTokenCommon_withRegion(AppConfig app, IClientCredentia
202197
.build())
203198
.get();
204199

205-
assertNotNull(resultNoRegion);
206-
assertNotNull(resultNoRegion.accessToken());
200+
IntegrationTestHelper.assertAccessTokenNotNull(resultNoRegion);
207201
assertEquals(TestConstants.MICROSOFT_AUTHORITY_BASIC_HOST, resultNoRegion.environment());
208202

209203
//Ensure regional tokens are properly cached and retrievable
@@ -212,17 +206,15 @@ private void assertAcquireTokenCommon_withRegion(AppConfig app, IClientCredentia
212206
.build())
213207
.get();
214208

215-
assertNotNull(resultRegion);
216-
assertNotNull(resultRegion.accessToken());
217-
assertEquals(resultRegion.environment(), regionalAuthority);
209+
IntegrationTestHelper.assertAccessTokenNotNull(resultRegion);
210+
assertEquals(regionalAuthority, resultRegion.environment());
218211

219212
IAuthenticationResult resultRegionCached = ccaRegion.acquireToken(ClientCredentialParameters
220213
.builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE))
221214
.build())
222215
.get();
223216

224-
assertNotNull(resultRegionCached);
225-
assertNotNull(resultRegionCached.accessToken());
217+
IntegrationTestHelper.assertAccessTokenNotNull(resultRegionCached);
226218
assertEquals(resultRegionCached.accessToken(), resultRegion.accessToken());
227219

228220
//Tokens retrieved from regional endpoints should be interchangeable with non-regional, and vice-versa
@@ -233,8 +225,7 @@ private void assertAcquireTokenCommon_withRegion(AppConfig app, IClientCredentia
233225
.build())
234226
.get();
235227

236-
assertNotNull(resultNoRegion);
237-
assertNotNull(resultNoRegion.accessToken());
228+
IntegrationTestHelper.assertAccessTokenNotNull(resultNoRegion);
238229
assertEquals(resultNoRegion.accessToken(), resultRegion.accessToken());
239230
}
240231
}

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/TokenCacheIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void singleAccountInCache_RemoveAccountTest() throws Exception {
2929
build();
3030

3131
// Check that cache is empty
32-
assertEquals(pca.getAccounts().join().size(), 0);
32+
assertEquals(0, pca.getAccounts().join().size());
3333

3434
Map<String, String> extraQueryParameters = new HashMap<>();
3535
extraQueryParameters.put("test", "test");
@@ -43,12 +43,12 @@ void singleAccountInCache_RemoveAccountTest() throws Exception {
4343
.get();
4444

4545
// Check that cache contains one account
46-
assertEquals(pca.getAccounts().join().size(), 1);
46+
assertEquals(1, pca.getAccounts().join().size());
4747

4848
pca.removeAccount(pca.getAccounts().join().iterator().next()).join();
4949

5050
// Check that account has been removed
51-
assertEquals(pca.getAccounts().join().size(), 0);
51+
assertEquals(0, pca.getAccounts().join().size());
5252
}
5353

5454
@Test

msal4j-sdk/src/integrationtest/java/infrastructure/SeleniumExtensions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ private SeleniumExtensions() {
2828

2929
public static WebDriver createDefaultWebDriver() {
3030
ChromeOptions options = new ChromeOptions();
31-
options.addArguments("--headless");
31+
options.addArguments("--headless=new");
3232
options.addArguments("--incognito");
3333

3434
return new ChromeDriver(options);
3535
}
3636

3737
public static WebElement waitForElementToBeVisibleAndEnabled(WebDriver driver, By by, Duration timeout) {
38-
WebDriverWait wait = new WebDriverWait(driver, timeout.getSeconds());
38+
WebDriverWait wait = new WebDriverWait(driver, timeout);
3939
return wait.until(ExpectedConditions.elementToBeClickable(by));
4040
}
4141

msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/ADFSLoginPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ADFSLoginPage {
3232

3333
public ADFSLoginPage(WebDriver driver) {
3434
this.driver = driver;
35-
this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT.getSeconds());
35+
this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT);
3636
}
3737

3838
/**

msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/AzureADLoginPage.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class AzureADLoginPage {
4343

4444
public AzureADLoginPage(WebDriver driver) {
4545
this.driver = driver;
46-
this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT.getSeconds());
46+
this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT);
4747
}
4848

4949
/**
@@ -103,7 +103,7 @@ public AzureADLoginPage clickSubmit() {
103103
*/
104104
public boolean isAuthenticationComplete() {
105105
try {
106-
WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT.getSeconds());
106+
WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT);
107107
shortWait.until(ExpectedConditions.textToBePresentInElementLocated(
108108
AUTH_COMPLETE_BODY, AUTH_COMPLETE_TEXT));
109109
LOG.info("Authentication complete page detected");
@@ -150,7 +150,7 @@ private void handleOptionalPrompts() {
150150
private void handleAreYouTryingToSignInPrompt() {
151151
try {
152152
LOG.info("Checking for 'Are you trying to sign in' prompt");
153-
WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT.getSeconds());
153+
WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT);
154154
shortWait.until(ExpectedConditions.elementToBeClickable(ARE_YOU_TRYING_TO_SIGN_IN_BUTTON))
155155
.click();
156156
LOG.info("Clicked Continue on 'Are you trying to sign in' prompt");
@@ -165,7 +165,7 @@ private void handleAreYouTryingToSignInPrompt() {
165165
private void handleStaySignedInPrompt() {
166166
try {
167167
LOG.info("Checking for 'Stay signed in' prompt");
168-
WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT.getSeconds());
168+
WebDriverWait shortWait = new WebDriverWait(driver, SHORT_TIMEOUT);
169169
shortWait.until(ExpectedConditions.elementToBeClickable(STAY_SIGNED_IN_NO_BUTTON))
170170
.click();
171171
LOG.info("Clicked No on 'Stay signed in' prompt");

msal4j-sdk/src/integrationtest/java/infrastructure/pageobjects/B2CLocalLoginPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class B2CLocalLoginPage {
3333

3434
public B2CLocalLoginPage(WebDriver driver) {
3535
this.driver = driver;
36-
this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT.getSeconds());
36+
this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT);
3737
}
3838

3939
/**

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ void aadInstanceDiscoveryTest_AutoDetectRegion_NoRegionDetected() throws Excepti
138138
}
139139

140140
void assertValidResponse(InstanceDiscoveryMetadataEntry entry) {
141-
assertEquals(entry.preferredNetwork(), "login.microsoftonline.com");
142-
assertEquals(entry.preferredCache(), "login.windows.net");
143-
assertEquals(entry.aliases().size(), 4);
141+
assertEquals("login.microsoftonline.com", entry.preferredNetwork());
142+
assertEquals("login.windows.net", entry.preferredCache());
143+
assertEquals(4, entry.aliases().size());
144144
assertTrue(entry.aliases().contains("login.microsoftonline.com"));
145145
assertTrue(entry.aliases().contains("login.windows.net"));
146146
assertTrue(entry.aliases().contains("login.microsoft.com"));

0 commit comments

Comments
 (0)