You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2015/11/07 06:16:28 UTC

zest-java git commit: Adding test for Type finder predicate (matchAny)

Repository: zest-java
Updated Branches:
  refs/heads/develop 688d9adc3 -> 1c16db222


Adding test for Type finder predicate (matchAny)


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/1c16db22
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/1c16db22
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/1c16db22

Branch: refs/heads/develop
Commit: 1c16db2229e14d4f191d2a0490929ce47b6fe3a0
Parents: 688d9ad
Author: Niclas Hedhman <ni...@hedhman.org>
Authored: Sat Nov 7 13:16:20 2015 +0800
Committer: Niclas Hedhman <ni...@hedhman.org>
Committed: Sat Nov 7 13:16:20 2015 +0800

----------------------------------------------------------------------
 .../bootstrap/AssemblySpecificationTest.java    | 99 ++++++++++++++++++++
 1 file changed, 99 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c16db22/core/bootstrap/src/test/java/org/apache/zest/bootstrap/AssemblySpecificationTest.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/AssemblySpecificationTest.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/AssemblySpecificationTest.java
new file mode 100644
index 0000000..5173ba3
--- /dev/null
+++ b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/AssemblySpecificationTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.zest.bootstrap;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import org.apache.zest.api.type.HasTypes;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class AssemblySpecificationTest
+{
+    @Test
+    public void givenSingleMatchingTypeWhenFilteringExpectTrue()
+    {
+        Predicate<HasTypes> underTest = AssemblySpecifications.ofAnyType( String.class );
+        HasTypes hasTypes = new MockedHasTyoes( String.class );
+        assertThat( underTest.test( hasTypes ), equalTo(true) );
+    }
+
+    @Test
+    public void givenMultipleMatchingTypeWhenFilteringExpectTrue()
+    {
+        Predicate<HasTypes> underTest = AssemblySpecifications.ofAnyType( Long.class, BigDecimal.class, String.class );
+        HasTypes hasTypes = new MockedHasTyoes( String.class );
+        assertThat( underTest.test( hasTypes ), equalTo(true) );
+    }
+
+    @Test
+    public void givenSingleNonMatchingTypeWhenFilteringExpectFalse()
+    {
+        Predicate<HasTypes> underTest = AssemblySpecifications.ofAnyType( Long.class );
+        HasTypes hasTypes = new MockedHasTyoes( Integer.class );
+        assertThat( underTest.test( hasTypes ), equalTo(false) );
+    }
+
+    @Test
+    public void givenMultipleMatchingTypeWhenFilteringAgainstMultipleExpectTrue()
+    {
+        Predicate<HasTypes> underTest = AssemblySpecifications.ofAnyType( Long.class, Integer.class, BigDecimal.class );
+        HasTypes hasTypes = new MockedHasTyoes( String.class, Integer.class );
+        assertThat( underTest.test( hasTypes ), equalTo(true) );
+    }
+
+    @Test
+    public void givenMultipleNonMatchingTypeWhenFilteringAgainstSingleExpectFalse()
+    {
+        Predicate<HasTypes> underTest = AssemblySpecifications.ofAnyType( Long.class, BigDecimal.class, String.class );
+        HasTypes hasTypes = new MockedHasTyoes( Integer.class );
+        assertThat( underTest.test( hasTypes ), equalTo(false) );
+    }
+
+    @Test
+    public void givenMultipleNonMatchingTypeWhenFilteringAgainstMultipleExpectFalse()
+    {
+        Predicate<HasTypes> underTest = AssemblySpecifications.ofAnyType( Long.class, BigDecimal.class );
+        HasTypes hasTypes = new MockedHasTyoes( String.class, Integer.class );
+        assertThat( underTest.test( hasTypes ), equalTo(false) );
+    }
+
+    private static class MockedHasTyoes
+        implements HasTypes
+    {
+        private final Class[] types;
+
+        public MockedHasTyoes( Class... types)
+        {
+            this.types = types;
+        }
+
+        @Override
+        public Stream<Class<?>> types()
+        {
+            return Arrays.stream(types);
+        }
+    }
+}