| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.test.suitebuilder; |
| 18 |
|
| 19 |
import android.test.InstrumentationTestCase; |
| 20 |
import android.test.suitebuilder.annotation.Smoke; |
| 21 |
import android.test.suitebuilder.annotation.Suppress; |
| 22 |
import com.android.internal.util.Predicate; |
| 23 |
import java.lang.annotation.Annotation; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class TestPredicates { |
| 29 |
|
| 30 |
static final Predicate<TestMethod> REJECT_INSTRUMENTATION = |
| 31 |
not(new AssignableFrom(InstrumentationTestCase.class)); |
| 32 |
|
| 33 |
static final Predicate<TestMethod> SELECT_SMOKE = hasAnnotation(Smoke.class); |
| 34 |
|
| 35 |
static final Predicate<TestMethod> REJECT_SUPPRESSED = not(hasAnnotation(Suppress.class)); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public static Predicate<TestMethod> hasAnnotation(Class<? extends Annotation> annotationClass) { |
| 42 |
return new HasAnnotation(annotationClass); |
| 43 |
} |
| 44 |
|
| 45 |
private static class HasAnnotation implements Predicate<TestMethod> { |
| 46 |
|
| 47 |
private final Class<? extends Annotation> annotationClass; |
| 48 |
|
| 49 |
private HasAnnotation(Class<? extends Annotation> annotationClass) { |
| 50 |
this.annotationClass = annotationClass; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public boolean apply(TestMethod testMethod) { |
| 55 |
return testMethod.getAnnotation(annotationClass) != null || |
| 56 |
testMethod.getEnclosingClass().getAnnotation(annotationClass) != null; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public static <T> Predicate<T> not(Predicate<? super T> predicate) { |
| 65 |
return new NotPredicate<T>(predicate); |
| 66 |
} |
| 67 |
|
| 68 |
private static class NotPredicate<T> implements Predicate<T> { |
| 69 |
private final Predicate<? super T> predicate; |
| 70 |
|
| 71 |
private NotPredicate(Predicate<? super T> predicate) { |
| 72 |
this.predicate = predicate; |
| 73 |
} |
| 74 |
|
| 75 |
public boolean apply(T t) { |
| 76 |
return !predicate.apply(t); |
| 77 |
} |
| 78 |
} |
| 79 |
} |