/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.test.suitebuilder; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.Smoke; import android.test.suitebuilder.annotation.Suppress; import com.android.internal.util.Predicate; import java.lang.annotation.Annotation; /** * {@hide} Not needed for 1.0 SDK. */ public class TestPredicates { static final Predicate REJECT_INSTRUMENTATION = not(new AssignableFrom(InstrumentationTestCase.class)); static final Predicate SELECT_SMOKE = hasAnnotation(Smoke.class); static final Predicate REJECT_SUPPRESSED = not(hasAnnotation(Suppress.class)); /** * Return a predicate that checks to see if a {@link TestMethod} has an instance of the supplied * annotation class, either on the method or on the containing class. */ public static Predicate hasAnnotation(Class annotationClass) { return new HasAnnotation(annotationClass); } private static class HasAnnotation implements Predicate { private final Class annotationClass; private HasAnnotation(Class annotationClass) { this.annotationClass = annotationClass; } @Override public boolean apply(TestMethod testMethod) { return testMethod.getAnnotation(annotationClass) != null || testMethod.getEnclosingClass().getAnnotation(annotationClass) != null; } } /** * Returns a Predicate that evaluates to true iff the given Predicate * evaluates to false. */ public static Predicate not(Predicate predicate) { return new NotPredicate(predicate); } private static class NotPredicate implements Predicate { private final Predicate predicate; private NotPredicate(Predicate predicate) { this.predicate = predicate; } public boolean apply(T t) { return !predicate.apply(t); } } }