Replace ExpectedException with assertThrows
Change-Id: I4a4bc66215621291c9468c3520c9c08e6a40db44
diff --git a/src/test/java/com/googlesource/gerrit/plugins/oauth/OAuth2AccessTokenJsonExtractorTest.java b/src/test/java/com/googlesource/gerrit/plugins/oauth/OAuth2AccessTokenJsonExtractorTest.java
index 09df7ee..ccc1db3 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/oauth/OAuth2AccessTokenJsonExtractorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/oauth/OAuth2AccessTokenJsonExtractorTest.java
@@ -14,12 +14,12 @@
package com.googlesource.gerrit.plugins.oauth;
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.scribe.model.OAuthConstants.ACCESS_TOKEN;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.scribe.exceptions.OAuthException;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.model.Token;
@@ -33,8 +33,6 @@
"{ \"" + ACCESS_TOKEN + "\" : \"" + TOKEN + "\"}'";
private static final String MESSAGE = "Cannot extract a token from a null or empty String";
- @Rule public ExpectedException exception = ExpectedException.none();
-
@Test
public void parseResponse() throws Exception {
Token token = extractor.extract(RESPONSE);
@@ -49,22 +47,24 @@
@Test
public void failParseNonJsonResponse() throws Exception {
- exception.expect(OAuthException.class);
- exception.expectMessage("Cannot extract an access token. Response was: " + RESPONSE_NON_JSON);
- extractor.extract(RESPONSE_NON_JSON);
+ OAuthException thrown =
+ assertThrows(OAuthException.class, () -> extractor.extract(RESPONSE_NON_JSON));
+ assertThat(thrown)
+ .hasMessageThat()
+ .contains("Cannot extract an access token. Response was: " + RESPONSE_NON_JSON);
}
@Test
public void shouldThrowExceptionIfForNullParameter() throws Exception {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage(MESSAGE);
- extractor.extract(null);
+ IllegalArgumentException thrown =
+ assertThrows(IllegalArgumentException.class, () -> extractor.extract(null));
+ assertThat(thrown).hasMessageThat().contains(MESSAGE);
}
@Test
public void shouldThrowExceptionIfForEmptyString() throws Exception {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage(MESSAGE);
- extractor.extract("");
+ IllegalArgumentException thrown =
+ assertThrows(IllegalArgumentException.class, () -> extractor.extract(""));
+ assertThat(thrown).hasMessageThat().contains(MESSAGE);
}
}