PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchResult.java

https://gitlab.com/matticala/apache-camel
Java | 66 lines | 39 code | 11 blank | 16 comment | 6 complexity | c8569a7fc0b321cebd6c1fb4eacdc3f2 MD5 | raw file
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.camel.component.jira.mocks;
  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.Comparator;
  21. import com.atlassian.jira.rest.client.domain.BasicIssue;
  22. import com.atlassian.jira.rest.client.domain.SearchResult;
  23. public class MockSearchResult extends SearchResult {
  24. private ArrayList<? extends BasicIssue> issues;
  25. private BasicIssueComparator basicIssueComparator = new BasicIssueComparator();
  26. public MockSearchResult(int startIndex, int maxResults, int total, java.lang.Iterable<? extends BasicIssue> issues) {
  27. super(startIndex, maxResults, total, issues);
  28. this.issues = (ArrayList<? extends BasicIssue>) issues;
  29. }
  30. @Override
  31. public int getTotal() {
  32. return issues.size();
  33. }
  34. @Override
  35. public Iterable<? extends BasicIssue> getIssues() {
  36. Collections.sort(issues, basicIssueComparator);
  37. ArrayList<? extends BasicIssue> copy = new ArrayList<BasicIssue>(issues);
  38. if (!issues.isEmpty()) {
  39. issues.remove(0);
  40. }
  41. return copy;
  42. }
  43. public class BasicIssueComparator implements Comparator<BasicIssue> {
  44. @Override
  45. public int compare(BasicIssue issue1, BasicIssue issue2) {
  46. if (issue1.getId() < issue2.getId()) {
  47. return 1;
  48. } else if (issue1.getId() == issue2.getId()) {
  49. return 0;
  50. } else {
  51. return -1;
  52. }
  53. }
  54. }
  55. }