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/09/17 19:10:26 UTC
[isis] 01/02: ISIS-1976: fixing tests,
also remove some unused test code
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 60cc330da3b1dfd7cbc5ba0cd94f5572fcfd37c8
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Sep 17 19:46:02 2018 +0200
ISIS-1976: fixing tests, also remove some unused test code
Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
.../core/commons/lang/ListUtilsTest_adjust.java | 10 +-
.../core/commons/lang/ListUtilsTest_insert.java | 8 +-
.../collections/JavaCollectionFacetTest.java | 16 +-
.../runtime/services/ServicesInstallerUtils.java | 7 +-
.../runtime/services/DeweyOrderComparatorTest.java | 116 --------------
.../isis/core/runtime/services/DeweyOrderUtil.java | 168 ---------------------
.../core/runtime/services/DeweyOrderUtilTest.java | 113 --------------
.../runtime/services/ServiceInstantiatorTest.java | 9 +-
8 files changed, 20 insertions(+), 427 deletions(-)
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java
index 5b6e05a..49ff2b6 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java
@@ -20,18 +20,18 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.junit.Test;
-import org.apache.isis.commons.internal.collections._Lists;
-
public class ListUtilsTest_adjust {
@Test
public void sameLength() throws Exception {
- final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+ final List<Integer> list = Arrays.asList(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
ListExtensions.adjust(list, 3);
assertThat(list.size(), is(3));
@@ -42,7 +42,7 @@ public class ListUtilsTest_adjust {
@Test
public void ifLonger() throws Exception {
- final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+ final List<Integer> list = new ArrayList<>(Arrays.asList(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
ListExtensions.adjust(list, 4);
assertThat(list.size(), is(4));
@@ -54,7 +54,7 @@ public class ListUtilsTest_adjust {
@Test
public void ifShorter() throws Exception {
- final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+ final List<Integer> list = new ArrayList<>(Arrays.asList(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
ListExtensions.adjust(list, 2);
assertThat(list.size(), is(2));
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java
index a1d899f..f37703e 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java
@@ -30,7 +30,7 @@ public class ListUtilsTest_insert {
@Test
public void insert_whenInsertionPointAtBeginning() throws Exception {
- final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+ final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
ListExtensions.insert(list, 0, Integer.valueOf(10));
assertThat(list.size(), is(4));
@@ -42,7 +42,7 @@ public class ListUtilsTest_insert {
@Test
public void insert_whenInsertionPointInMiddle() throws Exception {
- final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+ final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
ListExtensions.insert(list, 1, Integer.valueOf(10));
assertThat(list.size(), is(4));
@@ -54,7 +54,7 @@ public class ListUtilsTest_insert {
@Test
public void insert_whenInsertionPointAtEnd() throws Exception {
- final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+ final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
ListExtensions.insert(list, 3, Integer.valueOf(10));
assertThat(list.size(), is(4));
@@ -66,7 +66,7 @@ public class ListUtilsTest_insert {
@Test
public void insert_whenInsertionPointBeyondEnd() throws Exception {
- final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+ final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
ListExtensions.insert(list, 4, Integer.valueOf(10));
assertThat(list.size(), is(5));
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java
index 2eceedc..9300746 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java
@@ -24,7 +24,7 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import java.util.Collection;
-import java.util.Iterator;
+import java.util.stream.Stream;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
@@ -54,15 +54,13 @@ public class JavaCollectionFacetTest {
@Mock
private Collection<ObjectAdapter> mockWrappedCollection;
@Mock
- private Iterator<ObjectAdapter> mockIterator;
- @Mock
- private ObjectAdapterProvider mockAdapterManager;
+ private ObjectAdapterProvider mockOAProvider;
@Before
public void setUp() throws Exception {
- mockAdapterManager = context.mock(ObjectAdapterProvider.class);
+ mockOAProvider = context.mock(ObjectAdapterProvider.class);
- facet = new JavaCollectionFacet(mockFacetHolder, mockAdapterManager);
+ facet = new JavaCollectionFacet(mockFacetHolder, mockOAProvider);
}
@After
@@ -77,11 +75,9 @@ public class JavaCollectionFacetTest {
oneOf(mockCollection).getObject();
will(returnValue(mockWrappedCollection));
- oneOf(mockWrappedCollection).iterator();
- will(returnValue(mockIterator));
+ oneOf(mockWrappedCollection).stream();
+ will(returnValue(Stream.empty()));
- oneOf(mockIterator).hasNext();
- will(returnValue(false));
}
});
assertThat(facet.firstElement(mockCollection), is(nullValue()));
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java
index c347d07..574981b 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java
@@ -91,12 +91,7 @@ final class ServicesInstallerUtils {
}
private static Function<String, Object> instantiator(final ServiceInstantiator serviceInstantiator) {
- return new Function<String, Object>() {
- @Override
- public Object apply(String serviceName) {
- return instantiateService(serviceName, serviceInstantiator);
- }
- };
+ return (String serviceName) -> instantiateService(serviceName, serviceInstantiator);
}
}
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderComparatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderComparatorTest.java
deleted file mode 100644
index adf86e2..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderComparatorTest.java
+++ /dev/null
@@ -1,116 +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.runtime.services;
-
-import java.util.*;
-import com.google.common.collect.Iterators;
-import org.apache.isis.commons.internal.collections._Lists;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import org.apache.isis.core.metamodel.util.DeweyOrderComparator;
-
-import static org.hamcrest.CoreMatchers.is;
-
-public class DeweyOrderComparatorTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Test
- public void emptySet() throws Exception {
- assertThatSorting(
- ofS(),
- ofL());
- }
-
- @Test
- public void singleElement() throws Exception {
- assertThatSorting(
- ofS("1"),
- ofL("1")
- );
- }
-
- @Test
- public void inOrder() throws Exception {
- assertThatSorting(
- ofS("1", "2"),
- ofL("1", "2")
- );
- }
-
- @Test
- public void notInOrder() throws Exception {
- assertThatSorting(
- ofS("2", "1"),
- ofL("1", "2")
- );
- }
-
- @Test
- public void notInOrderDepth2() throws Exception {
- assertThatSorting(
- ofS("1.2", "1.1"),
- ofL("1.1", "1.2")
- );
- }
-
- @Test
- public void differentDepths() throws Exception {
- assertThatSorting(
- ofS("2", "1.3", "1.2", "1.2.2", "1.2.1", "1.1"),
- ofL("1.1", "1.2", "1.2.1", "1.2.2", "1.3", "2")
- );
- }
-
- @Test
- public void mismatchedDepth3() throws Exception {
- assertThatSorting(
- ofS("1.2.2", "1.2.1", "1.1"),
- ofL("1.1", "1.2.1", "1.2.2")
- );
- }
-
- @Test
- public void X() throws Exception {
- assertThatSorting(
- ofS("45.1", "10.10"),
- ofL("10.10", "45.1")
- );
- }
-
- private static Collection<String> ofS(String... str) {
- return Arrays.asList(str);
- }
-
- private static List<String> ofL(String... str) {
- return _Lists.newArrayList(ofS(str));
- }
-
- private static void assertThatSorting(Collection<String> input, List<String> expected) {
- final SortedSet<String> treeSet = new TreeSet<String>(new DeweyOrderComparator());
- treeSet.addAll(input);
- final List<String> strings = Arrays.asList(Iterators.toArray(treeSet.iterator(), String.class));
- Assert.assertThat(strings, is(expected));
- }
-
-}
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtil.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtil.java
deleted file mode 100644
index 092aab4..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtil.java
+++ /dev/null
@@ -1,168 +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.runtime.services;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
-import org.apache.isis.commons.internal.collections._Sets;
-
-class DeweyOrderUtil {
-
- public static final <V> Function<Parsed, Map.Entry<String, V>> toMapEntry() {
- return new Function<Parsed, Map.Entry<String, V>>() {
- @Override
- public Map.Entry<String, V> apply(Parsed input) {
- return input.toMapEntry();
- }
- };
- }
-
- private DeweyOrderUtil() {}
-
- static <V> List<Map.Entry<String, V>> deweySorted(Map<String, V> map) {
- Set<Map.Entry<String, V>> set = _Sets.newLinkedHashSet();
- for (Map.Entry<String, V> entry : map.entrySet()) {
- set.add(entry);
- }
- return deweySorted(set);
- }
-
- static <V> List<Map.Entry<String, V>> deweySorted(Set<Map.Entry<String, V>> keys) {
- if(keys == null) {
- throw new IllegalArgumentException("Keys cannot be null");
- }
- final Iterable<Parsed<V>> parsedIter = Iterables.transform(keys,
- new Function<Map.Entry<String,V>, Parsed<V>>() {
- @Override
- public Parsed<V> apply(Map.Entry<String,V> input) {
- return new Parsed(input);
- }
- });
-
- final SortedSet<Parsed<V>> parseds = _Sets.newTreeSet(parsedIter);
- final Iterable<Map.Entry<String, V>> transform = Iterables.transform(parseds, DeweyOrderUtil.<V>toMapEntry());
- return Lists.newArrayList(transform);
- }
-
-}
-
-
-class Parsed<V> implements Comparable<Parsed<V>> {
- private static final Function<String, Integer> PARSE = new Function<String, Integer>() {
- @Override
- public Integer apply(String input) {
- try {
- return Integer.parseInt(input);
- } catch (NumberFormatException e) {
- return Integer.MAX_VALUE;
- }
- }
- };
- private final List<Integer> parts;
- private final String key;
- private final V value;
- Parsed(Map.Entry<String, V> entry) {
- key = entry.getKey();
- value = entry.getValue();
- final Iterable<String> iter = Splitter.on(".").split(entry.getKey());
- parts = Lists.newArrayList(Iterators.transform(iter.iterator(),PARSE));
- }
-
- @Override
- public int compareTo(Parsed<V> other) {
- for (int i = 0; i < parts.size(); i++) {
- Integer p = parts.get(i);
- if (other.parts.size() < parts.size()) {
- // run out of parts for other, put it before us
- return -1;
- }
- final Integer q = other.parts.get(i);
- final int comparison = p.compareTo(q);
- if(comparison != 0) {
- return +comparison;
- }
- }
- if(other.parts.size() > parts.size()) {
- // run out of parts on our side, still more on others; put us before it
- return +1;
- }
- return 0;
- }
-
- public Map.Entry<String, V> toMapEntry() {
- return new MapEntry<String, V>(key, value){};
- }
-}
-
-class MapEntry<K, V> implements Map.Entry<K, V> {
-
- private K key;
- private V value;
-
- MapEntry(K key, V value) {
- this.key = key;
- this.value = value;
- }
-
- @Override
- public K getKey() {
- return key;
- }
-
- @Override
- public V getValue() {
- return value;
- }
-
- @Override
- public V setValue(V value) {
- throw new UnsupportedOperationException();
- }
-
- @Override public boolean equals(Object object) {
- if (object instanceof Map.Entry) {
- Map.Entry<?, ?> that = (Map.Entry<?, ?>) object;
- return Objects.equal(this.getKey(), that.getKey())
- && Objects.equal(this.getValue(), that.getValue());
- }
- return false;
- }
-
- @Override public int hashCode() {
- K k = getKey();
- V v = getValue();
- return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
- }
-
- /**
- * Returns a string representation of the form {@code {key}={value}}.
- */
- @Override public String toString() {
- return getKey() + "=" + getValue();
- }
-}
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtilTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtilTest.java
deleted file mode 100644
index 5183d96..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtilTest.java
+++ /dev/null
@@ -1,113 +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.runtime.services;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.isis.commons.internal.collections._Lists;
-import org.apache.isis.commons.internal.collections._Sets;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.hamcrest.CoreMatchers.is;
-
-public class DeweyOrderUtilTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Test
- public void emptySet() throws Exception {
- assertThatSorting(
- ofS(),
- ofL());
- }
-
- @Test
- public void singleElement() throws Exception {
- assertThatSorting(
- ofS(el("1", "aaa")),
- ofL(el("1", "aaa")));
- }
-
- @Test
- public void inOrder() throws Exception {
- assertThatSorting(
- ofS(el("1", "aaa"), el("2", "bbb")),
- ofL(el("1", "aaa"), el("2", "bbb")));
- }
-
- @Test
- public void notInOrder() throws Exception {
- assertThatSorting(
- ofS(el("2", "bbb"), el("1", "aaa")),
- ofL(el("1", "aaa"), el("2", "bbb")));
- }
-
- @Test
- public void notInOrderDepth2() throws Exception {
- assertThatSorting(
- ofS(el("1.2", "bbb"), el("1.1", "aaa")),
- ofL(el("1.1", "aaa"), el("1.2", "bbb")));
- }
-
- @Test
- public void differentDepths() throws Exception {
- assertThatSorting(
- ofS(el("2", "aaa"), el("1.3", "aaa"), el("1.2", "aaa"), el("1.2.2", "ccc"), el("1.2.1", "bbb"), el("1.1", "aaa")),
- ofL(el("1.1", "aaa"), el("1.2.1", "bbb"), el("1.2.2", "ccc"), el("1.2", "aaa"), el("1.3", "aaa"), el("2", "aaa")));
- }
-
- @Test
- public void mismatchedDepth3() throws Exception {
- assertThatSorting(
- ofS(el("1.2.2", "ccc"), el("1.2.1", "bbb"), el("1.1", "aaa")),
- ofL(el("1.1", "aaa"), el("1.2.1", "bbb"), el("1.2.2", "ccc")));
- }
-
- private void assertThatSorting(Set<Map.Entry<String, Object>> input, List<Map.Entry<String, Object>> expected) {
- final List<Map.Entry<String, Object>> list = DeweyOrderUtil.deweySorted(input);
- Assert.assertThat(list, is(expected));
- }
-
-
- private static Set<Map.Entry<String, Object>> ofS(String[]... str) {
- final Set<Map.Entry<String,Object>> seq = _Sets.newLinkedHashSet();
- for (String[] strings : str) {
- if(strings.length != 2) {
- throw new IllegalArgumentException("array must have 2 elements");
- }
- seq.add(new MapEntry<String, Object>(strings[0], (Object) strings[1]));
- }
- return seq;
- }
-
- private static List<Map.Entry<String, Object>> ofL(String[]... str) {
- return _Lists.newArrayList(ofS(str));
- }
-
-
- private static String[] el(String a, String b) {
- return new String[]{a, b};
- }
-
-}
\ No newline at end of file
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
index 4c53d0a..92ca5ec 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
@@ -32,7 +32,6 @@ import javax.enterprise.context.RequestScoped;
import org.jmock.auto.Mock;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -66,13 +65,13 @@ public class ServiceInstantiatorTest {
assertThat(calculator.add(3,4), is(7));
}
- @Test @Ignore("test is in core plugins codegen-*")
+ @Test
public void requestScoped_instantiate() {
AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
assertThat(calculator instanceof RequestScopedService, is(true));
}
- @Test @Ignore("test is in core plugins codegen-*")
+ @Test
public void requestScoped_justOneThread() {
AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
try {
@@ -85,7 +84,7 @@ public class ServiceInstantiatorTest {
}
}
- @Test @Ignore("test is in core plugins codegen-*")
+ @Test
public void requestScoped_multipleThreads() throws InterruptedException, BrokenBarrierException {
final AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
@@ -139,7 +138,7 @@ public class ServiceInstantiatorTest {
assertThat(totals[2], is(30));
}
- @Test @Ignore("test is in core plugins codegen-*")
+ @Test
public void requestScoped_childThreads() throws InterruptedException {
final Consumer consumer = serviceInstantiator.createInstance(Consumer.class);