|
20 | 20 |
|
21 | 21 | import static org.hamcrest.Matchers.*; |
22 | 22 | import static org.hamcrest.core.IsInstanceOf.instanceOf; |
| 23 | +import static org.junit.Assert.assertThrows; |
23 | 24 | import static org.kohsuke.github.GHVerification.Reason.*; |
24 | 25 |
|
25 | 26 | /** |
@@ -417,6 +418,66 @@ public void listCommitCommentsNoComments() throws IOException { |
417 | 418 | assertThat("Commit has no comments", commitComments.isEmpty()); |
418 | 419 | } |
419 | 420 |
|
| 421 | + @Test |
| 422 | + public void searchAllPublicAndForkedRepos() throws IOException { |
| 423 | + PagedSearchIterable<GHRepository> list = gitHub.searchRepositories() |
| 424 | + .user("t0m4uk1991") |
| 425 | + .visibility(GHRepository.Visibility.PUBLIC) |
| 426 | + .fork(GHRepositorySearchBuilder.Fork.PARENT_AND_FORKS) |
| 427 | + .list(); |
| 428 | + List<GHRepository> u = list.toList(); |
| 429 | + assertThat(u.size(), is(14)); |
| 430 | + assertThat(u.stream().filter(item -> item.getName().equals("github-api")).count(), is(1L)); |
| 431 | + assertThat(u.stream().filter(item -> item.getName().equals("Complete-Python-3-Bootcamp")).count(), is(1L)); |
| 432 | + } |
| 433 | + |
| 434 | + @Test |
| 435 | + public void searchForPublicForkedOnlyRepos() throws IOException { |
| 436 | + PagedSearchIterable<GHRepository> list = gitHub.searchRepositories() |
| 437 | + .user("t0m4uk1991") |
| 438 | + .visibility(GHRepository.Visibility.PUBLIC) |
| 439 | + .fork(GHRepositorySearchBuilder.Fork.FORKS_ONLY) |
| 440 | + .list(); |
| 441 | + List<GHRepository> u = list.toList(); |
| 442 | + assertThat(u.size(), is(2)); |
| 443 | + assertThat(u.get(0).getName(), is("github-api")); |
| 444 | + assertThat(u.get(1).getName(), is("Complete-Python-3-Bootcamp")); |
| 445 | + } |
| 446 | + |
| 447 | + @Test |
| 448 | + public void ghRepositorySearchBuilderIgnoresUnknownVisibility() { |
| 449 | + GHRepositorySearchBuilder ghRepositorySearchBuilder; |
| 450 | + |
| 451 | + GHException exception = assertThrows(GHException.class, |
| 452 | + () -> new GHRepositorySearchBuilder(gitHub).visibility(Visibility.UNKNOWN)); |
| 453 | + assertThat(exception.getMessage(), |
| 454 | + startsWith("UNKNOWN is a placeholder for unexpected values encountered when reading data.")); |
| 455 | + |
| 456 | + ghRepositorySearchBuilder = new GHRepositorySearchBuilder(gitHub).visibility(Visibility.PUBLIC); |
| 457 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("is:")).count(), is(1L)); |
| 458 | + |
| 459 | + ghRepositorySearchBuilder = new GHRepositorySearchBuilder(gitHub).visibility(Visibility.PRIVATE); |
| 460 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("is:")).count(), is(1L)); |
| 461 | + |
| 462 | + ghRepositorySearchBuilder = new GHRepositorySearchBuilder(gitHub).visibility(Visibility.INTERNAL); |
| 463 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("is:")).count(), is(1L)); |
| 464 | + } |
| 465 | + |
| 466 | + @Test |
| 467 | + public void ghRepositorySearchBuilderForkDefaultResetForksSearchTerms() { |
| 468 | + GHRepositorySearchBuilder ghRepositorySearchBuilder = new GHRepositorySearchBuilder(gitHub); |
| 469 | + ghRepositorySearchBuilder = ghRepositorySearchBuilder.fork(GHRepositorySearchBuilder.Fork.PARENT_AND_FORKS); |
| 470 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("fork:true")).count(), is(1L)); |
| 471 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("fork:")).count(), is(1L)); |
| 472 | + |
| 473 | + ghRepositorySearchBuilder = ghRepositorySearchBuilder.fork(GHRepositorySearchBuilder.Fork.FORKS_ONLY); |
| 474 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("fork:only")).count(), is(1L)); |
| 475 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("fork:")).count(), is(2L)); |
| 476 | + |
| 477 | + ghRepositorySearchBuilder = ghRepositorySearchBuilder.fork(GHRepositorySearchBuilder.Fork.PARENT_ONLY); |
| 478 | + assertThat(ghRepositorySearchBuilder.terms.stream().filter(item -> item.contains("fork:")).count(), is(0L)); |
| 479 | + } |
| 480 | + |
420 | 481 | @Test |
421 | 482 | public void listCommitCommentsSomeComments() throws IOException { |
422 | 483 | List<GHCommitComment> commitComments = getRepository() |
|
0 commit comments