本文整理匯總了Java中org.junit.runner.manipulation.Filter類的典型用法代碼示例。如果您正苦於以下問題:Java Filter類的具體用法?Java Filter怎麽用?Java Filter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Filter類屬於org.junit.runner.manipulation包,在下文中一共展示了Filter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: allTestsFiltered
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private boolean allTestsFiltered(Runner runner, List<Filter> filters) {
LinkedList<Description> queue = new LinkedList<Description>();
queue.add(runner.getDescription());
while (!queue.isEmpty()) {
Description description = queue.removeFirst();
queue.addAll(description.getChildren());
boolean run = true;
for (Filter filter : filters) {
if (!filter.shouldRun(description)) {
run = false;
break;
}
}
if (run) {
return false;
}
}
return true;
}
示例2: getTestRequests
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
protected static List<TestRequest> getTestRequests(String folderName, Filter filter) {
List<TestRequest> requests = new ArrayList<>();
getTestClasses(folderName).forEach(testClass -> {
try {
new BlockJUnit4ClassRunner(testClass).getDescription().getChildren()
.forEach(description -> {
if (filter.shouldRun(description)) {
TestRequest request = new TestRequest(description);
request.setTestRunUUID(TestUUID.getTestUUID());
requests.add(request);
}
});
} catch (InitializationError e) {
LOGGER.log(e);
}
});
return requests;
}
示例3: execute
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private static void execute( Class<?> testClass, Notifier notifier, Filter filter )
throws TestSetFailedException
{
final int classModifiers = testClass.getModifiers();
if ( !isAbstract( classModifiers ) && !isInterface( classModifiers ) )
{
Request request = aClass( testClass );
if ( filter != null )
{
request = request.filterWith( filter );
}
Runner runner = request.getRunner();
if ( countTestsInRunner( runner.getDescription() ) != 0 )
{
executeInPlayContext( runner, notifier );
}
}
}
示例4: filter
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
@Override
public void filter(final Filter raw) throws NoTestsRemainException {
super.filter(new Filter() {
@Override
public boolean shouldRun(Description description) {
String testDisplay = StringUtils.substringBefore(description.getDisplayName(), " ");
if (testDisplay != description.getDisplayName()) {
description = Description.createTestDescription(description.getTestClass(), testDisplay);
}
return raw.shouldRun(description);
}
@Override
public String describe() {
return raw.describe();
}
});
}
示例5: assertFilterLeavesTestUnscathed
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private void assertFilterLeavesTestUnscathed(Class<?> testClass) {
Request oneClass = Request.aClass(testClass);
Request filtered = oneClass.filterWith(new Filter() {
@Override
public boolean shouldRun(Description description) {
return true;
}
@Override
public String describe() {
return "Everything";
}
});
int filterCount = filtered.getRunner().testCount();
int coreCount = oneClass.getRunner().testCount();
assertEquals("Counts match up in " + testClass, coreCount, filterCount);
}
示例6: findTestUnits
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
@Override
public List<TestUnit> findTestUnits(final Class<?> clazz) {
final Runner runner = AdaptedJUnitTestUnit.createRunner(clazz);
if (isExcluded(runner) || isNotARunnableTest(runner, clazz.getName()) || !isIncluded(clazz)) {
return Collections.emptyList();
}
if (Filterable.class.isAssignableFrom(runner.getClass())
&& !shouldTreatAsOneUnit(clazz, runner)) {
List<TestUnit> filteredUnits = splitIntoFilteredUnits(runner.getDescription());
return filterUnitsByMethod(filteredUnits);
} else {
return Collections.<TestUnit> singletonList(new AdaptedJUnitTestUnit(
clazz, Option.<Filter> none()));
}
}
示例7: createFilter
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private Option<Filter> createFilter(final Class<?> clazz, final String method) {
final Description d = Description.createTestDescription(clazz, method);
final Filter f = new Filter() {
@Override
public boolean shouldRun(final Description description) {
return d.toString().equals(description.toString());
}
@Override
public String describe() {
return null;
}
};
return Option.some(f);
}
示例8: simulateSelfRandomizingTestRun
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
/**
* Simulates test sharding with the given filters and test descriptions, for a
* set of test descriptions that is in a different order in every test shard.
*
* @param filters a list of filters, one per test shard
* @param descriptions a list of test descriptions
* @return a mapping from each filter to the descriptions of the tests that would be run
* by the shard associated with that filter.
*/
protected static Map<Filter, List<Description>> simulateSelfRandomizingTestRun(
List<Filter> filters, List<Description> descriptions) {
if (descriptions.isEmpty()) {
return new HashMap<>();
}
Deque<Description> mutatingDescriptions = new LinkedList<>(descriptions);
Map<Filter, List<Description>> descriptionsRun = new HashMap<>();
for (Filter filter : filters) {
// rotate the queue so that each filter gets the descriptions in a different order
mutatingDescriptions.addLast(mutatingDescriptions.pollFirst());
for (Description description : descriptions) {
if (filter.shouldRun(description)) {
addDescriptionForFilterToMap(descriptionsRun, filter, description);
}
}
}
return descriptionsRun;
}
示例9: testCreateShardingFilter_defaultStrategy
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
@Test
public void testCreateShardingFilter_defaultStrategy() {
List<Description> descriptions = ShardingFilterTestCase.createGenericTestCaseDescriptions(6);
RoundRobinShardingFilter expectedFilter = new RoundRobinShardingFilter(descriptions, 0, 5);
when(mockShardingEnvironment.getShardIndex()).thenReturn(0);
when(mockShardingEnvironment.getTotalShards()).thenReturn(5);
when(mockShardingEnvironment.getTestShardingStrategy()).thenReturn(null);
ShardingFilters shardingFilters = new ShardingFilters(mockShardingEnvironment,
ShardingFilters.ShardingStrategy.ROUND_ROBIN);
Filter filter = shardingFilters.createShardingFilter(descriptions);
assertThat(filter).isInstanceOf(RoundRobinShardingFilter.class);
RoundRobinShardingFilter shardingFilter = (RoundRobinShardingFilter) filter;
assertThat(shardingFilter.testToShardMap).isEqualTo(expectedFilter.testToShardMap);
assertThat(shardingFilter.shardIndex).isEqualTo(expectedFilter.shardIndex);
assertThat(shardingFilter.totalShards).isEqualTo(expectedFilter.totalShards);
}
示例10: HavaRunner_supports_the_JUnit_filter_API_even_when_the_test_contains_scenarios
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
@Test
public void HavaRunner_supports_the_JUnit_filter_API_even_when_the_test_contains_scenarios() {
HavaRunner havaRunner = new HavaRunner(TestClassWithScenarios.class);
havaRunner.filter(new Filter() {
public boolean shouldRun(Description description) {
throw new UnsupportedOperationException("HavaRunner should not call this method");
}
public String describe() {
return String.format("Method HavaRunner_should_run_only_this_method(%s)", TestClassWithScenarios.class.getName());
}
});
run(havaRunner);
assertEquals(Sets.newHashSet("first scenario", "second scenario"), TestClassWithScenarios.filteredTestCalledForScenarios);
assertEquals(Sets.newHashSet(), TestClassWithScenarios.rejectedTestCalledForScenarios);
}
示例11: initExecutions
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private void initExecutions() {
if (!executionsInitialized) {
try {
Runner descriptionProvider = createRunnerFor(Arrays.asList(target), Collections.<Filter>emptyList());
templateDescription = descriptionProvider.getDescription();
} catch (InitializationError initializationError) {
throw UncheckedException.throwAsUncheckedException(initializationError);
}
createExecutions();
for (Execution execution : executions) {
execution.init(target, templateDescription);
}
executionsInitialized = true;
}
}
示例12: runEnabledTests
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private void runEnabledTests(RunNotifier nested) {
if (enabledTests.isEmpty()) {
return;
}
Runner runner;
try {
runner = createExecutionRunner();
} catch (Throwable t) {
runner = new CannotExecuteRunner(getDisplayName(), target, t);
}
try {
if (!disabledTests.isEmpty()) {
((Filterable) runner).filter(new Filter() {
@Override
public boolean shouldRun(Description description) {
return !disabledTests.contains(description);
}
@Override
public String describe() {
return "disabled tests";
}
});
}
} catch (NoTestsRemainException e) {
return;
}
runner.run(nested);
}
示例13: populateDescriptionRunningMap
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private void populateDescriptionRunningMap(Description description, Map<Description, Boolean> accumulator, Filter filter) {
if(description.isTest()) {
Boolean shouldRunStatus = filter.shouldRun(description);
accumulator.put(description, shouldRunStatus);
return;
}
List<Description> children = description.getChildren();
for(Description d : children) {
populateDescriptionRunningMap(d, accumulator, filter);
}
}
示例14: getFilter
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
public Filter getFilter() {
return new Filter() {
@Override
public boolean shouldRun(Description description) {
return Boolean.TRUE.equals(context.get(description));
}
@Override
public String describe() {
return "RTest Filter";
}
@Override
public void apply(Object child) throws NoTestsRemainException {
if(child instanceof Filterable) {
Filterable filterableChild = (Filterable) child;
filterableChild.filter(this);
}
}
};
//return Filter.matchMethodDescription(desiredDescription);
/*return new Filter() {
@Override
public boolean shouldRun(Description description) {
return (toRun.contains(description));
}
@Override
public String describe() {
return "RTest methods filter";
}
};*/
}
示例15: addFilter
import org.junit.runner.manipulation.Filter; //導入依賴的package包/類
private void addFilter(Filter filter) {
try {
filter(filter);
} catch (NoTestsRemainException ex) {
System.out.println("No tests remain exception: " + ex);
}
}