Skip to content

Commit c141846

Browse files
committed
Make method signatures for Function parameters more flexible
1 parent 067d976 commit c141846

File tree

12 files changed

+34
-18
lines changed

12 files changed

+34
-18
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-6.0.0-M1.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ repository on GitHub.
7676
property has been removed. JUnit now always adheres to standard Java semantics regarding
7777
whether a given field or method is visible or overridden according to the rules of the
7878
Java language.
79+
* The type bounds of the following methods have been changed to be more flexible and allow
80+
nullable and non-nullable types:
81+
- `ConfigurationParameters.get(String, Function)`
82+
- `NamespacedHierarchicalStore.getOrComputeIfAbsent(N, K, Function)`
83+
- `NamespacedHierarchicalStore.getOrComputeIfAbsent(N, K, Function, Class)`
7984

8085
[[release-notes-6.0.0-M1-junit-platform-new-features-and-improvements]]
8186
==== New Features and Improvements
@@ -112,6 +117,11 @@ repository on GitHub.
112117
`callsInPlace(executable, AT_MOST_ONCE)` which might result in compilation errors.
113118
* The `junit-jupiter-migrationsupport` artifact and its contained classes are now
114119
deprecated and will be removed in the next major version.
120+
* The type bounds of the following methods have been changed to be more flexible and allow
121+
nullable and non-nullable types:
122+
- `ExtensionContext.getConfigurationParameter(String, Function)`
123+
- `ExtensionContext.getOrComputeIfAbsent(K, Function)`
124+
- `ExtensionContext.getOrComputeIfAbsent(K, Function, Class)`
115125

116126
[[release-notes-6.0.0-M1-junit-jupiter-new-features-and-improvements]]
117127
==== New Features and Improvements

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ExtensionContext.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ default Method getRequiredTestMethod() {
345345
* @see org.junit.platform.engine.ConfigurationParameters
346346
*/
347347
@API(status = STABLE, since = "5.10")
348-
<T> Optional<T> getConfigurationParameter(String key, Function<String, T> transformer);
348+
<T> Optional<T> getConfigurationParameter(String key, Function<? super String, ? extends @Nullable T> transformer);
349349

350350
/**
351351
* Publish a map of key-value pairs to be consumed by an
@@ -649,7 +649,8 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
649649
* @see CloseableResource
650650
* @see AutoCloseable
651651
*/
652-
<K, V extends @Nullable Object> @Nullable Object getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator);
652+
<K, V extends @Nullable Object> @Nullable Object getOrComputeIfAbsent(K key,
653+
Function<? super K, ? extends V> defaultCreator);
653654

654655
/**
655656
* Get the value of the specified required type that is stored under the
@@ -680,8 +681,8 @@ default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) {
680681
* @see CloseableResource
681682
* @see AutoCloseable
682683
*/
683-
<K, V extends @Nullable Object> @Nullable V getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator,
684-
Class<V> requiredType);
684+
<K, V extends @Nullable Object> @Nullable V getOrComputeIfAbsent(K key,
685+
Function<? super K, ? extends V> defaultCreator, Class<V> requiredType);
685686

686687
/**
687688
* Store a {@code value} for later retrieval under the supplied {@code key}.

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/config/CachingJupiterConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Optional<String> getRawConfigurationParameter(String key) {
5959
}
6060

6161
@Override
62-
public <T> Optional<T> getRawConfigurationParameter(String key, Function<String, T> transformer) {
62+
public <T> Optional<T> getRawConfigurationParameter(String key, Function<? super String, ? extends T> transformer) {
6363
return delegate.getRawConfigurationParameter(key, transformer);
6464
}
6565

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/config/DefaultJupiterConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Optional<String> getRawConfigurationParameter(String key) {
120120
}
121121

122122
@Override
123-
public <T> Optional<T> getRawConfigurationParameter(String key, Function<String, T> transformer) {
123+
public <T> Optional<T> getRawConfigurationParameter(String key, Function<? super String, ? extends T> transformer) {
124124
return configurationParameters.get(key, transformer);
125125
}
126126

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/config/JupiterConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public interface JupiterConfiguration {
5757

5858
Optional<String> getRawConfigurationParameter(String key);
5959

60-
<T> Optional<T> getRawConfigurationParameter(String key, Function<String, T> transformer);
60+
<T> Optional<T> getRawConfigurationParameter(String key, Function<? super String, ? extends T> transformer);
6161

6262
boolean isParallelExecutionEnabled();
6363

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/AbstractExtensionContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public Optional<String> getConfigurationParameter(String key) {
242242
}
243243

244244
@Override
245-
public <V> Optional<V> getConfigurationParameter(String key, Function<String, V> transformer) {
245+
public <V> Optional<V> getConfigurationParameter(String key,
246+
Function<? super String, ? extends @Nullable V> transformer) {
246247
return this.configuration.getRawConfigurationParameter(key, transformer);
247248
}
248249

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/NamespaceAwareStore.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public NamespaceAwareStore(NamespacedHierarchicalStore<Namespace> valuesStore, N
5454
}
5555

5656
@Override
57-
public <K, V extends @Nullable Object> @Nullable Object getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator) {
57+
public <K, V extends @Nullable Object> @Nullable Object getOrComputeIfAbsent(K key,
58+
Function<? super K, ? extends V> defaultCreator) {
5859
Preconditions.notNull(key, "key must not be null");
5960
Preconditions.notNull(defaultCreator, "defaultCreator function must not be null");
6061
Supplier<@Nullable Object> action = () -> this.valuesStore.getOrComputeIfAbsent(this.namespace, key,
@@ -63,8 +64,8 @@ public NamespaceAwareStore(NamespacedHierarchicalStore<Namespace> valuesStore, N
6364
}
6465

6566
@Override
66-
public <K, V extends @Nullable Object> @Nullable V getOrComputeIfAbsent(K key, Function<? super K, ? extends V> defaultCreator,
67-
Class<V> requiredType) {
67+
public <K, V extends @Nullable Object> @Nullable V getOrComputeIfAbsent(K key,
68+
Function<? super K, ? extends V> defaultCreator, Class<V> requiredType) {
6869
Preconditions.notNull(key, "key must not be null");
6970
Preconditions.notNull(defaultCreator, "defaultCreator function must not be null");
7071
Preconditions.notNull(requiredType, "requiredType must not be null");

junit-platform-engine/src/main/java/org/junit/platform/engine/ConfigurationParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public interface ConfigurationParameters {
117117
* @see #CONFIG_FILE_NAME
118118
*/
119119
@API(status = STABLE, since = "1.3")
120-
default <T> Optional<T> get(String key, Function<String, ? extends @Nullable T> transformer) {
120+
default <T> Optional<T> get(String key, Function<? super String, ? extends @Nullable T> transformer) {
121121
Preconditions.notNull(transformer, "transformer must not be null");
122122
return get(key).map(input -> {
123123
try {

junit-platform-engine/src/main/java/org/junit/platform/engine/support/config/PrefixedConfigurationParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Optional<Boolean> getBoolean(String key) {
5858
}
5959

6060
@Override
61-
public <T> Optional<T> get(String key, Function<String, ? extends @Nullable T> transformer) {
61+
public <T> Optional<T> get(String key, Function<? super String, ? extends @Nullable T> transformer) {
6262
return delegate.get(prefixed(key), transformer);
6363
}
6464

junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/NamespacedHierarchicalStore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ public void close() {
220220
* be cast to the required type, or if this store has already been closed
221221
*/
222222
public <K, V extends @Nullable Object> @Nullable V getOrComputeIfAbsent(N namespace, K key,
223-
Function<? super K, ? extends V> defaultCreator, Class<V> requiredType) throws NamespacedHierarchicalStoreException {
223+
Function<? super K, ? extends V> defaultCreator, Class<V> requiredType)
224+
throws NamespacedHierarchicalStoreException {
224225

225226
Object value = getOrComputeIfAbsent(namespace, key, defaultCreator);
226227
return castToRequiredType(key, value, requiredType);

0 commit comments

Comments
 (0)