empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r747225 - in /incubator/empire-db/trunk/empire-db/src: main/java/org/apache/empire/commons/Attributes.java test/java/org/apache/empire/commons/AttributesTest.java test/java/org/apache/empire/commons/DateUtilsTest.java
Date Tue, 24 Feb 2009 00:02:09 GMT
Author: francisdb
Date: Tue Feb 24 00:02:08 2009
New Revision: 747225

URL: http://svn.apache.org/viewvc?rev=747225&view=rev
Log:
faster iteration (according to effective java 2nd ed)
added junit test for Attributes class

Added:
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/AttributesTest.java
Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/Attributes.java
    incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/Attributes.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/Attributes.java?rev=747225&r1=747224&r2=747225&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/Attributes.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/commons/Attributes.java
Tue Feb 24 00:02:08 2009
@@ -20,6 +20,7 @@
 
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.Map;
 
 import org.w3c.dom.Element;
 
@@ -72,11 +73,9 @@
     public void addXml(Element element, long flags)
     {
         // add All Options
-        Iterator<String> i = keySet().iterator();
-        while (i.hasNext())
-        {
-            String key = i.next();
-            element.setAttribute(key, String.valueOf(get(key)));
-        }
+    	for(Map.Entry<String,Object> entry:entrySet())
+    	{
+    		element.setAttribute(entry.getKey(), String.valueOf(entry.getValue()));
+    	}
     }
 }

Added: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/AttributesTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/AttributesTest.java?rev=747225&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/AttributesTest.java
(added)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/AttributesTest.java
Tue Feb 24 00:02:08 2009
@@ -0,0 +1,111 @@
+/**
+ * 
+ */
+package org.apache.empire.commons;
+
+import static org.junit.Assert.*;
+
+import java.util.Calendar;
+import java.util.Random;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @author francisdb
+ *
+ */
+public class AttributesTest
+{
+
+	/**
+	 * Test method for {@link org.apache.empire.commons.Attributes#get(java.lang.String)}.
+	 */
+	@Test
+	public void testGetString()
+	{
+		Attributes attributes = new Attributes();
+		Object val = attributes.get("unexisting");
+		assertEquals(null, val);
+		attributes.put("test", Integer.valueOf(123));
+		val = attributes.get("test");
+		assertEquals(Integer.valueOf(123), val);
+	}
+
+	/**
+	 * Test method for {@link org.apache.empire.commons.Attributes#get(java.lang.Object)}.
+	 */
+	@Test
+	public void testGetObject()
+	{
+		Attributes attributes = new Attributes();
+		Object val = attributes.get(new Object());
+		assertEquals(null, val);
+		attributes.put("123", Integer.valueOf(456));
+		val = attributes.get(Integer.valueOf(123));
+		assertEquals(Integer.valueOf(456), val);
+	}
+
+	/**
+	 * Test method for {@link org.apache.empire.commons.Attributes#put(java.lang.String, java.lang.Object)}.
+	 */
+	@Test
+	public void testPutStringObject()
+	{
+		Attributes attributes = new Attributes();
+		attributes.put(null, null);
+		assertEquals(null, attributes.get(null));
+		attributes.put("", null);
+		assertEquals(null, attributes.get(""));
+		attributes.put("test", null);
+		assertEquals(null, attributes.get("test"));
+		attributes.put("test", Integer.valueOf(456));
+		assertEquals(Integer.valueOf(456), attributes.get("test"));
+	}
+
+	/**
+	 * Test method for {@link org.apache.empire.commons.Attributes#set(java.lang.String, java.lang.Object)}.
+	 */
+	@Test
+	public void testSet()
+	{
+		Attributes attributes = new Attributes();
+		attributes.set(null, null);
+		assertEquals(null, attributes.get(null));
+		attributes.set("", null);
+		assertEquals(null, attributes.get(""));
+		attributes.set("test", null);
+		assertEquals(null, attributes.get("test"));
+		attributes.set("test", Integer.valueOf(456));
+		assertEquals(Integer.valueOf(456), attributes.get("test"));
+	}
+
+	/**
+	 * Test method for {@link org.apache.empire.commons.Attributes#addXml(org.w3c.dom.Element,
long)}.
+	 * @throws ParserConfigurationException 
+	 */
+	@Test
+	public void testAddXml() throws ParserConfigurationException
+	{
+		Attributes attributes = new Attributes();
+		attributes.set("test", "testvalue");
+		attributes.set("test2", "testvalue2");
+
+		DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+		Document doc = builder.newDocument();
+		Element root = doc.createElement("root");
+        doc.appendChild(root);
+        
+		// value should be ignored
+		Random random = new Random();
+		attributes.addXml(root, random.nextInt());
+		root.getAttribute("test").equals("testvalue");
+		root.getAttribute("test2").equals("testvalue2");
+	}
+
+}

Modified: incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java?rev=747225&r1=747224&r2=747225&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/test/java/org/apache/empire/commons/DateUtilsTest.java
Tue Feb 24 00:02:08 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.empire.commons;
 
-import static org.junit.Assert.fail;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -26,7 +25,6 @@
 import java.util.Date;
 import java.util.Locale;
 
-import org.junit.Assert;
 import org.junit.Test;
 
 /**



Mime
View raw message