Merge branch 'stable-2.16' into stable-3.0 * stable-2.16: Replace ExpectedException with assertThrows Add .apt_generated to .gitignore Change-Id: I2bcced2d44ff6e5546a1580626881a63a2181f82
diff --git a/.gitignore b/.gitignore index b9fe628..c20030a 100644 --- a/.gitignore +++ b/.gitignore
@@ -1,3 +1,4 @@ +/.apt_generated /.classpath /.project /.settings
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); } }