GitHubPRRepositoryFactory extends GitHubRepositoryFactory<GitHubPRRepositoryFactory, GitHubPRTrigger> { @Override @Nonnull public Collection<? extends Action> createFor(@Nonnull Job job) { try { if (nonNull(ghPRTriggerFromJob(job))) { return singleton(forProject(job)); } } catch (Exception ex) { LOGGER.error("Bad configured project {} - {}", job.getFullName(), ex.getMessage(), ex); } return Collections.emptyList(); }  @Override @Nonnull Collection<? extends Action> createFor(@Nonnull Job job); @Override Class<Job> type();  }
@Test public void createForNullTrigger() { PowerMockito.mockStatic(JobHelper.class); given(ghPRTriggerFromJob(job)) .willReturn(null); Collection<? extends Action> repoCollection = new GitHubPRRepositoryFactory().createFor(job); Assert.assertTrue(repoCollection instanceof List); Assert.assertTrue(repoCollection.isEmpty()); }
@Test public void shouldNotCreateRepoForTriggerWithExc() throws Exception { PowerMockito.mockStatic(JobHelper.class); given(ghPRTriggerFromJob(job)) .willReturn(trigger); when(parent.getFullName()).thenReturn("mocked job"); when(job.getParent()).thenReturn(parent); when(trigger.getRepoFullName(job)).thenThrow(new RuntimeException()); assertThat(new GitHubPRRepositoryFactory().createFor(job), hasSize(0)); }