diff --git a/src/main/java/org/takes/facets/auth/social/PsGithub.java b/src/main/java/org/takes/facets/auth/social/PsGithub.java index de03bef34..40b571beb 100644 --- a/src/main/java/org/takes/facets/auth/social/PsGithub.java +++ b/src/main/java/org/takes/facets/auth/social/PsGithub.java @@ -31,7 +31,6 @@ import java.net.HttpURLConnection; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import javax.json.JsonObject; import lombok.EqualsAndHashCode; @@ -169,7 +168,7 @@ private String token(final String home, final String code) final String uri = new Href(this.github) .path(PsGithub.LOGIN).path("oauth").path(PsGithub.ACCESS_TOKEN) .toString(); - final List tokens = new JdkRequest(uri) + return new JdkRequest(uri) .method("POST") .header("Accept", "application/xml") .body() @@ -181,13 +180,10 @@ private String token(final String home, final String code) .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) - .xml().xpath("/OAuth/access_token/text()"); - if (tokens.isEmpty()) { - throw new HttpException( - HttpURLConnection.HTTP_BAD_REQUEST, "No access token" - ); - } - return tokens.get(0); + .assertXPath("/OAuth/access_token") + .xml() + .xpath("/OAuth/access_token/text()") + .get(0); } /** diff --git a/src/test/java/org/takes/facets/auth/social/PsGithubTest.java b/src/test/java/org/takes/facets/auth/social/PsGithubTest.java index 3c7b62139..72d5ece98 100644 --- a/src/test/java/org/takes/facets/auth/social/PsGithubTest.java +++ b/src/test/java/org/takes/facets/auth/social/PsGithubTest.java @@ -31,7 +31,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.takes.HttpException; import org.takes.Request; import org.takes.Response; import org.takes.Take; @@ -96,8 +95,7 @@ public final class PsGithubTest { */ @Test public void failsOnNoAccessToken() throws IOException { - this.thrown.expect(HttpException.class); - this.thrown.expectMessage("No access token"); + this.thrown.expect(AssertionError.class); this.performLogin(PsGithubTest.directiveWithoutAccessToken()); }