[jboss-svn-commits] JBoss Common SVN: r2934 - in common-core/trunk/src: test/java/org/jboss/test/util/test and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 3 04:28:22 EST 2008


Author: alesj
Date: 2008-11-03 04:28:22 -0500 (Mon, 03 Nov 2008)
New Revision: 2934

Added:
   common-core/trunk/src/test/java/org/jboss/test/util/test/ObjectsUnitTestCase.java
   common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazyMapUnitTestCase.java
   common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazySetUnitTestCase.java
Modified:
   common-core/trunk/src/main/java/org/jboss/util/Objects.java
   common-core/trunk/src/test/java/org/jboss/test/util/test/collection/AbstractMapUnitTest.java
   common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java
Log:
[JBCOMMON-73]; Objects::equals.
Fix PropertyEditorsUTC to use Locale.US.

Modified: common-core/trunk/src/main/java/org/jboss/util/Objects.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/Objects.java	2008-11-02 08:28:31 UTC (rev 2933)
+++ common-core/trunk/src/main/java/org/jboss/util/Objects.java	2008-11-03 09:28:22 UTC (rev 2934)
@@ -38,8 +38,8 @@
 /**
  * A collection of <code>Object</code> utilities.
  *
- * @version <tt>$Revision$</tt>
  * @author  <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @author  <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
 @SuppressWarnings("unchecked")
 public final class Objects
@@ -253,4 +253,37 @@
    public static boolean equals(final Object[] a, final Object[] b) {
       return equals(a, b, true);
    }
+
+   /**
+    * Test the equality of two objects.
+    * They can be an (multi dimensional) array.
+    *
+    * @param first the first obejct
+    * @param second the second object
+    * @return true if equal, false otherwise
+    */
+   public static boolean equals(Object first, Object second)
+   {
+      if (isArray(first))
+      {
+         if (isArray(second) == false)
+            return false;
+
+         int lenght = Array.getLength(first);
+         if (lenght != Array.getLength(second))
+            return false;
+
+         for (int i = 0; i < lenght; i++)
+         {
+            if (equals(Array.get(first, i), Array.get(second, i)) == false)
+               return false;
+         }
+
+         return true;
+      }
+      else
+      {
+         return JBossObject.equals(first, second);
+      }
+   }
 }

Added: common-core/trunk/src/test/java/org/jboss/test/util/test/ObjectsUnitTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/ObjectsUnitTestCase.java	                        (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/ObjectsUnitTestCase.java	2008-11-03 09:28:22 UTC (rev 2934)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.util.test;
+
+import java.util.Date;
+
+import junit.framework.TestCase;
+import org.jboss.util.Objects;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ObjectsUnitTestCase extends TestCase
+{
+   public void testEquals() throws Exception
+   {
+      assertTrue(Objects.equals("123", "123"));
+
+      Object first = new String[]{"123", "321"};
+      Object second = new String[]{"123", "321"};
+      assertTrue(Objects.equals(first, second));
+      first = new String[][]{{"1", "2"}, {"1", "2"}};
+      second = new String[][]{{"1", "2"}, {"1", "2"}};
+      assertTrue(Objects.equals(first, second));
+
+      assertFalse(Objects.equals("129", "123"));
+      first = new String[]{"123", "324"};
+      second = new String[]{"123", "321"};
+      assertFalse(Objects.equals(first, second));
+      first = new String[][]{{"1", "6"}, {"1", "2"}};
+      second = new String[][]{{"1", "2"}, {"1", "2"}};
+      assertFalse(Objects.equals(first, second));
+
+      first = new int[]{1, 2, 3};
+      second = new int[]{1, 2, 3};
+      assertTrue(Objects.equals(first, second));
+      first = new int[][]{{1, 2}, {1, 2}};
+      second = new int[][]{{1, 2}, {1, 2}};
+      assertTrue(Objects.equals(first, second));
+
+      first = new int[]{1, 2, 4};
+      second = new int[]{1, 2, 3};
+      assertFalse(Objects.equals(first, second));
+      first = new int[][]{{1, 6}, {1, 2}};
+      second = new int[][]{{1, 2}, {1, 2}};
+      assertFalse(Objects.equals(first, second));
+
+      assertFalse(Objects.equals("123", new int[]{1, 2, 3}));
+      assertFalse(Objects.equals(new int[]{1, 2, 3}, "123"));
+      assertFalse(Objects.equals(new Date(), 123));
+   }
+}

Modified: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/AbstractMapUnitTest.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/AbstractMapUnitTest.java	2008-11-02 08:28:31 UTC (rev 2933)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/AbstractMapUnitTest.java	2008-11-03 09:28:22 UTC (rev 2934)
@@ -20,29 +20,46 @@
    {
       Map map = createEmptyMap();
       assertTrue(map.isEmpty());
+      assertEquals(0, map.size());
 
-      String key = "date1";
-      Date value = new Date();
-      map.put(key, value);
+      String key1 = "date1";
+      Date value1 = new Date();
+      map.put(key1, value1);
 
-      assertTrue(map.containsKey(key));
-      assertTrue(map.containsValue(value));
+      assertTrue(map.containsKey(key1));
+      assertTrue(map.containsValue(value1));
       assertEquals(1, map.size());
 
+      String key2 = "date2";
+      Date value2 = new Date();
+      map.put(key2, value2);
+
+      assertTrue(map.containsKey(key2));
+      assertTrue(map.containsValue(value2));
+      assertEquals(2, map.size());
+
+      String key3 = "date3";
+      Date value3 = new Date();
+      map.put(key3, value3);
+
+      assertTrue(map.containsKey(key1));
+      assertTrue(map.containsValue(value1));
+      assertEquals(3, map.size());
+
       map.clear();
       assertTrue(map.isEmpty());
 
-      key = "date1";
-      value = new Date();
-      map.put(key, value);
+      key1 = "date1";
+      value1 = new Date();
+      map.put(key1, value1);
 
-      map.remove(key);
+      map.remove(key1);
       assertTrue(map.isEmpty());
 
-      map.putAll(Collections.singletonMap(key, value));
+      map.putAll(Collections.singletonMap(key1, value1));
 
-      assertEquals(value, map.get(key));
-      assertEquals(map, Collections.singletonMap(key, value));
+      assertEquals(value1, map.get(key1));
+      assertEquals(Collections.singletonMap(key1, value1), map);
       
       // iterables
       Iterable<String> keys = map.keySet();
@@ -51,8 +68,8 @@
       assertIterable(values, Date.class);
       Iterable<Map.Entry> entries = map.entrySet();
       Map.Entry entry = assertIterable(entries, Map.Entry.class);
-      assertEquals(key, entry.getKey());
-      assertEquals(value, entry.getValue());
+      assertEquals(key1, entry.getKey());
+      assertEquals(value1, entry.getValue());
    }
 
    protected <T> T assertIterable(Iterable<T> iter, Class<T> clazz)

Copied: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazyMapUnitTestCase.java (from rev 2933, common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueHashMapUnitTestCase.java)
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazyMapUnitTestCase.java	                        (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazyMapUnitTestCase.java	2008-11-03 09:28:22 UTC (rev 2934)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.util.test.collection;
+
+import java.util.Map;
+
+import org.jboss.util.collection.CollectionsFactory;
+
+/**
+ * SoftValueHashMap test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LazyMapUnitTestCase extends AbstractMapUnitTest
+{
+   protected Map createEmptyMap()
+   {
+      return CollectionsFactory.createLazyMap();
+   }
+}
\ No newline at end of file

Copied: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazySetUnitTestCase.java (from rev 2930, common-core/trunk/src/test/java/org/jboss/test/util/test/collection/ConcurrentSetUnitTestCase.java)
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazySetUnitTestCase.java	                        (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/LazySetUnitTestCase.java	2008-11-03 09:28:22 UTC (rev 2934)
@@ -0,0 +1,19 @@
+package org.jboss.test.util.test.collection;
+
+import java.util.Set;
+
+import org.jboss.util.collection.CollectionsFactory;
+
+/**
+ * Unit tests for ConcurrentSet
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+ at SuppressWarnings("unchecked")
+public class LazySetUnitTestCase extends AbstractSetUnitTest
+{
+   protected Set createSet()
+   {
+      return CollectionsFactory.createLazySet();
+   }
+}
\ No newline at end of file

Modified: common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java	2008-11-02 08:28:31 UTC (rev 2933)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java	2008-11-03 09:28:22 UTC (rev 2934)
@@ -41,9 +41,7 @@
 import java.util.concurrent.atomic.AtomicLong;
 
 import junit.framework.TestCase;
-
 import org.jboss.logging.Logger;
-import org.jboss.util.Strings;
 import org.jboss.util.propertyeditor.DateEditor;
 import org.jboss.util.propertyeditor.DocumentEditor;
 import org.jboss.util.propertyeditor.ElementEditor;
@@ -58,6 +56,7 @@
  * 
  * @author Scott.Stark at jboss.org
  * @author Dimitris.Andreadis at jboss.org
+ * @author Ales.Justin at jboss.org
  * @version $Revision: 43534 $
  */
 @SuppressWarnings("unchecked")
@@ -65,7 +64,8 @@
 {
    private static Logger log = Logger.getLogger(PropertyEditorsUnitTestCase.class);
    Calendar calendar = Calendar.getInstance();
-   
+   private Locale locale;
+
    /** Augment the PropertyEditorManager search path to incorporate the JBoss
     specific editors. This simply references the PropertyEditors.class to
     invoke its static initialization block.
@@ -139,6 +139,21 @@
       super(name);
    }
 
+   protected void setUp() throws Exception
+   {
+      locale = Locale.getDefault();
+      Locale.setDefault(Locale.US);
+
+      super.setUp();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+
+      Locale.setDefault(locale);
+   }
+
    public void testEditorSearchPath()
       throws Exception
    {




More information about the jboss-svn-commits mailing list