harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r901111 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/
Date Wed, 20 Jan 2010 08:58:47 GMT
Author: regisxu
Date: Wed Jan 20 08:58:04 2010
New Revision: 901111

URL: http://svn.apache.org/viewvc?rev=901111&view=rev
Log:
Apply patch for HARMONY-6429: [test] Improve the method coverage rate of unit test for java.util

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractListTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ListResourceBundleTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyResourceBundleTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractListTest.java?rev=901111&r1=901110&r2=901111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractListTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractListTest.java
Wed Jan 20 08:58:04 2010
@@ -430,4 +430,77 @@
 
         holder.clear();
     }
+
+    /**
+     * @tests {@link java.util.AbstractList#indexOf(Object)}
+     */
+    public void test_indexOf_Ljava_lang_Object() {
+        AbstractList<Integer> list = new MockArrayList<Integer>();
+        Integer[] array = { 1, 2, 3, 4, 5 };
+        list.addAll(Arrays.asList(array));
+
+        assertEquals("find 0 in the list do not contain 0", -1, list
+                .indexOf(new Integer(0)));
+        assertEquals("did not return the right location of element 3", 2, list
+                .indexOf(new Integer(3)));
+        assertEquals("find null in the list do not contain null element", -1,
+                list.indexOf(null));
+        list.add(null);
+        assertEquals("did not return the right location of element null", 5,
+                list.indexOf(null));
+    }
+
+    /**
+     * @add tests {@link java.util.AbstractList#lastIndexOf(Object)}
+     */
+    public void test_lastIndexOf_Ljava_lang_Object() {
+        AbstractList<Integer> list = new MockArrayList<Integer>();
+        Integer[] array = { 1, 2, 3, 4, 5, 5, 4, 3, 2, 1 };
+        list.addAll(Arrays.asList(array));
+
+        assertEquals("find 6 in the list do not contain 6", -1, list
+                .lastIndexOf(new Integer(6)));
+        assertEquals("did not return the right location of element 4", 6, list
+                .lastIndexOf(new Integer(4)));
+        assertEquals("find null in the list do not contain null element", -1,
+                list.lastIndexOf(null));
+        list.add(null);
+        assertEquals("did not return the right location of element null", 10,
+                list.lastIndexOf(null));
+    }
+
+    /**
+     * @add tests {@link java.util.AbstractList#remove(int)}
+     * @add tests {@link java.util.AbstractList#set(int, Object)}
+     */
+    public void test_remove_I() {
+        class MockList<E> extends AbstractList<E> {
+            private ArrayList<E> list;
+
+            @Override
+            public E get(int location) {
+                return list.get(location);
+            }
+
+            @Override
+            public int size() {
+                return list.size();
+            }
+
+        }
+        AbstractList<Integer> list = new MockList<Integer>();
+        try {
+            list.remove(0);
+            fail("should throw UnsupportedOperationException");
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+
+        try {
+            list.set(0, null);
+            fail("should throw UnsupportedOperationException");
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java?rev=901111&r1=901110&r2=901111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java
Wed Jan 20 08:58:04 2010
@@ -36,4 +36,15 @@
         }
     }
 
+    /**
+     * @tests {@link java.util.InvalidPropertiesFormatException#InvalidPropertiesFormatException(Throwable)}
+     */
+    public void test_Constructor_Ljava_lang_Throwable() {
+        Throwable throwable = new Throwable();
+        InvalidPropertiesFormatException exception = new InvalidPropertiesFormatException(
+                throwable);
+        assertEquals("the casue did not equals argument passed in constructor",
+                throwable, exception.getCause());
+    }
+
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ListResourceBundleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ListResourceBundleTest.java?rev=901111&r1=901110&r2=901111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ListResourceBundleTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ListResourceBundleTest.java
Wed Jan 20 08:58:04 2010
@@ -32,8 +32,8 @@
 		String name = "tests.support.Support_TestResource";
 		Locale.setDefault(new Locale("en", "US"));
 		bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
-		Enumeration keys = bundle.getKeys();
-		Vector result = new Vector();
+		Enumeration<String> keys = bundle.getKeys();
+		Vector<String> result = new Vector<String>();
 		while (keys.hasMoreElements()) {
 			result.addElement(keys.nextElement());
 		}

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java?rev=901111&r1=901110&r2=901111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
Wed Jan 20 08:58:04 2010
@@ -126,6 +126,8 @@
         Properties myProps = new Properties();
         myProps.setProperty("Abba", "Cadabra");
         myProps.setProperty("Open", "Sesame");
+        myProps.setProperty("LongProperty",
+                "a long long long long long long long property");
         myProps.list(ps);
         ps.flush();
         String propList = baos.toString();
@@ -133,6 +135,16 @@
                 propList.indexOf("Abba=Cadabra") >= 0);
         assertTrue("Property list innacurate",
                 propList.indexOf("Open=Sesame") >= 0);
+        assertTrue("property list do not conatins \"...\"", propList
+                .indexOf("...") != -1);
+
+        ps = null;
+        try {
+            myProps.list(ps);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
     /**
@@ -144,6 +156,8 @@
         Properties myProps = new Properties();
         myProps.setProperty("Abba", "Cadabra");
         myProps.setProperty("Open", "Sesame");
+        myProps.setProperty("LongProperty",
+                "a long long long long long long long property");
         myProps.list(pw);
         pw.flush();
         String propList = baos.toString();
@@ -151,6 +165,13 @@
                 propList.indexOf("Abba=Cadabra") >= 0);
         assertTrue("Property list innacurate",
                 propList.indexOf("Open=Sesame") >= 0);
+        pw = null;
+        try {
+            myProps.list(pw);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
     /**
@@ -286,7 +307,8 @@
      * @tests java.util.Properties#propertyNames()
      */
     public void test_propertyNames() {
-        Enumeration names = tProps.propertyNames();
+        Properties myPro = new Properties(tProps);
+        Enumeration names = myPro.propertyNames();
         while (names.hasMoreElements()) {
             String p = (String) names.nextElement();
             assertTrue("Incorrect names returned", p.equals("test.prop")
@@ -433,6 +455,13 @@
                 .getProperty("key2"));
         assertEquals("Failed to load correct properties", "value1", prop
                 .getProperty("key1"));
+        
+        try {
+            prop.loadFromXML(null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
     /**
@@ -492,6 +521,13 @@
             assertTrue("Stored property list not equal to original", myProps2
                     .getProperty(nextKey).equals(myProps.getProperty(nextKey)));
         }
+        
+        try {
+            myProps.storeToXML(out, null, null);
+            fail("should throw nullPointerException");
+        } catch (NullPointerException ne) {
+            // expected
+        }
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyResourceBundleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyResourceBundleTest.java?rev=901111&r1=901110&r2=901111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyResourceBundleTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertyResourceBundleTest.java
Wed Jan 20 08:58:04 2010
@@ -17,9 +17,11 @@
 
 package org.apache.harmony.luni.tests.java.util;
 
+import java.io.IOException;
 import java.util.Enumeration;
 import java.util.MissingResourceException;
 import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
 import java.util.Vector;
 
 public class PropertyResourceBundleTest extends junit.framework.TestCase {
@@ -95,4 +97,39 @@
 	 */
 	protected void tearDown() {
 	}
+
+    /**
+     * @add tests {@link java.util.PropertyResourceBundle#Enumeration}
+     */
+    public void test_access$0_Enumberation() throws IOException {
+        class MockResourceBundle extends PropertyResourceBundle {
+            MockResourceBundle(java.io.InputStream stream) throws IOException {
+                super(stream);
+            }
+
+            @Override
+            protected void setParent(ResourceBundle bundle) {
+                super.setParent(bundle);
+            }
+        }
+
+        java.io.InputStream localStream = new java.io.ByteArrayInputStream(
+                "p3=three\np4=four".getBytes());
+        MockResourceBundle localPrb = new MockResourceBundle(localStream);
+        localPrb.setParent(prb);
+        Enumeration<String> keys = localPrb.getKeys();
+        Vector<String> contents = new Vector<String>();
+        while (keys.hasMoreElements()) {
+            contents.add(keys.nextElement());
+        }
+
+        assertEquals("did not get the right number of properties", 4, contents
+                .size());
+        assertTrue("did not get the parent property p1", contents
+                .contains("p1"));
+        assertTrue("did not get the parent property p2", contents
+                .contains("p2"));
+        assertTrue("did not get the local property p3", contents.contains("p3"));
+        assertTrue("did not get the local property p4", contents.contains("p4"));
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java?rev=901111&r1=901110&r2=901111&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TimeZoneTest.java
Wed Jan 20 08:58:04 2010
@@ -17,10 +17,12 @@
 
 package org.apache.harmony.luni.tests.java.util;
 
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Formatter;
 import java.util.GregorianCalendar;
+import java.util.List;
 import java.util.Locale;
 import java.util.SimpleTimeZone;
 import java.util.TimeZone;
@@ -207,4 +209,67 @@
 
 	protected void tearDown() {
 	}
+	
+    /**
+     * @add test {@link java.util.TimeZone#getAvailableIDs(int)}
+     */
+    public void test_getAvailableIDs_I() {
+        TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
+        int rawoffset = tz.getRawOffset();
+        String[] ids = TimeZone.getAvailableIDs(rawoffset);
+        List<String> idList = Arrays.asList(ids);
+        assertTrue("Asia/shanghai and Hongkong should have the same rawoffset",
+                idList.contains("Hongkong"));        
+    }
+    
+    /**
+     * @add test {@link java.util.TimeZone#getDisplayName()}
+     */
+    public void test_getDisplayName() {
+        TimeZone defaultZone = TimeZone.getDefault();
+        Locale defaulLocal = Locale.getDefault();
+        String defaultName = defaultZone.getDisplayName();
+        String expectedName = defaultZone.getDisplayName(defaulLocal);
+        assertEquals(
+                "getDispalyName() did not return the default Locale suitable name",
+                expectedName, defaultName);
+    }
+
+    /**
+     * @add test {@link java.util.TimeZone#getDisplayName(boolean, int)}
+     */
+    public void test_getDisplayName_ZI() {
+        TimeZone defaultZone = TimeZone.getDefault();
+        Locale defaultLocale = Locale.getDefault();
+        String actualName = defaultZone.getDisplayName(false, TimeZone.LONG);
+        String expectedName = defaultZone.getDisplayName(false, TimeZone.LONG,
+                defaultLocale);
+        assertEquals(
+                "getDisplayName(daylight,style) did not return the default locale suitable
name",
+                expectedName, actualName);
+    }
+
+    /**
+     * @add test {@link java.util.TimeZone#hasSameRules(TimeZone)}
+     */
+    public void test_hasSameRules_Ljava_util_TimeZone() {
+        TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
+        int offset = tz.getRawOffset();
+
+        String[] ids = TimeZone.getAvailableIDs(offset);
+        int i = 0;
+        if (ids.length != 0) {
+            while (true) {
+                if (!(ids[i].equalsIgnoreCase(tz.getID()))) {
+                    TimeZone sameZone = TimeZone.getTimeZone(ids[i]);
+                    assertTrue(tz.hasSameRules(sameZone));
+                    break;
+                } else {
+                    i++;
+                }
+            }
+        }
+        assertFalse("should return false when parameter is null", tz
+                .hasSameRules(null));
+    }
 }



Mime
View raw message