You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/05/30 07:22:07 UTC
[isis] branch master updated: ISIS-1956: introduces _Reflect
(Internal API), removes org.reflections
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new d119856 ISIS-1956: introduces _Reflect (Internal API), removes org.reflections
d119856 is described below
commit d1198565aa1381ca963141aa7f27a8ff170595e7
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed May 30 09:21:43 2018 +0200
ISIS-1956: introduces _Reflect (Internal API), removes org.reflections
Task-Url: https://issues.apache.org/jira/browse/ISIS-1956
---
.../apache/isis/commons/internal/_Constants.java | 12 ++
.../commons/internal/collections/_Collections.java | 10 ++
.../isis/commons/internal/reflection/_Reflect.java | 164 +++++++++++++++++++++
.../package-info.java} | 43 +-----
core/unittestsupport-test/pom.xml | 19 ---
core/unittestsupport/pom.xml | 20 ---
.../AbstractApplyToAllContractTest.java | 9 +-
...irectionalRelationshipContractTestAbstract.java | 104 +++++++++----
.../unittestsupport/bidir/InstantiatorMap.java | 8 +-
.../ComparableContractTest_compareTo.java | 3 +-
.../comparable/ComparableContractTester.java | 8 +-
...rviceMethodMustBeFinalContractTestAbstract.java | 11 +-
.../core/unittestsupport/jaxb/JaxbMatchers.java | 18 +--
.../core/unittestsupport/jmocking/IsisActions.java | 3 +-
.../unittestsupport/jmocking/JMockActions.java | 6 +-
.../jmocking/JUnitRuleMockery2.java | 6 +-
.../unittestsupport/jmocking/MyMockomatic.java | 11 +-
.../unittestsupport/soap/PublishedEndpoints.java | 7 +-
.../soap/SoapEndpointPublishingRule.java | 24 +--
.../unittestsupport/soap/SoapEndpointSpec.java | 14 +-
.../sortedsets/SortedSetsContractTestAbstract.java | 13 +-
.../core/unittestsupport/utils/CollectUtils.java | 2 -
.../core/unittestsupport/utils/ReflectUtils.java | 52 +++----
23 files changed, 356 insertions(+), 211 deletions(-)
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/_Constants.java b/core/commons/src/main/java/org/apache/isis/commons/internal/_Constants.java
index 85c86a4..fb789f6 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/_Constants.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/_Constants.java
@@ -19,6 +19,9 @@
package org.apache.isis.commons.internal;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* <h1>- internal use only -</h1>
* <p>
@@ -55,5 +58,14 @@ public final class _Constants {
* empty array of byte
*/
public static final byte[] emptyBytes = new byte[0];
+
+ /**
+ * writer that does nothing
+ */
+ public static final Writer nopWriter = new Writer() {
+ @Override public void write(char[] cbuf, int off, int len) throws IOException { }
+ @Override public void flush() throws IOException { }
+ @Override public void close() throws IOException { }
+ };
}
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java
index 91dffda..38d0725 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java
@@ -143,6 +143,16 @@ public final class _Collections {
return _Collections_SortedSetOfList.of(list);
}
+ // -- STREAM TO COMMON COLLECTIONS
+
+ public static <T> Collector<T, ?, HashSet<T>> toHashSet() {
+ return Collectors.toCollection(HashSet::new);
+ }
+
+ public static <T> Collector<T, ?, ArrayList<T>> toArrayList() {
+ return Collectors.toCollection(ArrayList::new);
+ }
+
// -- STREAM TO UMODIFIABLE COLLECTION COLLECTORS
/**
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
new file mode 100644
index 0000000..da1c3bc
--- /dev/null
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.isis.commons.internal.reflection;
+
+import static org.apache.isis.commons.internal.base._NullSafe.stream;
+import static org.apache.isis.commons.internal.base._With.mapIfPresentElse;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import javax.annotation.Nullable;
+
+/**
+ * <h1>- internal use only -</h1>
+ * <p>
+ * Reflection utilities.
+ * </p>
+ * <p>
+ * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this package! <br/>
+ * These may be changed or removed without notice!
+ * </p>
+ * @since 2.0.0
+ */
+public final class _Reflect {
+
+ private _Reflect() {}
+
+ // -- PREDICATES
+
+ /**
+ * Whether member name equals given {@code prefix}
+ * @param prefix
+ * @return
+ */
+ public static <T extends Member> Predicate<T> withName(final String memberName) {
+ return m -> m != null && memberName.equals(m.getName());
+ }
+
+ /**
+ * Whether member name startsWith given {@code prefix}
+ * @param prefix
+ * @return
+ */
+ public static <T extends Member> Predicate<T> withPrefix(final String prefix) {
+ return m -> m != null && m.getName().startsWith(prefix);
+ }
+
+ /**
+ * Whether method parameters count equal to given {@code count}
+ * @param count
+ * @return
+ */
+ public static Predicate<Method> withMethodParametersCount(final int count) {
+ return (Method m) -> m != null && m.getParameterTypes().length == count;
+ }
+
+ /**
+ * Whether field type is assignable to given {@code type}
+ * @param type
+ * @return
+ */
+ public static <T> Predicate<Field> withTypeAssignableTo(final Class<T> type) {
+ return (Field f) -> f != null && type.isAssignableFrom(f.getType());
+ }
+
+ // -- FIELDS
+
+ /**
+ * Stream fields of given {@code type}
+ * @param type (nullable)
+ * @return
+ */
+ public static Stream<Field> streamFields(@Nullable Class<?> type) {
+ return stream( mapIfPresentElse(type, Class::getDeclaredFields, (Field[])null) );
+ }
+
+ /**
+ * Stream all fields of given {@code type}, up the super class hierarchy.
+ * @param type (nullable)
+ * @return
+ */
+ public static Stream<Field> streamAllFields(@Nullable Class<?> type) {
+ return streamTypeHierarchy(type)
+ .filter(Object.class::equals) // do not process Object class.
+ .flatMap(_Reflect::streamFields);
+ }
+
+ // -- METHODS
+
+ /**
+ * Stream methods of given {@code type}
+ * @param type (nullable)
+ * @return
+ */
+ public static Stream<Method> streamMethods(@Nullable Class<?> type) {
+ return stream( mapIfPresentElse(type,
+ type.isInterface() ? Class::getMethods : Class::getDeclaredMethods, (Method[])null) );
+ }
+
+ /**
+ * Stream all methods of given {@code type}, up the super class hierarchy.
+ * @param type (nullable)
+ * @return
+ */
+ public static Stream<Method> streamAllMethods(@Nullable Class<?> type) {
+ return streamTypeHierarchy(type)
+ .filter(Object.class::equals) // do not process Object class.
+ .flatMap(_Reflect::streamMethods);
+ }
+
+ // SUPER CLASSES
+
+ /**
+ * Stream all types of given {@code type}, up the super class hierarchy starting with self
+ * @param type
+ * @param includeObject whether to include {@code Object}
+ * @return
+ */
+ public static Stream<Class<?>> streamTypeHierarchy(@Nullable Class<?> type) {
+
+ // https://stackoverflow.com/questions/40240450/java8-streaming-a-class-hierarchy?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
+ // Java 9+ will allow ...
+ // return Stream.iterate(type, Objects::nonNull, Class::getSuperclass);
+
+ return StreamSupport.stream(
+ new Spliterators.AbstractSpliterator<Class<?>>(100L,
+ Spliterator.ORDERED|Spliterator.IMMUTABLE|Spliterator.NONNULL) {
+ Class<?> current = type;
+ public boolean tryAdvance(Consumer<? super Class<?>> action) {
+ if(current == null) return false;
+ action.accept(current);
+ current = current.getSuperclass();
+ return true;
+ }
+ }, false);
+ }
+
+
+
+}
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/_Constants.java b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/package-info.java
similarity index 53%
copy from core/commons/src/main/java/org/apache/isis/commons/internal/_Constants.java
copy to core/commons/src/main/java/org/apache/isis/commons/internal/reflection/package-info.java
index 85c86a4..9713666 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/_Constants.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/package-info.java
@@ -16,44 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-package org.apache.isis.commons.internal;
-
/**
- * <h1>- internal use only -</h1>
- * <p>
- * A collection of commonly used constants.
- * </p>
- * <p>
- * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this package! <br/>
+ * <h1>Internal API</h1>
+ * Internal classes, contributing to the internal proprietary API.
* These may be changed or removed without notice!
+ * <p>
+ * <b>WARNING</b>:
+ * Do NOT use any of the classes provided by this package!
* </p>
- *
- * @since 2.0.0
*/
-public final class _Constants {
-
- private _Constants(){}
-
- /**
- * Convenient e.g. for reflective invocation
- */
- public static final Object[] emptyObjects = new Object[0];
-
- /**
- * Convenient e.g. for reflective invocation
- */
- @SuppressWarnings("rawtypes")
- public static final Class[] emptyClasses = new Class[0];
-
- /**
- * Convenient e.g. for toArray conversions
- */
- public static final String[] emptyStringArray = new String[0];
-
- /**
- * empty array of byte
- */
- public static final byte[] emptyBytes = new byte[0];
-
-}
+package org.apache.isis.commons.internal.reflection;
\ No newline at end of file
diff --git a/core/unittestsupport-test/pom.xml b/core/unittestsupport-test/pom.xml
index f05a9cd..b55dc28 100644
--- a/core/unittestsupport-test/pom.xml
+++ b/core/unittestsupport-test/pom.xml
@@ -121,25 +121,6 @@
<scope>provided</scope>
</dependency>
-<!-- <dependency> -->
-<!-- <groupId>org.reflections</groupId> -->
-<!-- <artifactId>reflections</artifactId> -->
-<!-- <exclusions> -->
-<!-- <exclusion> -->
- <!-- part of JDK 6+ the version here does not provide getUserData(),
- setUserData(), as needed by xmlsnapshot functionality in isis-core-runtime. -->
-<!-- <groupId>xml-apis</groupId> -->
-<!-- <artifactId>xml-apis</artifactId> -->
-<!-- </exclusion> -->
-<!-- <exclusion> -->
- <!-- provided by plugins if required -->
-<!-- <groupId>org.javassist</groupId> -->
-<!-- <artifactId>javassist</artifactId> -->
-<!-- </exclusion> -->
-<!-- </exclusions> -->
-<!-- <optional>true</optional> -->
-<!-- </dependency> -->
-
</dependencies>
</project>
diff --git a/core/unittestsupport/pom.xml b/core/unittestsupport/pom.xml
index 9096d5b..01fb43f 100644
--- a/core/unittestsupport/pom.xml
+++ b/core/unittestsupport/pom.xml
@@ -96,26 +96,6 @@
<scope>provided</scope>
</dependency>
- <!-- TODO [ahuber] work in progress to remove these dependencies -->
- <dependency>
- <groupId>org.reflections</groupId>
- <artifactId>reflections</artifactId>
- <exclusions>
- <exclusion>
- <!-- part of JDK 6+ the version here does not provide getUserData(),
- setUserData(), as needed by xmlsnapshot functionality in isis-core-runtime. -->
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- </exclusion>
- <exclusion>
- <!-- provided by plugins if required -->
- <groupId>org.javassist</groupId>
- <artifactId>javassist</artifactId>
- </exclusion>
- </exclusions>
- <optional>true</optional>
- </dependency>
-
</dependencies>
</project>
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/AbstractApplyToAllContractTest.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/AbstractApplyToAllContractTest.java
index f821e8d..650a00a 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/AbstractApplyToAllContractTest.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/AbstractApplyToAllContractTest.java
@@ -21,17 +21,16 @@ import java.io.PrintWriter;
import java.io.Writer;
import java.util.Comparator;
import java.util.Set;
+import java.util.TreeSet;
import javax.jdo.annotations.PersistenceCapable;
+import org.apache.isis.commons.internal._Constants;
import org.apache.isis.core.plugins.classdiscovery.ClassDiscovery;
import org.apache.isis.core.plugins.classdiscovery.ClassDiscoveryPlugin;
import org.apache.isis.core.unittestsupport.utils.IndentPrinter;
import org.junit.Test;
-import com.google.common.collect.Sets;
-import com.google.common.io.ByteStreams;
-
/**
* Provides some basic infrastructure to iterate over all entity types and
* apply some contract test.
@@ -44,7 +43,7 @@ public abstract class AbstractApplyToAllContractTest {
protected AbstractApplyToAllContractTest(
final String packagePrefix) {
discovery = ClassDiscoveryPlugin.get().discover(packagePrefix);
- out = new IndentPrinter(new PrintWriter(ByteStreams.nullOutputStream()));
+ out = new IndentPrinter(_Constants.nopWriter);
}
public AbstractApplyToAllContractTest withLoggingTo(Writer out) {
@@ -61,7 +60,7 @@ public abstract class AbstractApplyToAllContractTest {
public void searchAndTest() throws Exception {
Set<Class<?>> entityTypes =
- Sets.newTreeSet(new Comparator<Class<?>>() {
+ new TreeSet<>(new Comparator<Class<?>>() {
@Override
public int compare(Class<?> o1, Class<?> o2) {
return o1.getName().compareTo(o2.getName());
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/BidirectionalRelationshipContractTestAbstract.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/BidirectionalRelationshipContractTestAbstract.java
index 46c73ca..b893afe 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/BidirectionalRelationshipContractTestAbstract.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/BidirectionalRelationshipContractTestAbstract.java
@@ -16,6 +16,15 @@
*/
package org.apache.isis.core.unittestsupport.bidir;
+import static org.apache.isis.commons.internal.collections._Collections.toHashSet;
+import static org.apache.isis.commons.internal.reflection._Reflect.streamAllFields;
+import static org.apache.isis.commons.internal.reflection._Reflect.streamAllMethods;
+import static org.apache.isis.commons.internal.reflection._Reflect.withName;
+import static org.apache.isis.commons.internal.reflection._Reflect.withMethodParametersCount;
+import static org.apache.isis.core.unittestsupport.utils.ReflectUtils.withEntityParameter;
+import static org.apache.isis.core.unittestsupport.utils.ReflectUtils.withParametersAssignableFrom;
+import static org.apache.isis.core.unittestsupport.utils.ReflectUtils.withReturnTypeAssignableFrom;
+import static org.apache.isis.core.unittestsupport.utils.ReflectUtils.withTypeAssignableFrom;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.greaterThan;
@@ -25,22 +34,17 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
+import java.util.Map;
import java.util.Set;
+import java.util.function.Predicate;
import javax.jdo.annotations.Persistent;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableMap;
-
-import org.hamcrest.Matchers;
-import org.reflections.ReflectionUtils;
-import org.reflections.Reflections;
-
import org.apache.isis.core.unittestsupport.AbstractApplyToAllContractTest;
import org.apache.isis.core.unittestsupport.utils.CollectUtils;
import org.apache.isis.core.unittestsupport.utils.ReflectUtils;
import org.apache.isis.core.unittestsupport.utils.StringUtils;
+import org.hamcrest.Matchers;
public abstract class BidirectionalRelationshipContractTestAbstract extends AbstractApplyToAllContractTest implements Instantiators {
@@ -48,14 +52,17 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
protected BidirectionalRelationshipContractTestAbstract(
final String packagePrefix,
- ImmutableMap<Class<?>,Instantiator> instantiatorsByClass) {
+ Map<Class<?>, Instantiator> instantiatorsByClass) {
super(packagePrefix);
instantiatorMap = new InstantiatorMap(instantiatorsByClass);
}
@Override
protected void applyContractTest(Class<?> entityType) {
- final Set<Field> mappedByFields = ReflectionUtils.getAllFields(entityType, ReflectUtils.persistentMappedBy);
+ final Set<Field> mappedByFields = streamAllFields(entityType)
+ .filter(ReflectUtils.persistentMappedBy)
+ .collect(toHashSet());
+
for (Field mappedByField : mappedByFields) {
final Parent p = new Parent();
p.entityType = entityType;
@@ -78,7 +85,10 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
// getMethod
final String getMethod = StringUtils.methodNamed("get", p.childField);
- final Set<Method> getMethods = ReflectionUtils.getAllMethods(p.entityType, withConcreteMethodNamed(getMethod));
+ final Set<Method> getMethods = streamAllMethods(p.entityType)
+ .filter(withConcreteMethodNamed(getMethod))
+ .collect(toHashSet());
+
assertThat(p.desc() + ": no unique getXxx() method:" + getMethods , getMethods.size(), is(greaterThan(0)));
p.getMethod = CollectUtils.firstIn(getMethods);
@@ -88,8 +98,12 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
if(Collection.class.isAssignableFrom(returnType)) {
// addToMethod
final String addToMethod = StringUtils.methodNamed("addTo", p.childField);
- final Set<Method> addToMethods = ReflectionUtils.getAllMethods(p.entityType,
- Predicates.and(withConcreteMethodNamed(addToMethod), ReflectionUtils.withParametersCount(1), ReflectUtils.withEntityParameter()));
+ final Set<Method> addToMethods = streamAllMethods(p.entityType)
+ .filter(withConcreteMethodNamed(addToMethod))
+ .filter(withMethodParametersCount(1))
+ .filter(withEntityParameter())
+ .collect(toHashSet());
+
if(addToMethods.size() != 1) {
// just skip
out.println("no addToXxx() method in parent");
@@ -99,8 +113,12 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
// removeFromMethod
final String removeFromMethod = StringUtils.methodNamed("removeFrom", p.childField);
- final Set<Method> removeFromMethods = ReflectionUtils.getAllMethods(p.entityType,
- Predicates.and(withConcreteMethodNamed(removeFromMethod), ReflectionUtils.withParametersCount(1), ReflectUtils.withEntityParameter()));
+ final Set<Method> removeFromMethods = streamAllMethods(p.entityType)
+ .filter(withConcreteMethodNamed(removeFromMethod))
+ .filter(withMethodParametersCount(1))
+ .filter(withEntityParameter())
+ .collect(toHashSet());
+
if(removeFromMethods.size() != 1) {
// just skip
out.println("no removeFromXxx() method in parent");
@@ -120,8 +138,12 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
// modify
String modifyMethod = StringUtils.methodNamed("modify", p.childField);
- final Set<Method> modifyMethods = ReflectionUtils.getAllMethods(p.entityType,
- Predicates.and(withConcreteMethodNamed(modifyMethod), ReflectionUtils.withParametersCount(1), ReflectUtils.withEntityParameter()));
+ final Set<Method> modifyMethods = streamAllMethods(p.entityType)
+ .filter(withConcreteMethodNamed(modifyMethod))
+ .filter(withMethodParametersCount(1))
+ .filter(withEntityParameter())
+ .collect(toHashSet());
+
if(modifyMethods.size() != 1) {
// just skip
out.println("no modifyXxx() method in parent");
@@ -131,8 +153,11 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
// clear
String clearMethod = StringUtils.methodNamed("clear", p.childField);
- final Set<Method> clearMethods = ReflectionUtils.getAllMethods(p.entityType,
- Predicates.and(withConcreteMethodNamed(clearMethod), ReflectionUtils.withParametersCount(0)));
+ final Set<Method> clearMethods = streamAllMethods(p.entityType)
+ .filter(withConcreteMethodNamed(clearMethod))
+ .filter(withMethodParametersCount(0))
+ .collect(toHashSet());
+
if(clearMethods.size() != 1) {
// just skip
out.println("no clearXxx() method in parent");
@@ -160,12 +185,13 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
process(p, c);
}
- private static Predicate<Method> withConcreteMethodNamed(final String getMethod) {
- return Predicates.and(ReflectionUtils.withName(getMethod), new Predicate<Method>(){
- public boolean apply(Method m) {
- return !m.isSynthetic() && !Modifier.isAbstract(m.getModifiers());
- }
- });
+ private static Predicate<Method> withConcreteMethodNamed(final String methodName) {
+ return (Method m) -> {
+ if(m==null || !methodName.equals(m.getName())){
+ return false;
+ }
+ return !m.isSynthetic() && !Modifier.isAbstract(m.getModifiers());
+ };
}
@@ -193,22 +219,33 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
private void process(Parent p, Child c) {
// mappedBy field
- final Set<Field> parentFields = ReflectionUtils.getAllFields(c.entityType, Predicates.and(ReflectionUtils.withName(p.mappedBy), ReflectUtils.withTypeAssignableFrom(p.entityType)));
+ final Set<Field> parentFields = streamAllFields(c.entityType)
+ .filter(withName(p.mappedBy))
+ .filter(withTypeAssignableFrom(p.entityType))
+ .collect(toHashSet());
assertThat(c.entityType.getName()+ ": could not locate '" + p.mappedBy + "' field, returning supertype of " + p.entityType.getSimpleName() +", (as per @Persistent(mappedBy=...) in parent "+ p.entityType.getSimpleName()+")", parentFields.size(), is(1));
c.parentField = CollectUtils.firstIn(parentFields);
// getter
String getterMethod = StringUtils.methodNamed("get", c.parentField);
- final Set<Method> getterMethods = ReflectionUtils.getAllMethods(c.entityType,
- Predicates.and(withConcreteMethodNamed(getterMethod), ReflectionUtils.withParametersCount(0), ReflectUtils.withReturnTypeAssignableFrom(p.entityType)));
+ final Set<Method> getterMethods = streamAllMethods(c.entityType)
+ .filter(withConcreteMethodNamed(getterMethod))
+ .filter(withMethodParametersCount(0))
+ .filter(withReturnTypeAssignableFrom(p.entityType))
+ .collect(toHashSet());
+
assertThat(p.descRel(c) +": could not locate getter " + getterMethod + "() returning supertype of " + p.entityType.getSimpleName(), getterMethods.size(), is(1));
c.getMethod = CollectUtils.firstIn(getterMethods);
// modify
String modifyMethod = StringUtils.methodNamed("modify", c.parentField);
- final Set<Method> modifyMethods = ReflectionUtils.getAllMethods(c.entityType,
- Predicates.and(withConcreteMethodNamed(modifyMethod), ReflectionUtils.withParametersCount(1), ReflectUtils.withParametersAssignableFrom(p.entityType)));
+ final Set<Method> modifyMethods = streamAllMethods(c.entityType)
+ .filter(withConcreteMethodNamed(modifyMethod))
+ .filter(withMethodParametersCount(1))
+ .filter(withParametersAssignableFrom(p.entityType))
+ .collect(toHashSet());
+
if(modifyMethods.size() != 1) {
// just skip
out.println("no modifyXxx() method in child");
@@ -218,8 +255,11 @@ public abstract class BidirectionalRelationshipContractTestAbstract extends Abst
// clear
String clearMethod = StringUtils.methodNamed("clear", c.parentField);
- final Set<Method> clearMethods = ReflectionUtils.getAllMethods(c.entityType,
- Predicates.and(withConcreteMethodNamed(clearMethod), ReflectionUtils.withParametersCount(0)));
+ final Set<Method> clearMethods = streamAllMethods(c.entityType)
+ .filter(withConcreteMethodNamed(clearMethod))
+ .filter(withMethodParametersCount(0))
+ .collect(toHashSet());
+
if(clearMethods.size() != 1) {
// just skip
out.println("no clearXxx() method in child");
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/InstantiatorMap.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/InstantiatorMap.java
index b4e661c..7f9dc29 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/InstantiatorMap.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/InstantiatorMap.java
@@ -16,17 +16,15 @@
*/
package org.apache.isis.core.unittestsupport.bidir;
+import java.util.HashMap;
import java.util.Map;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
class InstantiatorMap {
private Map<Class<?>, Instantiator> instantiatorMap;
- public InstantiatorMap(ImmutableMap<Class<?>, Instantiator> instantiatorMap) {
- this.instantiatorMap = Maps.newHashMap(instantiatorMap);
+ public InstantiatorMap(Map<Class<?>, Instantiator> instantiatorMap) {
+ this.instantiatorMap = new HashMap<>(instantiatorMap);
}
Instantiator get(Class<?> cls) {
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTest_compareTo.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTest_compareTo.java
index 0c5334b..9bb2129 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTest_compareTo.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTest_compareTo.java
@@ -42,7 +42,8 @@ public abstract class ComparableContractTest_compareTo<T extends Comparable<T>>
/**
* Syntax sugar to remove boilerplate from subclasses.
*/
- protected <E> List<E> listOf(E... elements) {
+ @SafeVarargs
+ protected static <E> List<E> listOf(E... elements) {
return Arrays.asList(elements);
}
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTester.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTester.java
index f3dfdb7..2b18d1d 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTester.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/comparable/ComparableContractTester.java
@@ -23,8 +23,7 @@ import static org.junit.Assert.assertThat;
import java.util.List;
-import com.google.common.collect.Lists;
-
+import org.apache.isis.commons.internal.collections._Lists;
import org.hamcrest.Matchers;
public class ComparableContractTester<T extends Comparable<T>> {
@@ -73,8 +72,9 @@ public class ComparableContractTester<T extends Comparable<T>> {
/**
* Syntax sugar to remove boilerplate from subclasses.
*/
- public static <E> List<E> listOf(E... elements) {
- return Lists.newArrayList(elements);
+ @SafeVarargs
+ public static <E> List<E> listOf(E... elements) {
+ return _Lists.of(elements);
}
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/inject/InjectServiceMethodMustBeFinalContractTestAbstract.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/inject/InjectServiceMethodMustBeFinalContractTestAbstract.java
index ecde21c..86b3347 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/inject/InjectServiceMethodMustBeFinalContractTestAbstract.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/inject/InjectServiceMethodMustBeFinalContractTestAbstract.java
@@ -18,6 +18,8 @@
*/
package org.apache.isis.core.unittestsupport.inject;
+import static org.apache.isis.commons.internal.collections._Collections.toHashSet;
+import static org.apache.isis.commons.internal.reflection._Reflect.withPrefix;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -25,9 +27,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Set;
-import org.reflections.ReflectionUtils;
-import org.reflections.Reflections;
-
+import org.apache.isis.commons.internal.reflection._Reflect;
import org.apache.isis.core.unittestsupport.AbstractApplyToAllContractTest;
/**
@@ -47,7 +47,10 @@ public abstract class InjectServiceMethodMustBeFinalContractTestAbstract extends
@Override
protected void applyContractTest(Class<?> entityType) {
- final Set<Method> injectMethods = ReflectionUtils.getAllMethods(entityType, ReflectionUtils.withPrefix("inject"));
+ final Set<Method> injectMethods = _Reflect.streamAllMethods(entityType)
+ .filter(withPrefix("inject"))
+ .collect(toHashSet());
+
for (Method injectMethod : injectMethods) {
try {
final String desc = desc(entityType, injectMethod);
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jaxb/JaxbMatchers.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jaxb/JaxbMatchers.java
index c126f57..ad91577 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jaxb/JaxbMatchers.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jaxb/JaxbMatchers.java
@@ -21,19 +21,18 @@ import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
-import java.net.URL;
import java.nio.charset.Charset;
import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
-import com.google.common.base.Objects;
-import com.google.common.collect.MapMaker;
-import com.google.common.io.Resources;
-
+import org.apache.isis.commons.internal.base._Casts;
+import org.apache.isis.commons.internal.resources._Resource;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@@ -54,7 +53,7 @@ public class JaxbMatchers {
protected boolean matchesSafely(final T item) {
final String expectedXml = JaxbUtil2.toXml(expected);
final String itemXml = JaxbUtil2.toXml(item);
- return Objects.equal(expectedXml, itemXml);
+ return Objects.equals(expectedXml, itemXml);
}
@Override
@@ -76,7 +75,7 @@ class JaxbUtil2 {
Unmarshaller un = null;
try {
un = jaxbContextFor(dtoClass).createUnmarshaller();
- return (T)un.unmarshal(reader);
+ return _Casts.uncheckedCast( un.unmarshal(reader) );
} catch (JAXBException e) {
throw new RuntimeException(e);
}
@@ -87,8 +86,7 @@ class JaxbUtil2 {
final String resourceName,
final Charset charset,
final Class<T> dtoClass) throws IOException {
- final URL url = Resources.getResource(contextClass, resourceName);
- final String s = Resources.toString(url, charset);
+ final String s = _Resource.loadAsString(contextClass, resourceName, charset);
return fromXml(new StringReader(s), dtoClass);
}
@@ -110,7 +108,7 @@ class JaxbUtil2 {
}
}
- private static Map<Class<?>, JAXBContext> jaxbContextByClass = new MapMaker().concurrencyLevel(10).makeMap();
+ private static Map<Class<?>, JAXBContext> jaxbContextByClass = new ConcurrentHashMap<>();
public static <T> JAXBContext jaxbContextFor(final Class<T> dtoClass) {
JAXBContext jaxbContext = jaxbContextByClass.get(dtoClass);
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/IsisActions.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/IsisActions.java
index 26cec06..6d4c5a3 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/IsisActions.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/IsisActions.java
@@ -31,7 +31,8 @@ public final class IsisActions {
return InjectIntoJMockAction.injectInto();
}
- public static <T> Action returnEach(final T... values) {
+ @SafeVarargs
+ public static <T> Action returnEach(final T... values) {
return JMockActions.returnEach(values);
}
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JMockActions.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JMockActions.java
index 43795d4..d1ea07a 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JMockActions.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JMockActions.java
@@ -31,7 +31,8 @@ public final class JMockActions {
private JMockActions() {
}
- public static <T> Action returnEach(final T... values) {
+ @SafeVarargs
+ public static <T> Action returnEach(final T... values) {
return new ReturnEachAction<T>(values);
}
@@ -49,7 +50,8 @@ public final class JMockActions {
this.iterator = collection.iterator();
}
- private ReturnEachAction(T... array) {
+ @SafeVarargs
+ private ReturnEachAction(T... array) {
this(Arrays.asList(array));
}
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JUnitRuleMockery2.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JUnitRuleMockery2.java
index 18db4cf..8a3f7f8 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JUnitRuleMockery2.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JUnitRuleMockery2.java
@@ -25,6 +25,8 @@ import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.List;
+
+import org.apache.isis.commons.internal.base._Casts;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
import org.jmock.integration.junit4.JUnit4Mockery;
@@ -206,7 +208,7 @@ public class JUnitRuleMockery2 extends JUnit4Mockery implements MethodRule {
if(cutType == null) {
throw new IllegalStateException("No field annotated @ClassUnderTest was found");
}
- return (T) container.getComponent(cutType);
+ return _Casts.uncheckedCast( container.getComponent(cutType) );
}
@@ -283,7 +285,7 @@ public class JUnitRuleMockery2 extends JUnit4Mockery implements MethodRule {
public static class ExpectationsOn<T> extends Expectations {
public ExpectationsOn(Object mock) {
- this.mockObj = (T) mock;
+ this.mockObj = _Casts.uncheckedCast( mock );
}
private T mockObj;
public T mock() {
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/MyMockomatic.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/MyMockomatic.java
index 3c200c3..ad2234a 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/MyMockomatic.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/MyMockomatic.java
@@ -31,17 +31,16 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
-import org.jmock.Sequence;
-import org.jmock.States;
-import org.jmock.auto.Auto;
-import org.jmock.auto.Mock;
-
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Allowing;
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Checking;
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.ExpectationsOn;
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Ignoring;
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Never;
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.One;
+import org.jmock.Sequence;
+import org.jmock.States;
+import org.jmock.auto.Auto;
+import org.jmock.auto.Mock;
class MyMockomatic {
private final JUnitRuleMockery2 context;
@@ -76,7 +75,7 @@ class MyMockomatic {
context.never(mock);
}
if(field.isAnnotationPresent(One.class)) {
- context.one(mock);
+ context.oneOf(mock);
}
if(field.isAnnotationPresent(Checking.class)) {
checking(field, mock);
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/PublishedEndpoints.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/PublishedEndpoints.java
index 6603f12..647a91f 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/PublishedEndpoints.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/PublishedEndpoints.java
@@ -19,7 +19,8 @@ package org.apache.isis.core.unittestsupport.soap;
import java.util.List;
import java.util.Map;
-import com.google.common.collect.Maps;
+import org.apache.isis.commons.internal.base._Casts;
+import org.apache.isis.commons.internal.collections._Maps;
/**
* Collection of SOAP endpoints that have been published; will automatically assign a unique address to any
@@ -28,7 +29,7 @@ import com.google.common.collect.Maps;
class PublishedEndpoints {
private int port = SoapEndpointPublishingRule.INITIAL_PORT;
- private Map<Class<?>, SoapEndpoint> soapEndpointByType = Maps.newLinkedHashMap();
+ private Map<Class<?>, SoapEndpoint> soapEndpointByType = _Maps.newLinkedHashMap();
void publishEndpointIfRequired(final List<SoapEndpointSpec> soapEndpointSpecs) {
// merge in any new endpoints to static cache
@@ -49,6 +50,6 @@ class PublishedEndpoints {
}
<T> T getEndpointImplementor(Class<T> endpointClass) {
- return (T) soapEndpointByType.get(endpointClass).getImplementor();
+ return _Casts.uncheckedCast( soapEndpointByType.get(endpointClass).getImplementor() );
}
}
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointPublishingRule.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointPublishingRule.java
index 71fd61b..e1400af 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointPublishingRule.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointPublishingRule.java
@@ -16,11 +16,11 @@
*/
package org.apache.isis.core.unittestsupport.soap;
-import java.util.Arrays;
-import java.util.List;
+import static org.apache.isis.commons.internal.base._NullSafe.stream;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
@@ -39,26 +39,32 @@ public class SoapEndpointPublishingRule implements TestRule {
private static PublishedEndpoints publishedEndpoints = new PublishedEndpoints();
- private final List<SoapEndpointSpec> soapEndpointSpecs = Lists.newArrayList();
+ private final List<SoapEndpointSpec> soapEndpointSpecs;
public SoapEndpointPublishingRule(final Class<?> endpointClass, final String endpointAddress) {
this(new SoapEndpointSpec(endpointClass, endpointAddress));
}
public SoapEndpointPublishingRule(Class<?>... endpointClasses) {
- this(Arrays.asList(endpointClasses));
+ this.soapEndpointSpecs = stream(endpointClasses)
+ .map(SoapEndpointSpec::asSoapEndpointSpec)
+ .collect(Collectors.toCollection(ArrayList::new));
}
public SoapEndpointPublishingRule(final List<Class<?>> endpointClasses) {
- this(Iterables.transform(endpointClasses, SoapEndpointSpec.asSoapEndpointSpec()));
+ this.soapEndpointSpecs = stream(endpointClasses)
+ .map(SoapEndpointSpec::asSoapEndpointSpec)
+ .collect(Collectors.toCollection(ArrayList::new));
}
public SoapEndpointPublishingRule(SoapEndpointSpec... soapEndpointSpecs) {
- this(Arrays.asList(soapEndpointSpecs));
+ this.soapEndpointSpecs = stream(soapEndpointSpecs)
+ .collect(Collectors.toCollection(ArrayList::new));
}
public SoapEndpointPublishingRule(final Iterable<SoapEndpointSpec> soapEndpointSpecs) {
- Iterables.addAll(this.soapEndpointSpecs, soapEndpointSpecs);
+ this.soapEndpointSpecs = stream(soapEndpointSpecs)
+ .collect(Collectors.toCollection(ArrayList::new));
}
@Override
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointSpec.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointSpec.java
index e83439a..b6a5b6f 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointSpec.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/soap/SoapEndpointSpec.java
@@ -16,20 +16,12 @@
*/
package org.apache.isis.core.unittestsupport.soap;
-import javax.annotation.Nullable;
-
-import com.google.common.base.Function;
-import com.google.common.base.Supplier;
+import java.util.function.Supplier;
public class SoapEndpointSpec {
- static Function<Class<?>, SoapEndpointSpec> asSoapEndpointSpec() {
- return new Function<Class<?>, SoapEndpointSpec>() {
- @Nullable @Override
- public SoapEndpointSpec apply(final Class<?> input) {
- return new SoapEndpointSpec(input);
- }
- };
+ static SoapEndpointSpec asSoapEndpointSpec(final Class<?> input) {
+ return new SoapEndpointSpec(input);
}
public SoapEndpointSpec(final Class<?> endpointClass) {
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAbstract.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAbstract.java
index f7f00c5..5174dd9 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAbstract.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAbstract.java
@@ -16,6 +16,8 @@
*/
package org.apache.isis.core.unittestsupport.sortedsets;
+import static org.apache.isis.commons.internal.collections._Collections.toHashSet;
+import static org.apache.isis.commons.internal.reflection._Reflect.withTypeAssignableTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -24,9 +26,7 @@ import java.util.Collection;
import java.util.Set;
import java.util.SortedSet;
-import org.reflections.ReflectionUtils;
-import org.reflections.Reflections;
-
+import org.apache.isis.commons.internal.reflection._Reflect;
import org.apache.isis.core.unittestsupport.AbstractApplyToAllContractTest;
public abstract class SortedSetsContractTestAbstract extends AbstractApplyToAllContractTest {
@@ -38,7 +38,10 @@ public abstract class SortedSetsContractTestAbstract extends AbstractApplyToAllC
@Override
protected void applyContractTest(Class<?> entityType) {
- final Set<Field> collectionFields = ReflectionUtils.getAllFields(entityType, ReflectionUtils.withTypeAssignableTo(Collection.class));
+ final Set<Field> collectionFields = _Reflect.streamAllFields(entityType)
+ .filter(withTypeAssignableTo(Collection.class))
+ .collect(toHashSet());
+
for (Field collectionField : collectionFields) {
try {
final String desc = desc(entityType, collectionField);
@@ -54,7 +57,7 @@ public abstract class SortedSetsContractTestAbstract extends AbstractApplyToAllC
private void process(Class<?> entityType, Field collectionField) {
assertThat(
desc(entityType, collectionField) + " must be a SortedSet",
- ReflectionUtils.withTypeAssignableTo(SortedSet.class).apply(collectionField), is(true));
+ _Reflect.withTypeAssignableTo(SortedSet.class).test(collectionField), is(true));
}
private String desc(Class<?> entityType, Field collectionField) {
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/CollectUtils.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/CollectUtils.java
index 88215ef..8cc7bd9 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/CollectUtils.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/CollectUtils.java
@@ -16,7 +16,6 @@
*/
package org.apache.isis.core.unittestsupport.utils;
-import java.lang.reflect.Field;
import java.util.Set;
public class CollectUtils {
@@ -25,5 +24,4 @@ public class CollectUtils {
return set.iterator().next();
}
-
}
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/ReflectUtils.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/ReflectUtils.java
index d4b0041..ea8ecb9 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/ReflectUtils.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/ReflectUtils.java
@@ -18,64 +18,50 @@ package org.apache.isis.core.unittestsupport.utils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.function.Predicate;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
-import com.google.common.base.Predicate;
-import com.google.common.base.Strings;
+import org.apache.isis.commons.internal.base._Strings;
public class ReflectUtils {
public static <T> Predicate<Field> withTypeAssignableFrom(final Class<T> type) {
- return new Predicate<Field>() {
- public boolean apply(Field input) {
- return input != null && input.getType().isAssignableFrom(type);
- }
- };
+ return (Field input)-> input != null && input.getType().isAssignableFrom(type);
}
public static <T> Predicate<Method> withReturnTypeAssignableFrom(final Class<T> type) {
- return new Predicate<Method>() {
- public boolean apply(Method input) {
- return input != null && input.getReturnType().isAssignableFrom(type);
- }
- };
+ return (Method input) -> input != null && input.getReturnType().isAssignableFrom(type);
}
public static Predicate<Method> withParametersAssignableFrom(final Class<?>... types) {
- return new Predicate<Method>() {
- public boolean apply(Method input) {
- if (input != null) {
- Class<?>[] parameterTypes = input.getParameterTypes();
- if (parameterTypes.length == types.length) {
- for (int i = 0; i < parameterTypes.length; i++) {
- if (!parameterTypes[i].isAssignableFrom(types[i])) {
- return false;
- }
+ return (Method input) -> {
+ if (input != null) {
+ Class<?>[] parameterTypes = input.getParameterTypes();
+ if (parameterTypes.length == types.length) {
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (!parameterTypes[i].isAssignableFrom(types[i])) {
+ return false;
}
- return true;
}
+ return true;
}
- return false;
}
+ return false;
};
}
- public static final Predicate<? super Field> persistentMappedBy = new Predicate<Field>() {
- public boolean apply(Field f) {
+ public static final Predicate<? super Field> persistentMappedBy =
+ (Field f) -> {
final Persistent annotation = f.getAnnotation(Persistent.class);
- return annotation!=null && !Strings.isNullOrEmpty(annotation.mappedBy());
- }
- };
+ return annotation!=null && !_Strings.isNullOrEmpty(annotation.mappedBy());
+ };
public static Predicate<? super Method> withEntityParameter() {
- return new Predicate<Method>() {
- public boolean apply(Method m) {
+ return (Method m) -> {
final Class<?> parameterType = m.getParameterTypes()[0];
- return parameterType.isAnnotationPresent(PersistenceCapable.class);
- }
- };
+ return parameterType.isAnnotationPresent(PersistenceCapable.class); };
}
}
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.