### Question:
PullRequestChainParser { public void parsePullRequestChains(PullRequests<? extends PullRequest> pullRequests) { Map<String, PullRequest> pullRequestsMap = Maps.newHashMap(); for (PullRequest pullRequest : pullRequests.getPullRequests()) { pullRequestsMap.put(pullRequest.getSource().getBranch().getName(), pullRequest); } for (PullRequest pullRequest : pullRequestsMap.values()) { List<String> chain = Lists.newArrayList(); PullRequestTarget destination = pullRequest.getDestination(); String branchName = destination.getBranch().getName(); chain.add(branchName); do { PullRequest destinationPullRequest = pullRequestsMap.get(branchName); if (destinationPullRequest != null) { branchName = destinationPullRequest.getDestination().getBranch().getName(); chain.add(branchName); } else { break; } } while (pullRequestsMap.containsKey(branchName)); pullRequest.setBranchChain(chain); } }  void parsePullRequestChains(PullRequests<? extends PullRequest> pullRequests);  }### Answer:
@Test public void parseChain_parseCorrectly() throws Exception { BitbucketPullRequest firstPr = createPr("a", "master"); BitbucketPullRequest secondPr = createPr("b", "a"); BitbucketPullRequests pullRequests = new BitbucketPullRequests(); pullRequests.setPullRequests(asList(secondPr, firstPr)); parser.parsePullRequestChains(pullRequests); assertEquals(1, firstPr.getBranchChain().size()); assertEquals(2, secondPr.getBranchChain().size()); assertTrue(firstPr.getBranchChain().contains("master")); assertTrue(secondPr.getBranchChain().containsAll(asList("a", "master"))); }