You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by to...@apache.org on 2007/07/12 12:42:11 UTC
svn commit: r555575 - in
/harmony/enhanced/classlib/branches/java6/modules/luni/src:
main/java/java/util/PropertyResourceBundle.java
test/api/common/tests/api/java/util/PropertyResourceBundleTest.java
Author: tonywu
Date: Thu Jul 12 03:42:10 2007
New Revision: 555575
URL: http://svn.apache.org/viewvc?view=rev&rev=555575
Log:
Apply patch HARMONY-4424 ([classlib][luni][java6] New method in java.util.PropertyResourceBundle for java6)
Modified:
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/PropertyResourceBundle.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/PropertyResourceBundleTest.java
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/PropertyResourceBundle.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/PropertyResourceBundle.java?view=diff&rev=555575&r1=555574&r2=555575
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/PropertyResourceBundle.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/PropertyResourceBundle.java Thu Jul 12 03:42:10 2007
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.Reader;
/**
* PropertyResourceBundle loads resources from an InputStream. All resources are
@@ -42,9 +43,36 @@
* @throws IOException
*/
public PropertyResourceBundle(InputStream stream) throws IOException {
+ if( null == stream ) {
+ throw new NullPointerException();
+ }
resources = new Properties();
resources.load(stream);
}
+
+ /**
+ * Constructs a new instance of PropertyResourceBundle and loads the
+ * properties from the reader.
+ *
+ * @param reader
+ * the input reader
+ * @throws IOException
+ * @since 1.6
+ */
+ public PropertyResourceBundle(Reader reader) throws IOException {
+ resources = new Properties();
+ resources.load(reader);
+ }
+
+ /**
+ * Answers a set of the keys in this ResourceBundle but not in its parents.
+ *
+ * @return a set of the keys in this ResourceBundle but not in its parents.
+ * @since 1.6
+ */
+ protected Set<String> handleKeySet(){
+ return resources.stringPropertyNames();
+ }
@SuppressWarnings("unchecked")
private Enumeration<String> getLocalKeys() {
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/PropertyResourceBundleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/PropertyResourceBundleTest.java?view=diff&rev=555575&r1=555574&r2=555575
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/PropertyResourceBundleTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/PropertyResourceBundleTest.java Thu Jul 12 03:42:10 2007
@@ -17,6 +17,15 @@
package tests.api.java.util;
+import java.io.ByteArrayInputStream;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
@@ -27,19 +36,75 @@
static PropertyResourceBundle prb;
/**
+ * @throws IOException
* @tests java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.InputStream)
*/
- public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.util.PropertyResourceBundle(java.io.InputStream)
- assertTrue("Used to test", true);
+ @SuppressWarnings("nls")
+ public void test_ConstructorLjava_io_InputStream() throws IOException {
+ InputStream propertiesStream = new ByteArrayInputStream(
+ "p1=one\ncharset=iso-8859-1".getBytes("ISO-8859-1"));
+ prb = new PropertyResourceBundle(propertiesStream);
+ assertEquals(2, prb.keySet().size());
+ assertEquals("one", prb.getString("p1"));
+ assertEquals("iso-8859-1", prb.getString("charset"));
+
+ propertiesStream = new ByteArrayInputStream("p1=one\ncharset=UTF-8"
+ .getBytes("UTF-8"));
+ prb = new PropertyResourceBundle(propertiesStream);
+ assertEquals(2, prb.keySet().size());
+ assertEquals("UTF-8", prb.getString("charset"));
+
+ try {
+ new PropertyResourceBundle((InputStream) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
}
- /**
+ /**
+ * @throws IOException
+ * @tests {@link java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.Reader)}
+ * @since 1.6
+ */
+ @SuppressWarnings("nls")
+ public void test_ConstructorLjava_io_Reader() throws IOException {
+ Charset charset = Charset.forName("ISO-8859-1");
+ String content = "p1=one\nfeature=good_feature";
+ CharBuffer cbuffer = charset.decode(ByteBuffer.wrap(content
+ .getBytes("ISO-8859-1")));
+ char[] chars = new char[cbuffer.limit()];
+ cbuffer.get(chars);
+
+ prb = new PropertyResourceBundle(new CharArrayReader(chars));
+ assertEquals(2, prb.keySet().size());
+ assertEquals("one", prb.getString("p1"));
+ assertEquals("good_feature", prb.getString("feature"));
+
+ charset = Charset.forName("UTF-8");
+ cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("UTF-8")));
+ chars = new char[cbuffer.limit()];
+ cbuffer.get(chars);
+
+ prb = new PropertyResourceBundle(new CharArrayReader(chars));
+ assertEquals(2, prb.keySet().size());
+ assertEquals("one", prb.getString("p1"));
+ assertEquals("good_feature", prb.getString("feature"));
+
+ try {
+ new PropertyResourceBundle((Reader) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ /**
* @tests java.util.PropertyResourceBundle#getKeys()
*/
public void test_getKeys() {
Enumeration keyEnum = prb.getKeys();
- Vector test = new Vector();
+ Vector<Object> test = new Vector<Object>();
int keyCount = 0;
while (keyEnum.hasMoreElements()) {
test.addElement(keyEnum.nextElement());
@@ -77,13 +142,15 @@
/**
* Sets up the fixture, for example, open a network connection. This method
* is called before a test is executed.
- */
- protected void setUp() {
- java.io.InputStream propertiesStream = new java.io.ByteArrayInputStream(
- "p1=one\np2=two".getBytes());
- try {
- prb = new PropertyResourceBundle(propertiesStream);
- } catch (java.io.IOException e) {
+ *
+ * @throws UnsupportedEncodingException
+ */
+ protected void setUp() throws UnsupportedEncodingException {
+ InputStream propertiesStream = new ByteArrayInputStream(
+ "p1=one\np2=two".getBytes("ISO-8859-1"));
+ try {
+ prb = new PropertyResourceBundle(propertiesStream);
+ } catch (java.io.IOException e) {
fail(
"Contruction of PropertyResourceBundle threw IOException");
}