1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.testing.local; 6 7import org.junit.runner.Description; 8import org.junit.runner.RunWith; 9import org.junit.runner.manipulation.Filter; 10 11/** 12 * Filters tests based on the Runner class annotating the test class. 13 */ 14class RunnerFilter extends Filter { 15 16 private final Class<?> mRunnerClass; 17 18 /** 19 * Creates the filter. 20 */ 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 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 40 public String describe() { 41 return "runner-filter: " + mRunnerClass.getName(); 42 } 43 44} 45 46