Skip to content

Instantly share code, notes, and snippets.

@zawadz88
Created February 15, 2018 16:42
Show Gist options
  • Save zawadz88/810ba3137a18411dd4ad82b77c3b1f6b to your computer and use it in GitHub Desktop.
Save zawadz88/810ba3137a18411dd4ad82b77c3b1f6b to your computer and use it in GitHub Desktop.
Parent filter copied from Android Support test library
package com.stepstone.base.test.runner.filter
import org.junit.runner.Description
import org.junit.runner.manipulation.Filter
/**
* Helper parent class for [Filter] that allows suites to run if any child matches.
*/
abstract class ParentFilter : Filter() {
/**
* {@inheritDoc}
*/
override fun shouldRun(description: Description): Boolean {
if (description.isTest) {
return evaluateTest(description)
}
// this is a suite, explicitly check if any children should run
// no children to run, filter this out
return description.children.any { shouldRun(it) }
}
/**
* Determine if given test description matches filter.
*
* @param description the [Description] describing the test
* @return `true` if matched
*/
protected abstract fun evaluateTest(description: Description): Boolean
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment