added a method to test credential.

This commit is contained in:
Kohsuke Kawaguchi
2010-12-09 15:58:33 -08:00
parent a7c63e5d6c
commit c6558c6527
2 changed files with 17 additions and 2 deletions

View File

@@ -188,6 +188,18 @@ public class GitHub {
.with("public", isPublic ? 1 : 0).to(getApiURL("/repos/create"), JsonRepository.class).wrap(this);
}
/**
* Ensures that the credential is valid.
*/
public boolean isCredentialValid() throws IOException {
try {
retrieveWithAuth(getApiURL("/user/show"),JsonUser.class);
return true;
} catch (IOException e) {
return false;
}
}
WebClient createWebClient() throws IOException {
WebClient wc = new WebClient();
wc.setJavaScriptEnabled(false);

View File

@@ -1,8 +1,6 @@
package org.kohsuke;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHTeam;
@@ -16,6 +14,11 @@ import java.util.Set;
* Unit test for simple App.
*/
public class AppTest extends TestCase {
public void testCredentialValid() throws IOException {
assertTrue(GitHub.connect().isCredentialValid());
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
}
public void testApp() throws IOException {
GitHub gitHub = GitHub.connect();
// testOrganization(gitHub);