Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit c564dc5

Browse files
committed
All tests should use the secondary account
1 parent d64453b commit c564dc5

3 files changed

Lines changed: 38 additions & 32 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.kohsuke;
2+
3+
import org.apache.commons.io.IOUtils;
4+
import org.junit.Assert;
5+
import org.junit.Before;
6+
import org.kohsuke.github.GitHub;
7+
8+
import java.io.FileInputStream;
9+
import java.util.Properties;
10+
11+
/**
12+
* @author Kohsuke Kawaguchi
13+
*/
14+
public abstract class AbstractGitHubApiTestBase extends Assert {
15+
16+
protected GitHub gitHub;
17+
18+
@Before
19+
public void setUp() throws Exception {
20+
Properties props = new Properties();
21+
java.io.File f = new java.io.File(System.getProperty("user.home"), ".github.kohsuke2");
22+
if (f.exists()) {
23+
FileInputStream in = new FileInputStream(f);
24+
try {
25+
props.load(in);
26+
gitHub = GitHub.connect(props.getProperty("login"),props.getProperty("oauth"));
27+
} finally {
28+
IOUtils.closeQuietly(in);
29+
}
30+
} else {
31+
gitHub = GitHub.connect();
32+
}
33+
}
34+
}

src/test/java/org/kohsuke/AppTest.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,7 @@
5959
/**
6060
* Unit test for simple App.
6161
*/
62-
public class AppTest {
63-
64-
private GitHub gitHub;
65-
66-
@Before
67-
public void setUp() throws Exception {
68-
Properties props = new Properties();
69-
java.io.File f = new java.io.File(System.getProperty("user.home"), ".github.kohsuke2");
70-
if (f.exists()) {
71-
FileInputStream in = new FileInputStream(f);
72-
try {
73-
props.load(in);
74-
gitHub = GitHub.connect(props.getProperty("login"),props.getProperty("oauth"));
75-
} finally {
76-
IOUtils.closeQuietly(in);
77-
}
78-
} else {
79-
gitHub = GitHub.connect();
80-
}
81-
}
82-
62+
public class AppTest extends AbstractGitHubApiTestBase {
8363
private String getTestRepositoryName() throws IOException {
8464
return getUser().getLogin() + "/github-api-test";
8565
}

src/test/java/org/kohsuke/LifecycleTest.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package org.kohsuke;
22

3-
import junit.framework.TestCase;
43
import org.apache.commons.io.IOUtils;
54
import org.eclipse.jgit.api.Git;
65
import org.eclipse.jgit.api.errors.GitAPIException;
76
import org.eclipse.jgit.dircache.DirCache;
87
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
8+
import org.junit.Test;
99
import org.kohsuke.github.GHAsset;
1010
import org.kohsuke.github.GHIssue;
1111
import org.kohsuke.github.GHMilestone;
1212
import org.kohsuke.github.GHMyself;
1313
import org.kohsuke.github.GHRelease;
1414
import org.kohsuke.github.GHRepository;
15-
import org.kohsuke.github.GitHub;
1615

1716
import java.io.File;
1817
import java.io.FileInputStream;
@@ -22,15 +21,8 @@
2221
import java.util.List;
2322
import java.util.Properties;
2423

25-
public class LifecycleTest extends TestCase {
26-
private GitHub gitHub;
27-
28-
@Override
29-
public void setUp() throws Exception {
30-
super.setUp();
31-
gitHub = GitHub.connect();
32-
}
33-
24+
public class LifecycleTest extends AbstractGitHubApiTestBase {
25+
@Test
3426
public void testCreateRepository() throws IOException, GitAPIException, InterruptedException {
3527
GHMyself myself = gitHub.getMyself();
3628
GHRepository repository = myself.getRepository("github-api-test");

0 commit comments

Comments
 (0)