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 /** Filters tests based on the Runner class annotating the test class. */ 12 class RunnerFilter extends Filter { 13 14 private final Class<?> mRunnerClass; 15 16 /** Creates the filter. */ RunnerFilter(Class<?> runnerClass)17 public RunnerFilter(Class<?> runnerClass) { 18 mRunnerClass = runnerClass; 19 } 20 21 /** 22 * Determines whether or not a test with the provided description should 23 * run based on the Runner class annotating the test class. 24 */ 25 @Override shouldRun(Description description)26 public boolean shouldRun(Description description) { 27 Class<?> c = description.getTestClass(); 28 return c != null 29 && c.isAnnotationPresent(RunWith.class) 30 && c.getAnnotation(RunWith.class).value() == mRunnerClass; 31 } 32 33 /** Returns a description of this filter. */ 34 @Override describe()35 public String describe() { 36 return "runner-filter: " + mRunnerClass.getName(); 37 } 38 } 39