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 2020/01/29 19:38:32 UTC
[isis] 03/25: ISIS-2273: fixes compile issues for applib, I hope
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2062
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 62c04433314374edf98fdb6b98231497ec6903eb
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jan 29 16:56:16 2020 +0000
ISIS-2273: fixes compile issues for applib, I hope
---
api/applib/pom.xml | 23 ++++
.../services/i18n/TranslatableStringTest.java | 4 +-
.../ValueTypeContractTestAbstract.java | 132 +++++++++++++++++++++
.../applib/util/ObjectContractsTest_compareTo.java | 3 +-
.../ObjectContractsTest_equals_and_hashCode.java | 2 +-
.../applib/util/schema/CommonDtoUtils_Test.java | 4 +-
.../schema/CommonDtoUtils_setValueOn_Test.java | 4 +-
7 files changed, 164 insertions(+), 8 deletions(-)
diff --git a/api/applib/pom.xml b/api/applib/pom.xml
index 79d46a7..27c0b2b 100644
--- a/api/applib/pom.xml
+++ b/api/applib/pom.xml
@@ -109,6 +109,29 @@
</dependency>
<dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-junit4</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>net.bytebuddy</groupId>
+ <artifactId>byte-buddy</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+
+ <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
diff --git a/api/applib/src/test/java/org/apache/isis/applib/services/i18n/TranslatableStringTest.java b/api/applib/src/test/java/org/apache/isis/applib/services/i18n/TranslatableStringTest.java
index 0f6defe..53c33cd 100644
--- a/api/applib/src/test/java/org/apache/isis/applib/services/i18n/TranslatableStringTest.java
+++ b/api/applib/src/test/java/org/apache/isis/applib/services/i18n/TranslatableStringTest.java
@@ -20,13 +20,13 @@ package org.apache.isis.applib.services.i18n;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
+import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Rule;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
public class TranslatableStringTest {
@@ -79,7 +79,7 @@ public class TranslatableStringTest {
public static class Translate extends TranslatableStringTest {
@Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES);
+ public final JUnitRuleMockery context = new JUnitRuleMockery();
@Mock
private TranslationService mockTranslationService;
diff --git a/api/applib/src/test/java/org/apache/isis/applib/unittestsupport/ValueTypeContractTestAbstract.java b/api/applib/src/test/java/org/apache/isis/applib/unittestsupport/ValueTypeContractTestAbstract.java
new file mode 100644
index 0000000..6ae88b7
--- /dev/null
+++ b/api/applib/src/test/java/org/apache/isis/applib/unittestsupport/ValueTypeContractTestAbstract.java
@@ -0,0 +1,132 @@
+/*
+ * 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.applib.unittestsupport;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+/**
+ * Contract test for value types ({@link #equals(Object) equals} and
+ * {@link #hashCode() hashCode}), and also {@link Comparable#compareTo(Object) compareTo} for
+ * any value types that also are {@link Comparable}
+ *
+ * <p>
+ * Used by core and domain apps only.
+ * </p>
+ */
+public abstract class ValueTypeContractTestAbstract<T> {
+
+ @Before
+ public void setUp() throws Exception {
+ assertSizeAtLeast(getObjectsWithSameValue(), 2);
+ assertSizeAtLeast(getObjectsWithDifferentValue(), 1);
+ }
+
+ private void assertSizeAtLeast(final List<T> objects, final int i) {
+ assertThat(objects, is(notNullValue()));
+ assertThat(objects.size(), is(greaterThan(i - 1)));
+ }
+
+ @Test
+ public void notEqualToNull() throws Exception {
+ for (final T o1 : getObjectsWithSameValue()) {
+ assertThat(o1.equals(null), is(false));
+ }
+ for (final T o1 : getObjectsWithDifferentValue()) {
+ assertThat(o1.equals(null), is(false));
+ }
+ }
+
+ @Test
+ public void reflexiveAndSymmetric() throws Exception {
+ for (final T o1 : getObjectsWithSameValue()) {
+ for (final T o2 : getObjectsWithSameValue()) {
+ assertThat(o1.equals(o2), is(true));
+ assertThat(o2.equals(o1), is(true));
+ assertThat(o1.hashCode(), is(equalTo(o2.hashCode())));
+ }
+ }
+ }
+
+ @Test
+ public void notEqual() throws Exception {
+ for (final T o1 : getObjectsWithSameValue()) {
+ for (final T o2 : getObjectsWithDifferentValue()) {
+ assertThat(o1.equals(o2), is(false));
+ assertThat(o2.equals(o1), is(false));
+ }
+ }
+ }
+
+ @Test
+ public void transitiveWhenEqual() throws Exception {
+ for (final T o1 : getObjectsWithSameValue()) {
+ for (final T o2 : getObjectsWithSameValue()) {
+ for (final Object o3 : getObjectsWithSameValue()) {
+ assertThat(o1.equals(o2), is(true));
+ assertThat(o2.equals(o3), is(true));
+ assertThat(o1.equals(o3), is(true));
+ }
+ }
+ }
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void comparableEquivalence() throws Exception {
+ for (final T o1 : getObjectsWithSameValue()) {
+ assumeThat(o1 instanceof Comparable, is(true));
+ Comparable c1 = (Comparable)o1;
+
+ for (final T o2 : getObjectsWithSameValue()) {
+ assumeThat(o2 instanceof Comparable, is(true));
+ Comparable c2 = (Comparable)o2;
+
+ assertThat(c1.compareTo(c2), is(0));
+ assertThat(c2.compareTo(c1), is(0));
+ }
+
+ for (final T o2 : getObjectsWithDifferentValue()) {
+ assumeThat(o2 instanceof Comparable, is(true));
+ Comparable c2 = (Comparable)o2;
+
+ final int x = c1.compareTo(c2);
+ final int y = c2.compareTo(c1);
+ assertThat(x, is(not(0)));
+
+ assertThat(x, is(-y));
+ }
+ }
+ }
+
+ protected abstract List<T> getObjectsWithSameValue();
+
+ protected abstract List<T> getObjectsWithDifferentValue();
+
+}
diff --git a/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_compareTo.java b/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_compareTo.java
index dc545f2..34bef57 100644
--- a/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_compareTo.java
+++ b/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_compareTo.java
@@ -20,7 +20,8 @@ import java.util.List;
import org.junit.Before;
-import org.apache.isis.core.unittestsupport.comparable.ComparableContractTest_compareTo;
+import org.apache.isis.applib.unittestsupport.ComparableContractTest_compareTo;
+
public class ObjectContractsTest_compareTo extends ComparableContractTest_compareTo<InvoiceItem> {
diff --git a/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java b/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java
index 3b2d109..84b915b 100644
--- a/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java
+++ b/api/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java
@@ -20,8 +20,8 @@ import java.util.List;
import org.junit.Before;
+import org.apache.isis.applib.unittestsupport.ValueTypeContractTestAbstract;
import org.apache.isis.core.commons.internal.collections._Lists;
-import org.apache.isis.core.unittestsupport.value.ValueTypeContractTestAbstract;
public class ObjectContractsTest_equals_and_hashCode extends ValueTypeContractTestAbstract<InvoiceItem3> {
diff --git a/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_Test.java b/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_Test.java
index dd99621..e7791fd 100644
--- a/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_Test.java
+++ b/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_Test.java
@@ -19,6 +19,7 @@
package org.apache.isis.applib.util.schema;
import org.jmock.auto.Mock;
+import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
@@ -29,7 +30,6 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import org.apache.isis.applib.services.bookmark.BookmarkService;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
import org.apache.isis.schema.cmd.v2.MapDto;
import org.apache.isis.schema.common.v2.ValueDto;
import org.apache.isis.schema.common.v2.ValueType;
@@ -37,7 +37,7 @@ import org.apache.isis.schema.common.v2.ValueType;
public class CommonDtoUtils_Test {
@Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES);
+ public JUnitRuleMockery context = new JUnitRuleMockery();
@Mock
private BookmarkService mockBookmarkService;
diff --git a/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_setValueOn_Test.java b/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_setValueOn_Test.java
index 50184ea..d4968ff 100644
--- a/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_setValueOn_Test.java
+++ b/api/applib/src/test/java/org/apache/isis/applib/util/schema/CommonDtoUtils_setValueOn_Test.java
@@ -19,6 +19,7 @@
package org.apache.isis.applib.util.schema;
import org.jmock.auto.Mock;
+import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -31,7 +32,6 @@ import static org.hamcrest.CoreMatchers.nullValue;
import org.apache.isis.applib.services.bookmark.BookmarkService;
import org.apache.isis.applib.value.Blob;
import org.apache.isis.applib.value.Clob;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
import org.apache.isis.schema.common.v2.BlobDto;
import org.apache.isis.schema.common.v2.ClobDto;
import org.apache.isis.schema.common.v2.ValueDto;
@@ -40,7 +40,7 @@ import org.apache.isis.schema.common.v2.ValueType;
public class CommonDtoUtils_setValueOn_Test {
@Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES);
+ public JUnitRuleMockery context = new JUnitRuleMockery();
@Mock
private BookmarkService mockBookmarkService;