View Javadoc

1   /*
2    * Copyright (C) 2012 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * 	http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }