Skip to content

Commit 7917b59

Browse files
committed
More coverage
1 parent 18849b8 commit 7917b59

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class PaginatedEndpointItems<Page extends GitHubPage<Item>, Item> implements Ite
3636
* hasNext() returns false.
3737
*/
3838
public Page getCurrentPage() {
39-
if (currentPage != null) {
39+
if (currentPage == null) {
4040
peek();
4141
}
4242
return currentPage;

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.kohsuke.github;
22

3+
import org.assertj.core.util.Objects;
34
import org.awaitility.Awaitility;
45
import org.junit.Before;
56
import org.junit.Test;
@@ -17,10 +18,13 @@
1718
import java.util.List;
1819
import java.util.Optional;
1920
import java.util.Scanner;
21+
import java.util.Spliterator;
22+
import java.util.Spliterators;
2023
import java.util.function.Function;
2124
import java.util.logging.Level;
2225
import java.util.logging.Logger;
2326
import java.util.stream.Collectors;
27+
import java.util.stream.StreamSupport;
2428
import java.util.zip.ZipEntry;
2529
import java.util.zip.ZipInputStream;
2630

@@ -347,7 +351,12 @@ public void testArtifacts() throws IOException {
347351
checkArtifactProperties(artifactById, "artifact2");
348352

349353
// Test GHRepository#listArtifacts() as we are sure we have artifacts around
350-
List<GHArtifact> artifactsFromRepo = new ArrayList<>(repo.listArtifacts().withPageSize(2).items().nextPage());
354+
var endpointItems = repo.listArtifacts().withPageSize(2).items();
355+
var currentPage = endpointItems.getCurrentPage();
356+
var firstPage = Objects.castIfBelongsToType(currentPage, GHArtifactsPage.class);
357+
assertThat(firstPage.getTotalCount(), equalTo(69));
358+
359+
List<GHArtifact> artifactsFromRepo = new ArrayList<>(endpointItems.nextPage());
351360
artifactsFromRepo.sort((a1, a2) -> a1.getName().compareTo(a2.getName()));
352361

353362
// We have at least the two artifacts we just added
@@ -523,9 +532,13 @@ public void testJobs() throws IOException {
523532
latestPreexistingWorkflowRunId)
524533
.orElseThrow(() -> new IllegalStateException("We must have a valid workflow run starting from here"));
525534

526-
List<GHWorkflowJob> jobs = workflowRun.listJobs()
527-
.toList()
528-
.stream()
535+
var endpointItems = workflowRun.listJobs().items();
536+
var currentPage = endpointItems.getCurrentPage();
537+
var firstPage = Objects.castIfBelongsToType(currentPage, GHWorkflowJobsPage.class);
538+
assertThat(firstPage.getTotalCount(), equalTo(2));
539+
540+
List<GHWorkflowJob> jobs = StreamSupport
541+
.stream(Spliterators.spliteratorUnknownSize(endpointItems, Spliterator.ORDERED), false)
529542
.sorted((j1, j2) -> j1.getName().compareTo(j2.getName()))
530543
.collect(Collectors.toList());
531544

@@ -762,9 +775,13 @@ public void testStartupFailureConclusion() throws IOException {
762775

763776
GHWorkflow ghWorkflow = repo.getWorkflow("startup-failure-workflow.yml");
764777

765-
List<GHWorkflowRun> ghWorkflowRunList = ghWorkflow.listRuns().toList();
778+
var endpointItems = ghWorkflow.listRuns().items();
779+
var currentPage = endpointItems.getCurrentPage();
780+
var firstPage = Objects.castIfBelongsToType(currentPage, GHWorkflowRunsPage.class);
781+
assertThat(firstPage.getTotalCount(), equalTo(4));
766782

767-
List<GHWorkflowRun> list = ghWorkflowRunList.stream()
783+
List<GHWorkflowRun> list = StreamSupport
784+
.stream(Spliterators.spliteratorUnknownSize(endpointItems, Spliterator.ORDERED), false)
768785
.filter(ghWorkflowRun -> ghWorkflowRun.getConclusion().equals(Conclusion.STARTUP_FAILURE))
769786
.collect(Collectors.toList());
770787

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package org.kohsuke.github;
22

3+
import org.assertj.core.util.Objects;
34
import org.junit.After;
45
import org.junit.Before;
56
import org.junit.Test;
67

78
import java.io.IOException;
89
import java.util.Collections;
910
import java.util.List;
11+
import java.util.Spliterator;
12+
import java.util.Spliterators;
13+
import java.util.stream.Collectors;
14+
import java.util.stream.StreamSupport;
1015

1116
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
1217
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
1318
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
1419
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
1520
import static org.hamcrest.Matchers.*;
16-
import static org.hamcrest.Matchers.notNullValue;
1721

1822
// TODO: Auto-generated Javadoc
1923
/**
@@ -184,7 +188,15 @@ public void testListWorkflowRuns() throws IOException {
184188
*/
185189
@Test
186190
public void testListWorkflows() throws IOException {
187-
List<GHWorkflow> workflows = repo.listWorkflows().toList();
191+
192+
var endpointItems = repo.listWorkflows().items();
193+
var currentPage = endpointItems.getCurrentPage();
194+
var firstPage = Objects.castIfBelongsToType(currentPage, GHWorkflowsPage.class);
195+
assertThat(firstPage.getTotalCount(), equalTo(1));
196+
197+
List<GHWorkflow> workflows = StreamSupport
198+
.stream(Spliterators.spliteratorUnknownSize(endpointItems, Spliterator.ORDERED), false)
199+
.collect(Collectors.toList());
188200

189201
GHWorkflow workflow = workflows.get(0);
190202
assertThat(workflow.getId(), equalTo(6817859L));

0 commit comments

Comments
 (0)