### Question:
CreateGithubCommentOnResolvedHandler { @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event) { if (addComment) { final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); if (issueInformation.getPlatform() == Platform.GITHUB) { final String solver = Optional.ofNullable(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber()).getSolver()) .orElseThrow(() -> new RuntimeException("No solver found for request " + request.getId())); final CreateGithubComment comment = new CreateGithubComment(); comment.setBody(githubCommentFactory.createResolvedComment(request.getId(), solver)); githubGateway.createCommentOnIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber(), comment); } } } CreateGithubCommentOnResolvedHandler(final GithubGateway githubGateway,
                                                final GithubScraper githubScraper,
                                                final GithubCommentFactory githubCommentFactory,
                                                @Value("${github.add-comments:false}") final Boolean addComment); @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) void createGithubCommentOnRequestClaimable(final RequestClaimableEvent event);  }### Answer:
@Test public void ignoresGithubComment() { handler = new CreateGithubCommentOnResolvedHandler(githubGateway, githubScraper, githubCommentFactory, false); handler.createGithubCommentOnRequestClaimable(mock((RequestClaimableEvent.class))); verifyZeroInteractions(githubGateway); }
@Test public void postsGithubComment() { final RequestClaimableEvent event = new RequestClaimableEvent(RequestDtoMother.freeCodeCampNoUserStories(), LocalDateTime.now()); final String expectedMessage = "ytufg"; final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); final String solver = "gdhfjghiuyutfyd"; final ArgumentCaptor<CreateGithubComment> createGithubCommentArgumentCaptor = ArgumentCaptor.forClass(CreateGithubComment.class); when(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber())).thenReturn(GithubIssue.builder() .solver(solver) .build()); when(githubCommentFactory.createResolvedComment(request.getId(), solver)).thenReturn(expectedMessage); handler.createGithubCommentOnRequestClaimable(event); verify(githubGateway).createCommentOnIssue(eq(issueInformation.getOwner()), eq(issueInformation.getRepo()), eq(issueInformation.getNumber()), createGithubCommentArgumentCaptor.capture()); assertThat(createGithubCommentArgumentCaptor.getValue().getBody()).isEqualTo(expectedMessage); }
@Test public void postsGithubComment_noSolverFound() { final RequestClaimableEvent event = new RequestClaimableEvent(RequestDtoMother.freeCodeCampNoUserStories(), LocalDateTime.now()); final RequestDto request = event.getRequestDto(); final IssueInformationDto issueInformation = request.getIssueInformation(); when(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber())).thenReturn(GithubIssue.builder().build()); try { handler.createGithubCommentOnRequestClaimable(event); fail("RuntimeException expected"); } catch (RuntimeException e) { assertThat(e.getMessage()).isEqualTo("No solver found for request " + request.getId()); } }