[java-shib-shared] branch main updated: Add a mock resolver base class for tests.
Scott Cantor
cantor.2 at osu.edu
Tue May 21 19:21:39 UTC 2024
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=c46ccbf8583e0ae09efd115835b517887f03e8ac
The following commit(s) were added to refs/heads/main by this push:
new c46ccbf8 Add a mock resolver base class for tests.
c46ccbf8 is described below
commit c46ccbf8583e0ae09efd115835b517887f03e8ac
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue May 21 15:21:36 2024 -0400
Add a mock resolver base class for tests.
---
.../shared/testing/MockExceptionCriterion.java | 49 +++++++++++++++++++
.../shibboleth/shared/testing/MockResolver.java | 55 ++++++++++++++++++++++
2 files changed, 104 insertions(+)
diff --git a/shib-testing/src/main/java/net/shibboleth/shared/testing/MockExceptionCriterion.java b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockExceptionCriterion.java
new file mode 100644
index 00000000..6f732977
--- /dev/null
+++ b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockExceptionCriterion.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.shared.testing;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.resolver.Criterion;
+import net.shibboleth.shared.resolver.ResolverException;
+
+/**
+ * A mock {@link Criterion} to cause a resolver to raise an exception.
+ *
+ * @since 9.1.3
+ */
+public class MockExceptionCriterion implements Criterion {
+
+ @Nonnull final ResolverException exception;
+
+ /**
+ * Constructor.
+ *
+ * @param e exception to raise
+ */
+ public MockExceptionCriterion(@Nonnull final ResolverException e) {
+ exception = Constraint.isNotNull(e, "Exception cannot be null.");
+ }
+
+ /**
+ * Gets the exception to raise.
+ *
+ * @return exception to raise
+ */
+ @Nonnull public ResolverException getException() {
+ return exception;
+ }
+}
\ No newline at end of file
diff --git a/shib-testing/src/main/java/net/shibboleth/shared/testing/MockResolver.java b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockResolver.java
new file mode 100644
index 00000000..68c88c20
--- /dev/null
+++ b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockResolver.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.shared.testing;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.resolver.CriteriaSet;
+import net.shibboleth.shared.resolver.Resolver;
+import net.shibboleth.shared.resolver.ResolverException;
+
+/**
+ * Mock {@link Resolver} for tests.
+ *
+ * @param <T> type of object being resolved
+ *
+ * @since 9.1.3
+ */
+public class MockResolver<T> implements Resolver<T,CriteriaSet> {
+
+ /** {@inheritDoc} */
+ @Nonnull public Iterable<T> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
+
+ final T t = resolveSingle(criteria);
+ return t != null ? CollectionSupport.singletonList(t) : CollectionSupport.emptyList();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable public T resolveSingle(@Nullable final CriteriaSet criteria) throws ResolverException {
+ if (criteria == null ) {
+ return null;
+ }
+
+ final MockExceptionCriterion exceptCrit = criteria.get(MockExceptionCriterion.class);
+ if (exceptCrit != null) {
+ throw exceptCrit.getException();
+ }
+
+ return null;
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list