1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.jira.rest.client.test.matchers;
18
19 import com.atlassian.jira.rest.client.api.domain.Issue;
20 import com.atlassian.jira.rest.client.api.domain.SearchResult;
21 import com.google.common.collect.Iterables;
22 import org.hamcrest.FeatureMatcher;
23 import org.hamcrest.Matcher;
24 import org.hamcrest.Matchers;
25
26 public class SearchResultMatchers {
27 public static Matcher<? super SearchResult> withStartIndex(final int startIndex) {
28 return new FeatureMatcher<SearchResult, Integer>(Matchers.is(startIndex),
29 "search result with start index that", "startIndex") {
30
31 @Override
32 protected Integer featureValueOf(SearchResult searchResult) {
33 return searchResult.getStartIndex();
34 }
35 };
36 }
37
38 public static Matcher<? super SearchResult> withMaxResults(final int maxResults) {
39 return new FeatureMatcher<SearchResult, Integer>(Matchers.is(maxResults),
40 "search result with max results that", "maxResults") {
41
42 @Override
43 protected Integer featureValueOf(SearchResult searchResult) {
44 return searchResult.getMaxResults();
45 }
46 };
47 }
48
49 public static Matcher<? super SearchResult> withTotal(final int total) {
50 return new FeatureMatcher<SearchResult, Integer>(Matchers.is(total),
51 "search result with total that", "total") {
52
53 @Override
54 protected Integer featureValueOf(SearchResult searchResult) {
55 return searchResult.getTotal();
56 }
57 };
58 }
59
60 public static Matcher<? super SearchResult> withIssueCount(final int issueCount) {
61 return new FeatureMatcher<SearchResult, Integer>(Matchers.is(issueCount),
62 "search result with issue count that", "issue count") {
63
64 @Override
65 protected Integer featureValueOf(SearchResult searchResult) {
66 final Iterable<Issue> issues = searchResult.getIssues();
67 return (issues == null) ? 0 : Iterables.size(issues);
68 }
69 };
70 }
71
72 public static Matcher<? super SearchResult> searchResultWithParamsAndIssueCount(final int startIndex, final int maxResults,
73 final int total, final int issueCount) {
74 return Matchers.allOf(withStartIndex(startIndex), withMaxResults(maxResults), withTotal(total),
75 withIssueCount(issueCount));
76 }
77 }