Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move combine methods for DiscoveryFilters to interface and document them
- Loading branch information
1 parent
4ceddca
commit 6ba1422
Showing
4 changed files
with
118 additions
and
96 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
junit-engine-api/src/main/java/org/junit/gen5/engine/CombinedDiscoveryFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2015-2016 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
import static java.lang.String.format; | ||
import static java.util.stream.Collectors.joining; | ||
import static org.junit.gen5.engine.FilterResult.included; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Combines a collection of {@link DiscoveryFilter DiscoveryFilters} into a new | ||
* filter that will include elements if and only if all of the filters in the | ||
* specified collection include it. | ||
*/ | ||
class CombinedDiscoveryFilter<T> implements DiscoveryFilter<T> { | ||
|
||
@SuppressWarnings("rawtypes") | ||
private static final DiscoveryFilter ALWAYS_INCLUDED_DISCOVERY_FILTER = obj -> included("Always included"); | ||
|
||
@SuppressWarnings("unchecked") | ||
static <T> DiscoveryFilter<T> alwaysIncluded() { | ||
return ALWAYS_INCLUDED_DISCOVERY_FILTER; | ||
} | ||
|
||
private final Collection<DiscoveryFilter<T>> filters; | ||
|
||
public CombinedDiscoveryFilter(Collection<DiscoveryFilter<T>> filters) { | ||
this.filters = filters; | ||
} | ||
|
||
@Override | ||
public FilterResult filter(T element) { | ||
// @formatter:off | ||
return filters.stream() | ||
.map(filter -> filter.filter(element)) | ||
.filter(FilterResult::excluded) | ||
.findFirst() | ||
.orElse(FilterResult.included("Element was included by all filters.")); | ||
// @formatter:on | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return filters.stream().map(Object::toString).map(value -> format("(%s)", value)).collect(joining(" and ")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 0 additions & 86 deletions
86
junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/CommonFilter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters