### Question:
GithubClaimResolver { public Boolean canClaim(final Principal user, final RequestDto request) { final String owner = request.getIssueInformation().getOwner(); final String repo = request.getIssueInformation().getRepo(); final String number = request.getIssueInformation().getNumber(); final GithubIssue githubIssue = githubScraper.fetchGithubIssue(owner, repo, number); return isIssueClosed(githubIssue) && isClaimalbeByLoggedInUser(user, request, githubIssue.getSolver()); } GithubClaimResolver(final GithubScraper githubScraper,
                               final AzraelClient azraelClient,
                               final KeycloakRepository keycloakRepository); SignedClaim getSignedClaim(final Principal user, final UserClaimRequest userClaimRequest, final RequestDto request); Boolean canClaim(final Principal user, final RequestDto request); ClaimableResultDto claimableResult(final String owner, final String repo, final String number, final RequestStatus requestStatus); Optional<String> getUserPlatformUsername(final Principal user, final Platform platform);  }### Answer:
@Test public void canClaim() { final Principal principal = PrincipalMother.davyvanroy(); final RequestDto requestDto = RequestDtoMother.fundRequestArea51(); final IssueInformationDto issueInformation = requestDto.getIssueInformation(); when(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber())).thenReturn(GithubIssue.builder() .solver("davyvanroy") .status("Closed") .build()); when(keycloakRepository.getUserIdentities(principal.getName())).thenReturn(Stream.of(UserIdentity.builder().provider(Provider.GITHUB).username("davyvanroy").build())); assertThat(claimResolver.canClaim(principal, requestDto)).isTrue(); }
@Test public void canClaim_differentUser() { final Principal principal = PrincipalMother.davyvanroy(); final RequestDto requestDto = RequestDtoMother.fundRequestArea51(); final IssueInformationDto issueInformation = requestDto.getIssueInformation(); when(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber())).thenReturn(GithubIssue.builder() .solver("dfgj") .status("Closed") .build()); when(keycloakRepository.getUserIdentities(principal.getName())).thenReturn(Stream.of(UserIdentity.builder().provider(Provider.GITHUB).username("davyvanroy").build())); assertThat(claimResolver.canClaim(principal, requestDto)).isFalse(); }
@Test public void canClaim_issueNotClosed() { final Principal principal = PrincipalMother.davyvanroy(); final RequestDto requestDto = RequestDtoMother.fundRequestArea51(); final IssueInformationDto issueInformation = requestDto.getIssueInformation(); when(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber())).thenReturn(GithubIssue.builder() .status("Open") .build()); assertThat(claimResolver.canClaim(principal, requestDto)).isFalse(); }