|
1 | 1 | package org.kohsuke.github; |
2 | 2 |
|
| 3 | +import org.assertj.core.util.Objects; |
3 | 4 | import org.awaitility.Awaitility; |
4 | 5 | import org.junit.Before; |
5 | 6 | import org.junit.Test; |
|
17 | 18 | import java.util.List; |
18 | 19 | import java.util.Optional; |
19 | 20 | import java.util.Scanner; |
| 21 | +import java.util.Spliterator; |
| 22 | +import java.util.Spliterators; |
20 | 23 | import java.util.function.Function; |
21 | 24 | import java.util.logging.Level; |
22 | 25 | import java.util.logging.Logger; |
23 | 26 | import java.util.stream.Collectors; |
| 27 | +import java.util.stream.StreamSupport; |
24 | 28 | import java.util.zip.ZipEntry; |
25 | 29 | import java.util.zip.ZipInputStream; |
26 | 30 |
|
@@ -347,7 +351,12 @@ public void testArtifacts() throws IOException { |
347 | 351 | checkArtifactProperties(artifactById, "artifact2"); |
348 | 352 |
|
349 | 353 | // 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()); |
351 | 360 | artifactsFromRepo.sort((a1, a2) -> a1.getName().compareTo(a2.getName())); |
352 | 361 |
|
353 | 362 | // We have at least the two artifacts we just added |
@@ -523,9 +532,13 @@ public void testJobs() throws IOException { |
523 | 532 | latestPreexistingWorkflowRunId) |
524 | 533 | .orElseThrow(() -> new IllegalStateException("We must have a valid workflow run starting from here")); |
525 | 534 |
|
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) |
529 | 542 | .sorted((j1, j2) -> j1.getName().compareTo(j2.getName())) |
530 | 543 | .collect(Collectors.toList()); |
531 | 544 |
|
@@ -762,9 +775,13 @@ public void testStartupFailureConclusion() throws IOException { |
762 | 775 |
|
763 | 776 | GHWorkflow ghWorkflow = repo.getWorkflow("startup-failure-workflow.yml"); |
764 | 777 |
|
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)); |
766 | 782 |
|
767 | | - List<GHWorkflowRun> list = ghWorkflowRunList.stream() |
| 783 | + List<GHWorkflowRun> list = StreamSupport |
| 784 | + .stream(Spliterators.spliteratorUnknownSize(endpointItems, Spliterator.ORDERED), false) |
768 | 785 | .filter(ghWorkflowRun -> ghWorkflowRun.getConclusion().equals(Conclusion.STARTUP_FAILURE)) |
769 | 786 | .collect(Collectors.toList()); |
770 | 787 |
|
|
0 commit comments