Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide better names for the test plan specification
- Reduced dependencies to the Builder DSL Issue: #116
- Loading branch information
Showing
13 changed files
with
241 additions
and
250 deletions.
There are no files selected for viewing
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
47 changes: 0 additions & 47 deletions
47
junit-engine-api/src/main/java/org/junit/gen5/engine/discoveryrequest/AllClassFilters.java
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
...e-api/src/main/java/org/junit/gen5/engine/discoveryrequest/PredicateBasedClassFilter.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
51 changes: 0 additions & 51 deletions
51
junit-engine-api/src/main/java/org/junit/gen5/engine/discoveryrequest/dsl/ClassFilters.java
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
junit-engine-api/src/main/java/org/junit/gen5/engine/discoveryrequest/dsl/CommonBuilder.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,83 @@ | ||
/* | ||
* 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.discoveryrequest.dsl; | ||
|
||
import static java.lang.String.format; | ||
import static java.util.Arrays.asList; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
import java.util.Collection; | ||
import java.util.StringJoiner; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.gen5.engine.DiscoveryFilter; | ||
import org.junit.gen5.engine.DiscoveryRequest; | ||
import org.junit.gen5.engine.FilterResult; | ||
|
||
/** | ||
* A collection of common builders for {@link DiscoveryRequest} elements. | ||
* | ||
* @since 5.0 | ||
*/ | ||
public class CommonBuilder { | ||
public static <T> DiscoveryFilter<T> alwaysIncluded() { | ||
return (any) -> FilterResult.included("Always included"); | ||
} | ||
|
||
public static <T> DiscoveryFilter<T> alwaysExcluded() { | ||
return (any) -> FilterResult.excluded("Always excluded"); | ||
} | ||
|
||
public static <T> DiscoveryFilter<T> allOf(DiscoveryFilter<T>... filters) { | ||
if (filters == null) { | ||
return alwaysIncluded(); | ||
} | ||
else { | ||
return allOf(asList(filters)); | ||
} | ||
} | ||
|
||
public static <T> DiscoveryFilter<T> allOf(Collection<DiscoveryFilter<T>> filters) { | ||
if (filters == null || filters.isEmpty()) { | ||
return alwaysIncluded(); | ||
} | ||
else if (filters.size() == 1) { | ||
return filters.iterator().next(); | ||
} | ||
else { | ||
return new AndAllDiscoveryFilter(filters); | ||
} | ||
} | ||
|
||
private static class AndAllDiscoveryFilter<T> implements DiscoveryFilter<T> { | ||
private final Collection<DiscoveryFilter<T>> filters; | ||
|
||
public AndAllDiscoveryFilter(Collection<DiscoveryFilter<T>> filters) { | ||
this.filters = filters; | ||
} | ||
|
||
@Override | ||
public FilterResult filter(T element) { | ||
// @formatter:off | ||
return this.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 this.filters.stream().map(Object::toString).map(s -> format("(%s)", s)).collect(joining(" and ")); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
junit-tests/src/test/java/org/junit/gen5/engine/ClassFilterBuilderTests.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,39 @@ | ||
/* | ||
* 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 org.junit.gen5.api.Assertions.*; | ||
|
||
import java.util.Collection; | ||
|
||
import org.junit.gen5.api.Test; | ||
import org.junit.gen5.engine.discoveryrequest.dsl.ClassFilterBuilder; | ||
|
||
class ClassFilterBuilderTests { | ||
@Test | ||
void classNameMatches() { | ||
String regex = "^java\\.lang\\..*"; | ||
|
||
ClassFilter filter = ClassFilterBuilder.pattern(regex); | ||
|
||
assertEquals("Filter class names with regular expression: " + regex, filter.toString()); | ||
assertTrue(filter.filter(String.class).included()); | ||
assertFalse(filter.filter(Collection.class).included()); | ||
} | ||
|
||
@Test | ||
void anyClass() { | ||
ClassFilter filter = ClassFilterBuilder.anyClass(); | ||
|
||
assertTrue(filter.filter(String.class).included()); | ||
assertTrue(filter.filter(this.getClass()).included()); | ||
} | ||
} |
83 changes: 0 additions & 83 deletions
83
junit-tests/src/test/java/org/junit/gen5/engine/ClassFiltersTests.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.