You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2023/02/28 09:43:24 UTC
[sling-org-apache-sling-testing-osgi-mock] branch feature/SLING-11792-plugin-mixing created (now 6214016)
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a change to branch feature/SLING-11792-plugin-mixing
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
at 6214016 SLING-11792 Allow mixture of plugins/callbacks
This branch includes the following new commits:
new 6214016 SLING-11792 Allow mixture of plugins/callbacks
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-testing-osgi-mock] 01/01: SLING-11792 Allow mixture of plugins/callbacks
Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch feature/SLING-11792-plugin-mixing
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
commit 62140167761b7cbb16447472a53052844e051734
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Feb 28 10:35:58 2023 +0100
SLING-11792 Allow mixture of plugins/callbacks
---
.../testing/mock/osgi/context/ContextPlugins.java | 147 +++++++++++----------
.../mock/osgi/junit/OsgiContextBuilder.java | 14 +-
.../mock/osgi/junit5/OsgiContextBuilder.java | 10 +-
3 files changed, 87 insertions(+), 84 deletions(-)
diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
index 45e79b1..ead865c 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/context/ContextPlugins.java
@@ -21,6 +21,8 @@ package org.apache.sling.testing.mock.osgi.context;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Stream;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;
@@ -68,15 +70,11 @@ public final class ContextPlugins {
* @param <T> context type
* @param plugin Plugin
*/
- @SuppressWarnings("unused")
@SafeVarargs
- public final <T extends OsgiContextImpl> void addPlugin(@NotNull ContextPlugin<T> @NotNull ... plugin) {
- for (final ContextPlugin<T> item : plugin) {
- if (item == null) {
- continue;
- }
- plugins.add(item);
- }
+ public final void addPlugin(@NotNull ContextPlugin<? extends OsgiContextImpl> @NotNull ... plugin) {
+ Stream.of(plugin)
+ .filter(Objects::nonNull)
+ .forEach(plugins::add);
}
/**
@@ -84,24 +82,25 @@ public final class ContextPlugins {
* @param <T> context type
* @param beforeSetUpCallback Allows the application to register an own callback function that is called before the built-in setup rules are executed.
*/
- @SuppressWarnings("unused")
+ @SuppressWarnings("null")
@SafeVarargs
- public final <T extends OsgiContextImpl> void addBeforeSetUpCallback(@NotNull final ContextCallback<T> @NotNull ... beforeSetUpCallback) {
- for (final ContextCallback<T> item : beforeSetUpCallback) {
- if (item == null) {
- continue;
+ public final void addBeforeSetUpCallback(@NotNull final ContextCallback<? extends OsgiContextImpl> @NotNull ... beforeSetUpCallback) {
+ Stream.of(beforeSetUpCallback)
+ .filter(Objects::nonNull)
+ .forEach(this::addBeforeSetUpCallbackItem);
+ }
+
+ private final <T extends OsgiContextImpl> void addBeforeSetUpCallbackItem(@NotNull final ContextCallback<T> item) {
+ plugins.add(new AbstractContextPlugin<T>() {
+ @Override
+ public void beforeSetUp(@NotNull T context) throws Exception {
+ item.execute(context);
}
- plugins.add(new AbstractContextPlugin<T>() {
- @Override
- public void beforeSetUp(@NotNull T context) throws Exception {
- item.execute(context);
- }
- @Override
- public String toString() {
- return item.toString();
- }
- });
- }
+ @Override
+ public String toString() {
+ return item.toString();
+ }
+ });
}
/**
@@ -109,49 +108,52 @@ public final class ContextPlugins {
* @param <T> context type
* @param afterSetUpCallback Allows the application to register an own callback function that is called after the built-in setup rules are executed.
*/
- @SuppressWarnings("unused")
+ @SuppressWarnings("null")
@SafeVarargs
- public final <T extends OsgiContextImpl> void addAfterSetUpCallback(@NotNull final ContextCallback<T> @NotNull ... afterSetUpCallback) {
- for (final ContextCallback<T> item : afterSetUpCallback) {
- if (item == null) {
- continue;
+ public final void addAfterSetUpCallback(@NotNull final ContextCallback<? extends OsgiContextImpl> @NotNull ... afterSetUpCallback) {
+ Stream.of(afterSetUpCallback)
+ .filter(Objects::nonNull)
+ .forEach(this::addAfterSetUpCallbackItem);
+ }
+
+ private final <T extends OsgiContextImpl> void addAfterSetUpCallbackItem(@NotNull final ContextCallback<T> item) {
+ plugins.add(new AbstractContextPlugin<T>() {
+ @Override
+ public void afterSetUp(@NotNull T context) throws Exception {
+ item.execute(context);
}
- plugins.add(new AbstractContextPlugin<T>() {
- @Override
- public void afterSetUp(@NotNull T context) throws Exception {
- item.execute(context);
- }
- @Override
- public String toString() {
- return item.toString();
- }
- });
- }
+ @Override
+ public String toString() {
+ return item.toString();
+ }
+ });
}
+
/**
* Add callback
* @param <T> context type
* @param beforeTearDownCallback Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
*/
- @SuppressWarnings("unused")
+ @SuppressWarnings("null")
@SafeVarargs
- public final <T extends OsgiContextImpl> void addBeforeTearDownCallback(@NotNull final ContextCallback<T> @NotNull ... beforeTearDownCallback) {
- for (final ContextCallback<T> item : beforeTearDownCallback) {
- if (item == null) {
- continue;
+ public final void addBeforeTearDownCallback(@NotNull final ContextCallback<? extends OsgiContextImpl> @NotNull ... beforeTearDownCallback) {
+ Stream.of(beforeTearDownCallback)
+ .filter(Objects::nonNull)
+ .forEach(this::addBeforeTearDownCallbackItem);
+ }
+
+ private final <T extends OsgiContextImpl> void addBeforeTearDownCallbackItem(@NotNull final ContextCallback<T> item) {
+ plugins.add(new AbstractContextPlugin<T>() {
+ @Override
+ public void beforeTearDown(@NotNull T context) throws Exception {
+ item.execute(context);
}
- plugins.add(new AbstractContextPlugin<T>() {
- @Override
- public void beforeTearDown(@NotNull T context) throws Exception {
- item.execute(context);
- }
- @Override
- public String toString() {
- return item.toString();
- }
- });
- }
+ @Override
+ public String toString() {
+ return item.toString();
+ }
+ });
}
/**
@@ -159,24 +161,25 @@ public final class ContextPlugins {
* @param <T> context type
* @param afterTearDownCallback Allows the application to register an own callback function that is after before the built-in teardown rules are executed.
*/
- @SuppressWarnings("unused")
+ @SuppressWarnings("null")
@SafeVarargs
- public final <T extends OsgiContextImpl> void addAfterTearDownCallback(@NotNull final ContextCallback<T> @NotNull ... afterTearDownCallback) {
- for (final ContextCallback<T> item : afterTearDownCallback) {
- if (item == null) {
- continue;
+ public final void addAfterTearDownCallback(@NotNull final ContextCallback<? extends OsgiContextImpl> @NotNull ... afterTearDownCallback) {
+ Stream.of(afterTearDownCallback)
+ .filter(Objects::nonNull)
+ .forEach(this::addAfterTearDownCallbackItem);
+ }
+
+ private final <T extends OsgiContextImpl> void addAfterTearDownCallbackItem(@NotNull final ContextCallback<T> item) {
+ plugins.add(new AbstractContextPlugin<T>() {
+ @Override
+ public void afterTearDown(@NotNull T context) throws Exception {
+ item.execute(context);
}
- plugins.add(new AbstractContextPlugin<T>() {
- @Override
- public void afterTearDown(@NotNull T context) throws Exception {
- item.execute(context);
- }
- @Override
- public String toString() {
- return item.toString();
- }
- });
- }
+ @Override
+ public String toString() {
+ return item.toString();
+ }
+ });
}
/**
diff --git a/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java b/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
index bdb72dd..3003a6a 100644
--- a/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
+++ b/junit4/src/main/java/org/apache/sling/testing/mock/osgi/junit/OsgiContextBuilder.java
@@ -18,11 +18,11 @@
*/
package org.apache.sling.testing.mock.osgi.junit;
+import org.apache.sling.testing.mock.osgi.context.ContextCallback;
+import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
import org.apache.sling.testing.mock.osgi.context.ContextPlugins;
import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
import org.jetbrains.annotations.NotNull;
-import org.apache.sling.testing.mock.osgi.context.ContextCallback;
-import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
import org.osgi.annotation.versioning.ProviderType;
/**
@@ -44,7 +44,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder plugin(@NotNull ContextPlugin<T> @NotNull ... plugin) {
+ public final @NotNull OsgiContextBuilder plugin(@NotNull ContextPlugin<? extends OsgiContextImpl> @NotNull ... plugin) {
plugins.addPlugin(plugin);
return this;
}
@@ -55,7 +55,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder beforeSetUp(@NotNull ContextCallback<T> @NotNull ... beforeSetUpCallback) {
+ public final @NotNull OsgiContextBuilder beforeSetUp(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... beforeSetUpCallback) {
plugins.addBeforeSetUpCallback(beforeSetUpCallback);
return this;
}
@@ -66,7 +66,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder afterSetUp(@NotNull ContextCallback<T> @NotNull ... afterSetUpCallback) {
+ public final @NotNull OsgiContextBuilder afterSetUp(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... afterSetUpCallback) {
plugins.addAfterSetUpCallback(afterSetUpCallback);
return this;
}
@@ -77,7 +77,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder beforeTearDown(@NotNull ContextCallback<T> @NotNull ... beforeTearDownCallback) {
+ public final @NotNull OsgiContextBuilder beforeTearDown(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... beforeTearDownCallback) {
plugins.addBeforeTearDownCallback(beforeTearDownCallback);
return this;
}
@@ -88,7 +88,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final @NotNull <T extends OsgiContextImpl> OsgiContextBuilder afterTearDown(@NotNull ContextCallback<T> @NotNull ... afterTearDownCallback) {
+ public final @NotNull OsgiContextBuilder afterTearDown(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... afterTearDownCallback) {
plugins.addAfterTearDownCallback(afterTearDownCallback);
return this;
}
diff --git a/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextBuilder.java b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextBuilder.java
index 8a90f81..5192863 100644
--- a/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextBuilder.java
+++ b/junit5/src/main/java/org/apache/sling/testing/mock/osgi/junit5/OsgiContextBuilder.java
@@ -45,7 +45,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> OsgiContextBuilder plugin(@NotNull ContextPlugin<T> @NotNull ... plugin) {
+ public final OsgiContextBuilder plugin(@NotNull ContextPlugin<? extends OsgiContextImpl> @NotNull ... plugin) {
plugins.addPlugin(plugin);
return this;
}
@@ -58,7 +58,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> OsgiContextBuilder beforeSetUp(@NotNull ContextCallback<T> @NotNull ... beforeSetUpCallback) {
+ public final OsgiContextBuilder beforeSetUp(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... beforeSetUpCallback) {
plugins.addBeforeSetUpCallback(beforeSetUpCallback);
return this;
}
@@ -71,7 +71,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> OsgiContextBuilder afterSetUp(@NotNull ContextCallback<T> @NotNull ... afterSetUpCallback) {
+ public final OsgiContextBuilder afterSetUp(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... afterSetUpCallback) {
plugins.addAfterSetUpCallback(afterSetUpCallback);
return this;
}
@@ -84,7 +84,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> OsgiContextBuilder beforeTearDown(@NotNull ContextCallback<T> @NotNull ... beforeTearDownCallback) {
+ public final OsgiContextBuilder beforeTearDown(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... beforeTearDownCallback) {
plugins.addBeforeTearDownCallback(beforeTearDownCallback);
return this;
}
@@ -97,7 +97,7 @@ public final class OsgiContextBuilder {
* @return this
*/
@SafeVarargs
- public final <T extends OsgiContextImpl> OsgiContextBuilder afterTearDown(@NotNull ContextCallback<T> @NotNull ... afterTearDownCallback) {
+ public final OsgiContextBuilder afterTearDown(@NotNull ContextCallback<? extends OsgiContextImpl> @NotNull ... afterTearDownCallback) {
plugins.addAfterTearDownCallback(afterTearDownCallback);
return this;
}