You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/12/27 21:06:47 UTC

[groovy] branch GROOVY_3_0_X updated: Add a test for `Arrays`

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 54498a9  Add a test for `Arrays`
54498a9 is described below

commit 54498a9c43de181be2aa4abb2d0babeb77fdc654
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Dec 28 05:05:57 2019 +0800

    Add a test for `Arrays`
    
    (cherry picked from commit f09141f284b3d5f0b74b5c71bf2d0b9c81a785a1)
---
 src/test/org/apache/groovy/util/ArraysTest.java | 58 +++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/src/test/org/apache/groovy/util/ArraysTest.java b/src/test/org/apache/groovy/util/ArraysTest.java
new file mode 100644
index 0000000..f46e336
--- /dev/null
+++ b/src/test/org/apache/groovy/util/ArraysTest.java
@@ -0,0 +1,58 @@
+/*
+ *  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.groovy.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ArraysTest {
+    @Test
+    public void testMerge0() {
+        try {
+            Integer[] result = Arrays.merge();
+            Assert.fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            Assert.assertTrue(e.getMessage().contains("arrays should not be empty"));
+        }
+    }
+
+    @Test
+    public void testMerge1() {
+        Integer[] a = new Integer[] {1, 2};
+        Integer[] result = Arrays.merge(a);
+        Assert.assertArrayEquals(new Integer[] {1, 2}, result);
+    }
+
+    @Test
+    public void testMerge2() {
+        Integer[] a = new Integer[] {1, 2};
+        Integer[] b = new Integer[] {3, 4};
+        Integer[] result = Arrays.merge(a, b);
+        Assert.assertArrayEquals(new Integer[] {1, 2, 3, 4}, result);
+    }
+
+    @Test
+    public void testMerge3() {
+        Integer[] a = new Integer[] {1, 2};
+        Integer[] b = new Integer[] {3, 4};
+        Integer[] c = new Integer[] {5, 6, 7, 8, 9};
+        Integer[] result = Arrays.merge(a, b, c);
+        Assert.assertArrayEquals(new Integer[] {1, 2, 3, 4, 5, 6, 7, 8, 9}, result);
+    }
+}