1 /* 2 * Copyright (C) 2016 The Android Open Source Project 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 android.widget.cts.util; 18 19 import org.hamcrest.Description; 20 import org.hamcrest.Matcher; 21 import org.hamcrest.TypeSafeMatcher; 22 23 import java.util.List; 24 25 public class TestUtilsMatchers { 26 /** 27 * Returns a matcher that matches lists of int values that are in ascending order. 28 */ inAscendingOrder()29 public static Matcher<List<Integer>> inAscendingOrder() { 30 return new TypeSafeMatcher<List<Integer>>() { 31 private String mFailedDescription; 32 33 @Override 34 public void describeTo(Description description) { 35 description.appendText(mFailedDescription); 36 } 37 38 @Override 39 protected boolean matchesSafely(List<Integer> item) { 40 int itemCount = item.size(); 41 42 if (itemCount >= 2) { 43 for (int i = 0; i < itemCount - 1; i++) { 44 int curr = item.get(i); 45 int next = item.get(i + 1); 46 47 if (curr > next) { 48 mFailedDescription = "Values should increase between #" + i + 49 ":" + curr + " and #" + (i + 1) + ":" + next; 50 return false; 51 } 52 } 53 } 54 55 return true; 56 } 57 }; 58 } 59 } 60