| 
      
      
      From: <be...@us...> - 2010-03-28 11:31:41
      
     | 
| Revision: 319
          http://objectlabkit.svn.sourceforge.net/objectlabkit/?rev=319&view=rev
Author:   benoitx
Date:     2010-03-28 11:31:34 +0000 (Sun, 28 Mar 2010)
Log Message:
-----------
100% coverage for CollectionUtil
and make the deliverable an osgi bundle!
Modified Paths:
--------------
    trunk/utils/pom.xml
    trunk/utils/src/main/java/net/objectlab/kit/util/CollectionUtil.java
    trunk/utils/src/test/java/net/objectlab/kit/util/CollectionUtilTest.java
Modified: trunk/utils/pom.xml
===================================================================
--- trunk/utils/pom.xml	2010-03-28 10:55:09 UTC (rev 318)
+++ trunk/utils/pom.xml	2010-03-28 11:31:34 UTC (rev 319)
@@ -6,7 +6,7 @@
   <groupId>net.objectlab.kit</groupId>
   <artifactId>objectlab-utils</artifactId>
   <version>1.0-SNAPSHOT</version>
-  <packaging>jar</packaging>
+  <packaging>bundle</packaging>
 
   <name>ObjectLab Kit - General Utilities</name>
 
@@ -39,6 +39,20 @@
           <target>1.5</target>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>net.objectlab.kit.*;version="${pom.version}"</Export-Package>
+            <Private-Package />
+            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+            <Bundle-Version>${pom.version}</Bundle-Version>
+            <Bundle-RequiredExecutionEnvironment>J2SE-1.5</Bundle-RequiredExecutionEnvironment>
+          </instructions>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
Modified: trunk/utils/src/main/java/net/objectlab/kit/util/CollectionUtil.java
===================================================================
--- trunk/utils/src/main/java/net/objectlab/kit/util/CollectionUtil.java	2010-03-28 10:55:09 UTC (rev 318)
+++ trunk/utils/src/main/java/net/objectlab/kit/util/CollectionUtil.java	2010-03-28 11:31:34 UTC (rev 319)
@@ -103,6 +103,9 @@
      * @return true if none of the collections are empty or null
      */
     public static boolean noneEmpty(final Collection... collections) {
+        if (collections == null) {
+            return false;
+        }
         for (final Collection col : collections) {
             if (isEmpty(col)) {
                 return false;
@@ -112,8 +115,11 @@
     }
 
     public static boolean sameContent(final Collection c1, final Collection c2) {
-        boolean same = c1 != null && c2 != null || c1 == c2 || c1 == null && c2 == null;
-        if (same && c1 != null) {
+        if (c1 == c2 || (isEmpty(c2) && isEmpty(c1))) {
+            return true;
+        }
+        boolean same = false;
+        if (c1 != null && c2 != null) {
             same = c1.size() == c2.size();
             if (same) {
                 same = c1.equals(c2);
Modified: trunk/utils/src/test/java/net/objectlab/kit/util/CollectionUtilTest.java
===================================================================
--- trunk/utils/src/test/java/net/objectlab/kit/util/CollectionUtilTest.java	2010-03-28 10:55:09 UTC (rev 318)
+++ trunk/utils/src/test/java/net/objectlab/kit/util/CollectionUtilTest.java	2010-03-28 11:31:34 UTC (rev 319)
@@ -1,8 +1,12 @@
 package net.objectlab.kit.util;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 
 import org.junit.Test;
@@ -12,47 +16,116 @@
     @Test
     public void testIsEmpty() {
         assertTrue("null", CollectionUtil.isEmpty(null));
-        assertTrue("empty set", CollectionUtil.isEmpty(new HashSet()));
+        HashSet col = new HashSet();
+        assertTrue("empty set", CollectionUtil.isEmpty(col));
+        col.add(1);
+        assertFalse("not empty set", CollectionUtil.isEmpty(col));
+        col.add(2);
+        assertFalse("not empty set", CollectionUtil.isEmpty(col));
     }
 
     @Test
-    public void testIsNotEmptyCollectionOfQ() {
-        fail("Not yet implemented");
+    public void testIsNotEmptyCollection() {
+        assertFalse("null", CollectionUtil.isNotEmpty((Collection) null));
+        HashSet col = new HashSet();
+        assertFalse("empty set", CollectionUtil.isNotEmpty(col));
+        col.add(1);
+        assertTrue("not empty set", CollectionUtil.isNotEmpty(col));
+        col.add(2);
+        assertTrue("2 empty set", CollectionUtil.isNotEmpty(col));
     }
 
     @Test
-    public void testHasOneItem() {
-        fail("Not yet implemented");
+    public void testIsNotEmptyObjectArray() {
+        assertFalse("null", CollectionUtil.isNotEmpty((Object[]) null));
+        Object[] col = new String[0];
+        assertFalse("empty set", CollectionUtil.isNotEmpty(col));
+        col = new String[1];
+        assertTrue("not empty set", CollectionUtil.isNotEmpty(col));
     }
 
     @Test
-    public void testIsNotEmptyObjectArray() {
-        fail("Not yet implemented");
+    public void testHasOneItem() {
+        assertFalse("null", CollectionUtil.hasOneItem((Collection) null));
+        HashSet col = new HashSet();
+        assertFalse("empty set", CollectionUtil.hasOneItem(col));
+        col.add(1);
+        assertTrue("not empty set", CollectionUtil.hasOneItem(col));
+        col.add(2);
+        assertFalse("2 items set", CollectionUtil.hasOneItem(col));
     }
 
     @Test
     public void testSize() {
-        fail("Not yet implemented");
+        assertEquals("null", 0, CollectionUtil.size((Collection) null));
+        HashSet col = new HashSet();
+        assertEquals("empty ", 0, CollectionUtil.size(col));
+        col.add(1);
+        assertEquals("1", 1, CollectionUtil.size(col));
+        col.add(2);
+        assertEquals("2", 2, CollectionUtil.size(col));
     }
 
     @Test
     public void testContains() {
-        fail("Not yet implemented");
+        assertFalse("null", CollectionUtil.contains((Collection) null, "bla"));
+        HashSet col = new HashSet();
+        assertFalse("empty", CollectionUtil.contains(col, "bla"));
+        col.add(1);
+        assertFalse("1", CollectionUtil.contains(col, "bla"));
+        col.add("bla");
+        assertTrue("1 + bla", CollectionUtil.contains(col, "bla"));
     }
 
     @Test
     public void testContainsAny() {
-        fail("Not yet implemented");
+        assertFalse("null", CollectionUtil.containsAny((Collection) null, "bla", 2));
+        HashSet col = new HashSet();
+        assertFalse("empty", CollectionUtil.containsAny(col, "bla", 2));
+        col.add(1);
+        assertFalse("contains 1", CollectionUtil.containsAny(col, "bla", 2));
+        col.add(2);
+        assertTrue("contains 2", CollectionUtil.containsAny(col, "bla", 2));
+        col.add("bla");
+        assertTrue("contains 2 and bla", CollectionUtil.containsAny(col, "bla", 2));
+        col.remove(2);
+        assertTrue("contains bla", CollectionUtil.containsAny(col, "bla", 2));
+        col.remove("bla");
+        assertFalse("contains nothing", CollectionUtil.containsAny(col, "bla", 2));
     }
 
     @Test
     public void testNoneEmpty() {
-        fail("Not yet implemented");
+        assertFalse("1 null", CollectionUtil.noneEmpty(null));
+        assertFalse("2 null", CollectionUtil.noneEmpty(null, null));
+        assertFalse("empty null", CollectionUtil.noneEmpty(Collections.EMPTY_LIST, null));
+        assertFalse("empty empty", CollectionUtil.noneEmpty(Collections.EMPTY_LIST, Collections.EMPTY_LIST));
+        HashSet col = new HashSet();
+        assertFalse("empty empty", CollectionUtil.noneEmpty(col, col));
+        col.add(1);
+        assertTrue("1", CollectionUtil.noneEmpty(col));
+        HashSet col2 = new HashSet();
+        assertFalse("1 and 2 empty", CollectionUtil.noneEmpty(col, col2));
+        assertFalse("1 and null 2 empty", CollectionUtil.noneEmpty(col, null, col2));
+        col2.add("bla");
+        assertFalse("1 and null 2", CollectionUtil.noneEmpty(col, null, col2));
+        assertTrue("1 and 2", CollectionUtil.noneEmpty(col, col2));
     }
 
     @Test
     public void testSameContent() {
-        fail("Not yet implemented");
+        assertTrue("null null", CollectionUtil.sameContent(null, null));
+        HashSet col = new HashSet();
+        assertTrue("empty null", CollectionUtil.sameContent(col, null));
+        assertTrue("same", CollectionUtil.sameContent(col, col));
+        HashSet col1 = new HashSet();
+        col.add(1);
+        assertFalse("not same empty 1", CollectionUtil.sameContent(col, col1));
+        assertFalse("not same 1 empty", CollectionUtil.sameContent(col1, col));
+        col1.add(1);
+        assertTrue("same 1 1", CollectionUtil.sameContent(col1, col));
+        col1.add(2);
+        assertFalse("same 1 2", CollectionUtil.sameContent(col1, col));
     }
 
 }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |