Skip to content

Commit 22575c9

Browse files
committed
Add test for archive method
1 parent 2934922 commit 22575c9

295 files changed

Lines changed: 271 additions & 8 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,10 @@ public void delete() throws IOException {
647647
*
648648
* @throws IOException In case of any networking error or error from the server.
649649
*/
650-
public void doArchive() throws IOException {
650+
public void archive() throws IOException {
651651
edit("archived", "true");
652+
// Generall would not update this record,
653+
// but do so here since this will result in any other update actions failing
652654
archived = true;
653655
}
654656

src/test/java/org/kohsuke/github/AbstractGitHubApiWireMockTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Properties;
2222

2323
import static com.github.tomakehurst.wiremock.client.WireMock.*;
24+
import static org.junit.Assume.assumeFalse;
2425

2526
/**
2627
* @author Liam Newman
@@ -29,8 +30,10 @@ public abstract class AbstractGitHubApiWireMockTest extends Assert {
2930

3031
private final GitHubBuilder githubBuilder = createGitHubBuilder();
3132

32-
public final static String STUBBED_USER_LOGIN = "placeholder-user";
33-
public final static String STUBBED_USER_PASSWORD = "placeholder-password";
33+
final static String GITHUB_API_TEST_ORG = "github-api-test-org";
34+
35+
final static String STUBBED_USER_LOGIN = "placeholder-user";
36+
final static String STUBBED_USER_PASSWORD = "placeholder-password";
3437

3538
/**
3639
* {@link GitHub} instance for use during test.
@@ -109,4 +112,9 @@ public void wireMockSetup() throws Exception {
109112
gitHubBeforeAfter = null;
110113
}
111114
}
115+
116+
protected void snapshotNotAllowed() {
117+
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.", githubApi.isTakeSnapshot());
118+
}
119+
112120
}

src/test/java/org/kohsuke/github/PullRequestTest.java renamed to src/test/java/org/kohsuke/github/GHPullRequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* @author Kohsuke Kawaguchi
1515
*/
16-
public class PullRequestTest extends AbstractGitHubApiWireMockTest {
16+
public class GHPullRequestTest extends AbstractGitHubApiWireMockTest {
1717

1818
@Before
1919
@After
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.kohsuke.github;
2+
3+
import org.junit.Test;
4+
5+
import java.io.IOException;
6+
7+
import static org.hamcrest.Matchers.is;
8+
import static org.junit.Assert.*;
9+
import static org.junit.Assume.assumeFalse;
10+
11+
/**
12+
* @author Liam Newman
13+
*/
14+
public class GHRepositoryTest extends AbstractGitHubApiWireMockTest {
15+
16+
@Test
17+
public void archive() throws Exception {
18+
snapshotNotAllowed();
19+
20+
// Archive is a one-way action in the API.
21+
// We do thi this one
22+
GHRepository repo = getRepository();
23+
24+
assertThat(repo.isArchived(), is(false));
25+
26+
repo.archive();
27+
28+
assertThat(repo.isArchived(), is(true));
29+
assertThat(getRepository().isArchived(), is(true));
30+
}
31+
32+
protected GHRepository getRepository() throws IOException {
33+
return getRepository(gitHub);
34+
}
35+
36+
private GHRepository getRepository(GitHub gitHub) throws IOException {
37+
return gitHub.getOrganization("github-api-test-org").getRepository("github-api");
38+
}
39+
}

src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class WireMockStatusReporterTest extends AbstractGitHubApiWireMockTest {
2020

2121
@Test
2222
public void user_whenProxying_AuthCorrectlyConfigured() throws Exception {
23-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
23+
snapshotNotAllowed();
2424
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable)", githubApi.isUseProxy());
2525

2626
assertThat(
@@ -42,7 +42,7 @@ public void user_whenProxying_AuthCorrectlyConfigured() throws Exception {
4242

4343
@Test
4444
public void user_whenNotProxying_Stubbed() throws Exception {
45-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
45+
snapshotNotAllowed();
4646
assumeFalse("Test only valid when not proxying", githubApi.isUseProxy());
4747

4848
assertThat(gitHub.isAnonymous(), is(false));
@@ -59,7 +59,7 @@ public void user_whenNotProxying_Stubbed() throws Exception {
5959

6060
@Test
6161
public void BasicBehaviors_whenNotProxying() throws Exception {
62-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
62+
snapshotNotAllowed();
6363
assumeFalse("Test only valid when not proxying", githubApi.isUseProxy());
6464

6565
Exception e = null;
@@ -96,7 +96,7 @@ public void BasicBehaviors_whenNotProxying() throws Exception {
9696

9797
@Test
9898
public void BasicBehaviors_whenProxying() throws Exception {
99-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
99+
snapshotNotAllowed();
100100
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable)", githubApi.isUseProxy());
101101
Exception e = null;
102102
GHRepository repo = null;

src/test/resources/org/kohsuke/github/PullRequestTest/wiremock/closePullRequest/__files/orgs_github-api-test-org-24dc8a1a-e0fd-48e7-a48f-8fc0fc9bc01f.json renamed to src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/closePullRequest/__files/orgs_github-api-test-org-24dc8a1a-e0fd-48e7-a48f-8fc0fc9bc01f.json

File renamed without changes.

src/test/resources/org/kohsuke/github/PullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-0f9ebc51-ad67-49b7-b75c-ee2421880f0a.json renamed to src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-0f9ebc51-ad67-49b7-b75c-ee2421880f0a.json

File renamed without changes.

src/test/resources/org/kohsuke/github/PullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-1db0407d-2e07-4407-810e-486b374e8f3e.json renamed to src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-1db0407d-2e07-4407-810e-486b374e8f3e.json

File renamed without changes.

src/test/resources/org/kohsuke/github/PullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-b2a37888-a485-466a-90a1-b56337178b1c.json renamed to src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-b2a37888-a485-466a-90a1-b56337178b1c.json

File renamed without changes.

src/test/resources/org/kohsuke/github/PullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-d6b189f8-494a-48df-bb5b-0756c8396db0.json renamed to src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/closePullRequest/__files/repos_github-api-test-org_github-api-d6b189f8-494a-48df-bb5b-0756c8396db0.json

File renamed without changes.

0 commit comments

Comments
 (0)