1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.testing.local; 6 7 import org.junit.runner.Description; 8 import org.junit.runner.RunWith; 9 import org.junit.runner.manipulation.Filter; 10 11 /** 12 * Filters tests based on the Runner class annotating the test class. 13 */ 14 class RunnerFilter extends Filter { 15 16 private final Class<?> mRunnerClass; 17 18 /** 19 * Creates the filter. 20 */ RunnerFilter(Class<?> runnerClass)21 public RunnerFilter(Class<?> runnerClass) { 22 mRunnerClass = runnerClass; 23 } 24 25 /** 26 * Determines whether or not a test with the provided description should 27 * run based on the Runner class annotating the test class. 28 */ 29 @Override shouldRun(Description description)30 public boolean shouldRun(Description description) { 31 Class<?> c = description.getTestClass(); 32 return c != null && c.isAnnotationPresent(RunWith.class) 33 && c.getAnnotation(RunWith.class).value() == mRunnerClass; 34 } 35 36 /** 37 * Returns a description of this filter. 38 */ 39 @Override describe()40 public String describe() { 41 return "runner-filter: " + mRunnerClass.getName(); 42 } 43 44 } 45 46