File tree Expand file tree Collapse file tree 4 files changed +54
-14
lines changed
main/java/org/kohsuke/github
test/java/org/kohsuke/github Expand file tree Collapse file tree 4 files changed +54
-14
lines changed Original file line number Diff line number Diff line change @@ -173,14 +173,7 @@ public GHCommitSearchBuilder is(String v) {
173173
174174 @ Override
175175 public PagedSearchIterable <GHCommit > list () {
176- return list (item -> {
177- String repoName = getRepoName (item .url );
178- try {
179- GHRepository repo = root ().getRepository (repoName );
180- item .wrapUp (repo );
181- } catch (IOException ioe ) {
182- }
183- });
176+ return list (this ::lateBindGHCommit );
184177 }
185178
186179 /**
@@ -294,4 +287,16 @@ public GHCommitSearchBuilder user(String v) {
294287 protected String getApiUrl () {
295288 return "/search/commits" ;
296289 }
290+
291+ /**
292+ * Exposed internally for testing only.
293+ */
294+ void lateBindGHCommit (GHCommit item ) {
295+ String repoName = getRepoName (item .getUrl ().toString ());
296+ try {
297+ GHRepository repo = root ().getRepository (repoName );
298+ item .wrapUp (repo );
299+ } catch (IOException ioe ) {
300+ }
301+ }
297302}
Original file line number Diff line number Diff line change @@ -60,14 +60,12 @@ public PagedSearchIterable<T> withPageSize(int size) {
6060 }
6161
6262 @ Override
63- PaginatedEndpointItems <? extends GitHubPage <T >, T > items () {
64- // TODO Auto-generated method stub
65- return super .items ();
63+ PaginatedEndpointItems <? extends SearchResult <T >, T > items () {
64+ return new PaginatedEndpointItems <>(pages ());
6665 }
6766
6867 @ Override
69- PaginatedEndpointPages <? extends GitHubPage <T >, T > pages () {
70- // TODO Auto-generated method stub
71- return super .pages ();
68+ PaginatedEndpointPages <? extends SearchResult <T >, T > pages () {
69+ return searchPaginatedEndpoint .pages ();
7270 }
7371}
Original file line number Diff line number Diff line change @@ -432,6 +432,18 @@ public void testCommitSearch() throws IOException {
432432
433433 GHCommit firstCommit = r .iterator ().next ();
434434 assertThat (firstCommit .listFiles ().toList (), is (not (empty ())));
435+
436+ GHCommitSearchBuilder builder = new GHCommitSearchBuilder (GitHub .offline ());
437+ GHException e = Assert .assertThrows (GHException .class , () -> builder .list ().iterator ().next ());
438+ assertThat (e .getMessage (), equalTo ("Failed to retrieve https://api.github.invalid/search/commits?q=" ));
439+
440+ // Verify that this item initalizer does not throw when it otherwise would
441+ builder .lateBindGHCommit (new GHCommit () {
442+ @ Override
443+ public URL getUrl () {
444+ return firstCommit .getUrl ();
445+ }
446+ });
435447 }
436448
437449 /**
Original file line number Diff line number Diff line change @@ -65,6 +65,31 @@ public void testDeprecatedNextPage() throws IOException {
6565 assertThrows (NoSuchElementException .class , () -> items .nextPage ());
6666 }
6767
68+ /**
69+ * Test
70+ *
71+ * @throws IOException
72+ * Signals that an I/O exception has occurred.
73+ */
74+ @ Test
75+ public void testIterators () throws IOException {
76+ var page = new GitHubPageArrayAdapter <>(new Object []{ 1 , 2 , 3 });
77+
78+ var endpoint = PaginatedEndpoint .fromSinglePage (page , Object .class );
79+
80+ var iterator = endpoint .iterator ();
81+ assertThat (iterator .next (), equalTo (1 ));
82+ assertThat (iterator .next (), equalTo (2 ));
83+ assertThat (iterator .next (), equalTo (3 ));
84+ assertThat (iterator .hasNext (), equalTo (false ));
85+
86+ var pagedIterator = new PagedIterator <>(endpoint .items ());
87+ assertThat (pagedIterator .next (), equalTo (1 ));
88+ var nextPage = pagedIterator .nextPage ();
89+ assertThat (nextPage .size (), equalTo (2 ));
90+ assertThat (iterator .hasNext (), equalTo (false ));
91+ }
92+
6893 /**
6994 * Test
7095 *
You can’t perform that action at this time.
0 commit comments