Skip to content

Commit e94f728

Browse files
committed
Allow default package for PackageSource
(cherry picked from commit 63362e9)
1 parent b60fecf commit e94f728

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.13.4.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ repository on GitHub.
2828

2929
* `ClasspathResourceSelector` no longer allows to be constructed with a resource name that
3030
is blank after removing the leading slash.
31+
* `PackageSource.from(String)` now allows to be constructed with an empty string to
32+
indicate the default package.
3133

3234
[[release-notes-5.13.4-junit-platform-deprecations-and-breaking-changes]]
3335
==== Deprecations and Breaking Changes

junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/PackageSource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package org.junit.platform.engine.support.descriptor;
1212

1313
import static org.apiguardian.api.API.Status.STABLE;
14+
import static org.junit.platform.commons.util.StringUtils.isNotBlank;
1415

1516
import java.util.Objects;
1617

@@ -58,7 +59,10 @@ private PackageSource(Package javaPackage) {
5859
}
5960

6061
private PackageSource(String packageName) {
61-
this.packageName = Preconditions.notBlank(packageName, "package name must not be null or blank");
62+
Preconditions.notNull(packageName, "package name must not be null");
63+
Preconditions.condition(packageName.isEmpty() || isNotBlank(packageName),
64+
"package name must not contain only whitespace");
65+
this.packageName = packageName;
6266
}
6367

6468
/**

platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/PackageSourceTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.util.stream.Stream;
1919

2020
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.params.ParameterizedTest;
22+
import org.junit.jupiter.params.provider.ValueSource;
2123
import org.junit.platform.commons.PreconditionViolationException;
2224

2325
/**
@@ -47,9 +49,11 @@ void packageSourceFromNullPackageReference() {
4749
assertThrows(PreconditionViolationException.class, () -> PackageSource.from((Package) null));
4850
}
4951

50-
@Test
51-
void packageSourceFromPackageName() {
52-
var testPackage = getClass().getPackage().getName();
52+
@ParameterizedTest
53+
@ValueSource(classes = PackageSourceTests.class)
54+
@ValueSource(strings = "DefaultPackageTestCase")
55+
void packageSourceFromPackageName(Class<?> testClass) {
56+
var testPackage = testClass.getPackage().getName();
5357
var source = PackageSource.from(testPackage);
5458

5559
assertThat(source.getPackageName()).isEqualTo(testPackage);

platform-tests/src/test/java/org/junit/platform/launcher/core/DiscoveryIssueCollectorTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static Stream<Pair> pairs() {
6969
new Pair(selectClasspathResource("someResource", FilePosition.from(42, 23)),
7070
ClasspathResourceSource.from("someResource",
7171
org.junit.platform.engine.support.descriptor.FilePosition.from(42, 23))), //
72+
new Pair(selectPackage(""), PackageSource.from("")), //
7273
new Pair(selectPackage("some.package"), PackageSource.from("some.package")), //
7374
new Pair(selectFile("someFile"), FileSource.from(new File("someFile"))), //
7475
new Pair(selectFile("someFile", FilePosition.from(42)),

0 commit comments

Comments
 (0)