You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/06/06 16:58:56 UTC
git commit: ISIS-425: factored out AbstractApplyToAllContractTest.
Updated Branches:
refs/heads/master 4488cea0a -> 395b4a47d
ISIS-425: factored out AbstractApplyToAllContractTest.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/395b4a47
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/395b4a47
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/395b4a47
Branch: refs/heads/master
Commit: 395b4a47d8257c4f2c167a079e030b099316eaa7
Parents: 4488cea
Author: Dan Haywood <da...@apache.org>
Authored: Thu Jun 6 15:58:41 2013 +0100
Committer: Dan Haywood <da...@apache.org>
Committed: Thu Jun 6 15:58:41 2013 +0100
----------------------------------------------------------------------
.../AbstractApplyToAllContractTest.java | 96 ++++++++
...irectionalRelationshipContractTestAbstract.java | 59 +----
.../core/unittestsupport/bidir/CollectUtils.java | 29 ---
.../core/unittestsupport/bidir/IndentPrinter.java | 177 ---------------
.../core/unittestsupport/bidir/ReflectUtils.java | 81 -------
.../core/unittestsupport/bidir/StringUtils.java | 37 ---
.../sortedsets/SortedSetsContractTestAbstract.java | 65 ++++++
.../core/unittestsupport/utils/CollectUtils.java | 29 +++
.../core/unittestsupport/utils/IndentPrinter.java | 177 +++++++++++++++
.../core/unittestsupport/utils/ReflectUtils.java | 81 +++++++
.../core/unittestsupport/utils/StringUtils.java | 37 +++
.../sortedsets/SomeDomainObject.java | 35 +++
.../sortedsets/SortedSetsContractTestAll.java | 11 +
13 files changed, 540 insertions(+), 374 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/AbstractApplyToAllContractTest.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..5e39edf
--- /dev/null
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/AbstractApplyToAllContractTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.core.unittestsupport;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.Comparator;
+import java.util.Set;
+
+import javax.jdo.annotations.PersistenceCapable;
+
+import com.google.common.collect.Sets;
+import com.google.common.io.ByteStreams;
+
+import org.junit.Test;
+import org.reflections.Reflections;
+
+import org.apache.isis.core.unittestsupport.utils.IndentPrinter;
+
+/**
+ * Provides some basic infrastructure to iterate over all entity types and
+ * apply some contract test.
+ */
+public abstract class AbstractApplyToAllContractTest {
+
+ protected final Reflections reflections;
+ protected IndentPrinter out;
+
+ protected AbstractApplyToAllContractTest(
+ final String packagePrefix) {
+ reflections = new Reflections(packagePrefix);
+ out = new IndentPrinter(new PrintWriter(ByteStreams.nullOutputStream()));
+ }
+
+ public AbstractApplyToAllContractTest withLoggingTo(Writer out) {
+ this.out = new IndentPrinter(out);
+ return this;
+ }
+
+ public AbstractApplyToAllContractTest withLoggingTo(PrintStream out) {
+ this.out = new IndentPrinter(new PrintWriter(out));
+ return this;
+ }
+
+ @Test
+ public void searchAndTest() throws Exception {
+
+ Set<Class<?>> entityTypes =
+ Sets.newTreeSet(new Comparator<Class<?>>() {
+ @Override
+ public int compare(Class<?> o1, Class<?> o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ entityTypes.addAll(findTypes());
+
+ for (Class<?> entityType : entityTypes) {
+ out.println(entityType.getName());
+ out.incrementIndent();
+ try {
+ applyContractTest(entityType);
+ } finally {
+ out.decrementIndent();
+ }
+ }
+ out.println("DONE");
+ }
+
+ /**
+ * By default, finds all entity types (ie annotated with {@link PersistenceCapable}).
+ *
+ * <p>
+ * Can be overridden if need be.
+ */
+ protected Set<Class<?>> findTypes() {
+ return reflections.getTypesAnnotatedWith(PersistenceCapable.class);
+ }
+
+ protected abstract void applyContractTest(Class<?> entityType);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/BidirectionalRelationshipContractTestAbstract.java
----------------------------------------------------------------------
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 2d7d92c..7aefe56 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
@@ -20,79 +20,38 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
-import java.util.Comparator;
import java.util.Set;
-import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
-import com.google.common.io.ByteStreams;
import org.hamcrest.Matchers;
-import org.junit.Test;
import org.reflections.ReflectionUtils;
import org.reflections.Reflections;
-public abstract class BidirectionalRelationshipContractTestAbstract implements Instantiators {
+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;
+
+public abstract class BidirectionalRelationshipContractTestAbstract extends AbstractApplyToAllContractTest implements Instantiators {
- private final Reflections reflections;
private final InstantiatorMap instantiatorMap;
- private IndentPrinter out;
protected BidirectionalRelationshipContractTestAbstract(
final String packagePrefix,
ImmutableMap<Class<?>,Instantiator> instantiatorsByClass) {
- reflections = new Reflections(packagePrefix);
+ super(packagePrefix);
instantiatorMap = new InstantiatorMap(instantiatorsByClass);
- out = new IndentPrinter(new PrintWriter(ByteStreams.nullOutputStream()));
- }
-
- public Instantiators withLoggingTo(Writer out) {
- this.out = new IndentPrinter(out);
- return this;
- }
-
- public Instantiators withLoggingTo(PrintStream out) {
- this.out = new IndentPrinter(new PrintWriter(out));
- return this;
- }
-
- @Test
- public void searchAndTest() throws Exception {
-
- Set<Class<?>> entityTypes =
- Sets.newTreeSet(new Comparator<Class<?>>() {
-
- @Override
- public int compare(Class<?> o1, Class<?> o2) {
- return o1.getName().compareTo(o2.getName());
- }
- });
- entityTypes.addAll(reflections.getTypesAnnotatedWith(PersistenceCapable.class));
-
- for (Class<?> entityType : entityTypes) {
- out.println(entityType.getName());
- out.incrementIndent();
- try {
- process(entityType);
- } finally {
- out.decrementIndent();
- }
- }
- out.println("DONE");
- out.flush();
}
- private void process(Class<?> entityType) {
+ @Override
+ protected void applyContractTest(Class<?> entityType) {
final Set<Field> mappedByFields = Reflections.getAllFields(entityType, ReflectUtils.persistentMappedBy);
for (Field mappedByField : mappedByFields) {
final Parent p = new Parent();
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/CollectUtils.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/CollectUtils.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/CollectUtils.java
deleted file mode 100644
index d23003b..0000000
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/CollectUtils.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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.core.unittestsupport.bidir;
-
-import java.lang.reflect.Field;
-import java.util.Set;
-
-class CollectUtils {
-
- static <T> T firstIn(final Set<T> set) {
- return set.iterator().next();
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/IndentPrinter.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/IndentPrinter.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/IndentPrinter.java
deleted file mode 100644
index aa10637..0000000
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/IndentPrinter.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
- * 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.core.unittestsupport.bidir;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.Writer;
-
-/**
- * Adapted from <tt>groovy.util.IndentPrinter</tt> (published under ASL 2.0).
- */
-class IndentPrinter {
-
- private int indentLevel;
- private String indent;
- private Writer out;
- private final boolean addNewlines;
-
- /**
- * Creates an IndentPrinter backed by a PrintWriter pointing to System.out, with an indent of two spaces.
- *
- * @see #IndentPrinter(Writer, String)
- */
- public IndentPrinter() {
- this(new PrintWriter(System.out), " ");
- }
-
- /**
- * Creates an IndentPrinter backed by the supplied Writer, with an indent of two spaces.
- *
- * @param out Writer to output to
- * @see #IndentPrinter(Writer, String)
- */
- public IndentPrinter(Writer out) {
- this(out, " ");
- }
-
- /**
- * Creates an IndentPrinter backed by the supplied Writer,
- * with a user-supplied String to be used for indenting.
- *
- * @param out Writer to output to
- * @param indent character(s) used to indent each line
- */
- public IndentPrinter(Writer out, String indent) {
- this(out, indent, true);
- }
-
- /**
- * Creates an IndentPrinter backed by the supplied Writer,
- * with a user-supplied String to be used for indenting
- * and the ability to override newline handling.
- *
- * @param out Writer to output to
- * @param indent character(s) used to indent each line
- * @param addNewlines set to false to gobble all new lines (default true)
- */
- public IndentPrinter(Writer out, String indent, boolean addNewlines) {
- this.addNewlines = addNewlines;
- if (out == null) {
- throw new IllegalArgumentException("Must specify a Writer");
- }
- this.out = out;
- this.indent = indent;
- }
-
- /**
- * Prints a string followed by an end of line character.
- *
- * @param text String to be written
- */
- public void println(String text) {
- printIndent();
- try {
- out.write(text);
- println();
- flush();
- } catch(IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- /**
- * Prints a string.
- *
- * @param text String to be written
- */
- public void print(String text) {
- try {
- out.write(text);
- } catch(IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- /**
- * Prints a character.
- *
- * @param c char to be written
- */
- public void print(char c) {
- try {
- out.write(c);
- } catch(IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- /**
- * Prints the current indent level.
- */
- public void printIndent() {
- for (int i = 0; i < indentLevel; i++) {
- try {
- out.write(indent);
- } catch(IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
- }
-
- /**
- * Prints an end-of-line character (if enabled via addNewLines property).
- * Defaults to outputting a single '\n' character but by using a custom
- * Writer, e.g. PlatformLineWriter, you can get platform-specific
- * end-of-line characters.
- *
- * @see #IndentPrinter(Writer, String, boolean)
- */
- public void println() {
- if (addNewlines) {
- try {
- out.write("\n");
- } catch(IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
- }
-
- public void incrementIndent() {
- ++indentLevel;
- }
-
- public void decrementIndent() {
- --indentLevel;
- }
-
- public int getIndentLevel() {
- return indentLevel;
- }
-
- public void setIndentLevel(int indentLevel) {
- this.indentLevel = indentLevel;
- }
-
- public void flush() {
- try {
- out.flush();
- } catch(IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/ReflectUtils.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/ReflectUtils.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/ReflectUtils.java
deleted file mode 100644
index dff7615..0000000
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/ReflectUtils.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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.core.unittestsupport.bidir;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import javax.jdo.annotations.PersistenceCapable;
-import javax.jdo.annotations.Persistent;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Strings;
-
-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);
- }
- };
- }
-
- 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);
- }
- };
- }
-
- 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 true;
- }
- }
- return false;
- }
- };
- }
-
- static final Predicate<? super Field> persistentMappedBy = new Predicate<Field>() {
- public boolean apply(Field f) {
- final Persistent annotation = f.getAnnotation(Persistent.class);
- return annotation!=null && !Strings.isNullOrEmpty(annotation.mappedBy());
- }
- };
-
- static Predicate<? super Method> withEntityParameter() {
- return new Predicate<Method>() {
- public boolean apply(Method m) {
- final Class<?> parameterType = m.getParameterTypes()[0];
- return parameterType.isAnnotationPresent(PersistenceCapable.class);
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/StringUtils.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/StringUtils.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/StringUtils.java
deleted file mode 100644
index 23e9b4a..0000000
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/bidir/StringUtils.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.core.unittestsupport.bidir;
-
-import java.lang.reflect.Field;
-
-class StringUtils {
-
- public static String capitalize(final String str) {
- if (str == null || str.length() == 0) {
- return str;
- }
- if (str.length() == 1) {
- return str.toUpperCase();
- }
- return Character.toUpperCase(str.charAt(0)) + str.substring(1);
- }
-
- public static String methodNamed(final String methodPrefix, final Field field) {
- return methodPrefix + capitalize(field.getName());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAbstract.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..676e416
--- /dev/null
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAbstract.java
@@ -0,0 +1,65 @@
+/**
+ * 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.core.unittestsupport.sortedsets;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Set;
+import java.util.SortedSet;
+
+import org.reflections.ReflectionUtils;
+import org.reflections.Reflections;
+
+import org.apache.isis.core.unittestsupport.AbstractApplyToAllContractTest;
+
+public abstract class SortedSetsContractTestAbstract extends AbstractApplyToAllContractTest {
+
+ protected SortedSetsContractTestAbstract(
+ final String packagePrefix) {
+ super(packagePrefix);
+ }
+
+ @Override
+ protected void applyContractTest(Class<?> entityType) {
+ final Set<Field> collectionFields = Reflections.getAllFields(entityType, ReflectionUtils.withTypeAssignableTo(Collection.class));
+ for (Field collectionField : collectionFields) {
+ try {
+ final String desc = desc(entityType, collectionField);
+ out.println("processing " + desc);
+ out.incrementIndent();
+ process(entityType, collectionField);
+ } finally {
+ out.decrementIndent();
+ }
+ }
+ }
+
+ private void process(Class<?> entityType, Field collectionField) {
+ assertThat(
+ desc(entityType, collectionField) + " must be a SortedSet",
+ ReflectionUtils.withTypeAssignableTo(SortedSet.class).apply(collectionField), is(true));
+ }
+
+ private String desc(Class<?> entityType, Field collectionField) {
+ return entityType.getSimpleName() + "#" + collectionField.getName();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/CollectUtils.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..88215ef
--- /dev/null
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/CollectUtils.java
@@ -0,0 +1,29 @@
+/**
+ * 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.core.unittestsupport.utils;
+
+import java.lang.reflect.Field;
+import java.util.Set;
+
+public class CollectUtils {
+
+ public static <T> T firstIn(final Set<T> set) {
+ return set.iterator().next();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/IndentPrinter.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/IndentPrinter.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/IndentPrinter.java
new file mode 100644
index 0000000..384e797
--- /dev/null
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/IndentPrinter.java
@@ -0,0 +1,177 @@
+/**
+ * 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.core.unittestsupport.utils;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+/**
+ * Adapted from <tt>groovy.util.IndentPrinter</tt> (published under ASL 2.0).
+ */
+public class IndentPrinter {
+
+ private int indentLevel;
+ private String indent;
+ private Writer out;
+ private final boolean addNewlines;
+
+ /**
+ * Creates an IndentPrinter backed by a PrintWriter pointing to System.out, with an indent of two spaces.
+ *
+ * @see #IndentPrinter(Writer, String)
+ */
+ public IndentPrinter() {
+ this(new PrintWriter(System.out), " ");
+ }
+
+ /**
+ * Creates an IndentPrinter backed by the supplied Writer, with an indent of two spaces.
+ *
+ * @param out Writer to output to
+ * @see #IndentPrinter(Writer, String)
+ */
+ public IndentPrinter(Writer out) {
+ this(out, " ");
+ }
+
+ /**
+ * Creates an IndentPrinter backed by the supplied Writer,
+ * with a user-supplied String to be used for indenting.
+ *
+ * @param out Writer to output to
+ * @param indent character(s) used to indent each line
+ */
+ public IndentPrinter(Writer out, String indent) {
+ this(out, indent, true);
+ }
+
+ /**
+ * Creates an IndentPrinter backed by the supplied Writer,
+ * with a user-supplied String to be used for indenting
+ * and the ability to override newline handling.
+ *
+ * @param out Writer to output to
+ * @param indent character(s) used to indent each line
+ * @param addNewlines set to false to gobble all new lines (default true)
+ */
+ public IndentPrinter(Writer out, String indent, boolean addNewlines) {
+ this.addNewlines = addNewlines;
+ if (out == null) {
+ throw new IllegalArgumentException("Must specify a Writer");
+ }
+ this.out = out;
+ this.indent = indent;
+ }
+
+ /**
+ * Prints a string followed by an end of line character.
+ *
+ * @param text String to be written
+ */
+ public void println(String text) {
+ printIndent();
+ try {
+ out.write(text);
+ println();
+ flush();
+ } catch(IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+
+ /**
+ * Prints a string.
+ *
+ * @param text String to be written
+ */
+ public void print(String text) {
+ try {
+ out.write(text);
+ } catch(IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+
+ /**
+ * Prints a character.
+ *
+ * @param c char to be written
+ */
+ public void print(char c) {
+ try {
+ out.write(c);
+ } catch(IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+
+ /**
+ * Prints the current indent level.
+ */
+ public void printIndent() {
+ for (int i = 0; i < indentLevel; i++) {
+ try {
+ out.write(indent);
+ } catch(IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+ }
+
+ /**
+ * Prints an end-of-line character (if enabled via addNewLines property).
+ * Defaults to outputting a single '\n' character but by using a custom
+ * Writer, e.g. PlatformLineWriter, you can get platform-specific
+ * end-of-line characters.
+ *
+ * @see #IndentPrinter(Writer, String, boolean)
+ */
+ public void println() {
+ if (addNewlines) {
+ try {
+ out.write("\n");
+ } catch(IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+ }
+
+ public void incrementIndent() {
+ ++indentLevel;
+ }
+
+ public void decrementIndent() {
+ --indentLevel;
+ }
+
+ public int getIndentLevel() {
+ return indentLevel;
+ }
+
+ public void setIndentLevel(int indentLevel) {
+ this.indentLevel = indentLevel;
+ }
+
+ public void flush() {
+ try {
+ out.flush();
+ } catch(IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/ReflectUtils.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..d4b0041
--- /dev/null
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/ReflectUtils.java
@@ -0,0 +1,81 @@
+/**
+ * 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.core.unittestsupport.utils;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.jdo.annotations.PersistenceCapable;
+import javax.jdo.annotations.Persistent;
+
+import com.google.common.base.Predicate;
+import com.google.common.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);
+ }
+ };
+ }
+
+ 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);
+ }
+ };
+ }
+
+ 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 true;
+ }
+ }
+ return false;
+ }
+ };
+ }
+
+ public static final Predicate<? super Field> persistentMappedBy = new Predicate<Field>() {
+ public boolean apply(Field f) {
+ final Persistent annotation = f.getAnnotation(Persistent.class);
+ return annotation!=null && !Strings.isNullOrEmpty(annotation.mappedBy());
+ }
+ };
+
+ public static Predicate<? super Method> withEntityParameter() {
+ return new Predicate<Method>() {
+ public boolean apply(Method m) {
+ final Class<?> parameterType = m.getParameterTypes()[0];
+ return parameterType.isAnnotationPresent(PersistenceCapable.class);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/StringUtils.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/StringUtils.java
new file mode 100644
index 0000000..d0046c9
--- /dev/null
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/utils/StringUtils.java
@@ -0,0 +1,37 @@
+/**
+ * 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.core.unittestsupport.utils;
+
+import java.lang.reflect.Field;
+
+public class StringUtils {
+
+ public static String capitalize(final String str) {
+ if (str == null || str.length() == 0) {
+ return str;
+ }
+ if (str.length() == 1) {
+ return str.toUpperCase();
+ }
+ return Character.toUpperCase(str.charAt(0)) + str.substring(1);
+ }
+
+ public static String methodNamed(final String methodPrefix, final Field field) {
+ return methodPrefix + capitalize(field.getName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SomeDomainObject.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SomeDomainObject.java b/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SomeDomainObject.java
new file mode 100644
index 0000000..08396b2
--- /dev/null
+++ b/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SomeDomainObject.java
@@ -0,0 +1,35 @@
+/**
+ * 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.core.unittestsupport.sortedsets;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.jdo.annotations.PersistenceCapable;
+
+@PersistenceCapable
+public class SomeDomainObject {
+
+
+ private SortedSet<SomeDomainObject> someSortedSet = new TreeSet<SomeDomainObject>();
+
+ //private Set<SomeDomainObject> someSet = new HashSet<SomeDomainObject>();
+
+ //private List<SomeDomainObject> someList = new ArrayList<SomeDomainObject>();
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/395b4a47/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAll.java
----------------------------------------------------------------------
diff --git a/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAll.java b/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAll.java
new file mode 100644
index 0000000..6c47505
--- /dev/null
+++ b/core/unittestsupport/src/test/java/org/apache/isis/core/unittestsupport/sortedsets/SortedSetsContractTestAll.java
@@ -0,0 +1,11 @@
+package org.apache.isis.core.unittestsupport.sortedsets;
+
+
+public class SortedSetsContractTestAll extends SortedSetsContractTestAbstract {
+
+ public SortedSetsContractTestAll() {
+ super("org.apache.isis.core.unittestsupport.sortedsets");
+ withLoggingTo(System.out);
+ }
+
+}