Skip to content

Commit

Permalink
Rename @Packages to @SelectPackages
Browse files Browse the repository at this point in the history
Issue: #312
  • Loading branch information
sbrannen committed Jun 18, 2016
1 parent cd87471 commit 3e3e762
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion documentation/src/docs/asciidoc/running-tests.adoc
Expand Up @@ -324,6 +324,6 @@ The `JUnit4SuiteDemo` will discover and run all tests in the `example` package
and its subpackages.

There are more configuration options for discovering and filtering tests than just
`@Packages`. Please consult the
`@SelectPackages`. Please consult the
{javadoc-root}/org/junit/gen5/junit4/runner/package-summary.html[Javadoc] or the source
code for the `{JUnitPlatform-Runner}` runner for further details.
Expand Up @@ -13,7 +13,7 @@
import org.junit.gen5.junit4.runner.ExcludeTags;
import org.junit.gen5.junit4.runner.FilterClassName;
import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages;
import org.junit.gen5.junit4.runner.SelectPackages;
import org.junit.runner.RunWith;

/**
Expand All @@ -30,7 +30,7 @@
* @since 5.0
*/
@RunWith(JUnitPlatform.class)
@Packages("example")
@SelectPackages("example")
@FilterClassName(".+(Tests|Demo)$")
@ExcludeTags("exclude")
public class DocumentationTestSuite {
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/JUnit4SuiteDemo.java
Expand Up @@ -12,11 +12,11 @@

//tag::user_guide[]
import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages;
import org.junit.gen5.junit4.runner.SelectPackages;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@Packages("example")
@SelectPackages("example")
//end::user_guide[]
@org.junit.gen5.junit4.runner.ExcludeTags("exclude")
//tag::user_guide[]
Expand Down
Expand Up @@ -13,7 +13,7 @@
import org.junit.gen5.junit4.runner.FilterClassName;
import org.junit.gen5.junit4.runner.IncludeEngines;
import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages;
import org.junit.gen5.junit4.runner.SelectPackages;
import org.junit.runner.RunWith;

/**
Expand All @@ -32,7 +32,7 @@
* @since 5.0
*/
@RunWith(JUnitPlatform.class)
@Packages("org.junit.gen5.engine.junit4")
@SelectPackages("org.junit.gen5.engine.junit4")
@FilterClassName(".*Tests?")
@IncludeEngines("junit5")
public class JUnit4TestEngineTestSuite {
Expand Down
Expand Up @@ -64,7 +64,7 @@
* @since 5.0
* @see Classes
* @see FilterClassName
* @see Packages
* @see SelectPackages
* @see IncludeTags
* @see ExcludeTags
* @see IncludeEngines
Expand Down Expand Up @@ -114,7 +114,7 @@ private JUnitPlatformTestTree generateTestTree() {
}

private TestDiscoveryRequest createDiscoveryRequest() {
List<DiscoverySelector> selectors = getSpecElementsFromAnnotations();
List<DiscoverySelector> selectors = getSelectorsFromAnnotations();

// Allows to simply add @RunWith(JUnitPlatform.class) to any test case
if (selectors.isEmpty()) {
Expand All @@ -136,11 +136,11 @@ private void addFiltersFromAnnotations(TestDiscoveryRequest request) {
addExcludedEnginesFilter(request);
}

private List<DiscoverySelector> getSpecElementsFromAnnotations() {
private List<DiscoverySelector> getSelectorsFromAnnotations() {
List<DiscoverySelector> selectors = new ArrayList<>();

selectors.addAll(transform(getTestClasses(), ClassSelector::selectClass));
selectors.addAll(transform(getPackageNames(), PackageSelector::selectPackage));
selectors.addAll(transform(getSelectedClasses(), ClassSelector::selectClass));
selectors.addAll(transform(getSelectedPackageNames(), PackageSelector::selectPackage));

return selectors;
}
Expand Down Expand Up @@ -184,12 +184,12 @@ private void addExcludedEnginesFilter(TestDiscoveryRequest discoveryRequest) {
}
}

private Class<?>[] getTestClasses() {
private Class<?>[] getSelectedClasses() {
return getValueFromAnnotation(Classes.class, Classes::value, EMPTY_CLASS_ARRAY);
}

private String[] getPackageNames() {
return getValueFromAnnotation(Packages.class, Packages::value, EMPTY_STRING_ARRAY);
private String[] getSelectedPackageNames() {
return getValueFromAnnotation(SelectPackages.class, SelectPackages::value, EMPTY_STRING_ARRAY);
}

private String[] getIncludedTags() {
Expand Down
Expand Up @@ -22,20 +22,21 @@
import org.junit.gen5.commons.meta.API;

/**
* {@code @Packages} specifies the names of packages to be run when a class
* annotated with {@code @RunWith(JUnitPlatform.class)} is run.
* {@code @SelectPackages} specifies the names of packages to <em>select</em>
* when running a test suite via {@code @RunWith(JUnitPlatform.class)}.
*
* @since 5.0
* @see org.junit.gen5.engine.discovery.PackageSelector
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(Maintained)
public @interface Packages {
public @interface SelectPackages {

/**
* One or more package names.
* One or more fully qualified package names to select.
*/
String[] value();

Expand Down
Expand Up @@ -13,7 +13,7 @@
import org.junit.gen5.junit4.runner.FilterClassName;
import org.junit.gen5.junit4.runner.IncludeEngines;
import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages;
import org.junit.gen5.junit4.runner.SelectPackages;
import org.junit.runner.RunWith;

/**
Expand All @@ -32,7 +32,7 @@
* @since 5.0
*/
@RunWith(JUnitPlatform.class)
@Packages("org.junit.gen5.engine.junit5")
@SelectPackages("org.junit.gen5.engine.junit5")
@FilterClassName(".*Tests?")
@IncludeEngines("junit5")
public class JUnit5TestEngineTestSuite {
Expand Down
Expand Up @@ -14,7 +14,7 @@
import org.junit.gen5.junit4.runner.FilterClassName;
import org.junit.gen5.junit4.runner.IncludeEngines;
import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages;
import org.junit.gen5.junit4.runner.SelectPackages;
import org.junit.runner.RunWith;

/**
Expand All @@ -34,7 +34,7 @@
*/
@RunWith(JUnitPlatform.class)
//@formatter:off
@Packages({
@SelectPackages({
"org.junit.gen5.api",
"org.junit.gen5.commons",
"org.junit.gen5.console",
Expand Down
Expand Up @@ -106,7 +106,7 @@ class TestCase {
@Test
void requestsPackageSelectorsWhenPackagesAnnotationIsPresent() throws Exception {

@Packages({ "foo", "bar" })
@SelectPackages({ "foo", "bar" })
class TestCase {
}

Expand Down

0 comments on commit 3e3e762

Please sign in to comment.