Skip to content

Commit 665501c

Browse files
committed
Allow default package for PackageSource
1 parent e123ed6 commit 665501c

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ private PackageSource(Package javaPackage) {
6060
}
6161

6262
private PackageSource(String packageName) {
63-
this.packageName = Preconditions.notBlank(packageName, "package name must not be null or blank");
63+
Preconditions.notNull(packageName, "package name must not be null");
64+
Preconditions.condition(packageName.isEmpty() || !packageName.isBlank(),
65+
"package name must not contain only whitespace");
66+
this.packageName = packageName;
6467
}
6568

6669
/**

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
/**
@@ -49,9 +51,11 @@ void packageSourceFromNullPackageReference() {
4951
assertThrows(PreconditionViolationException.class, () -> PackageSource.from((Package) null));
5052
}
5153

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

5761
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)