Apply most of dalvik-prebuild's fixes to the test suite.
Change-Id: I87fe7b89cb64d734fb2ab93c00457c4ca82fe21d
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
index 7dc7131..e867873 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
@@ -1047,7 +1047,8 @@
defl.reset();
fail("defl.reset() can still be used after " + desc
+ " is called in test_" + desc);
- } catch (NullPointerException e) {
+ } catch (NullPointerException expected) {
+ } catch (IllegalStateException expected) {
}
// Methods where we expect NullPointerException to be thrown
@@ -1055,7 +1056,8 @@
defl.getBytesRead();
fail("defl.reset() can still be used after " + desc
+ " is called in test_" + desc);
- } catch (NullPointerException e) {
+ } catch (NullPointerException expected) {
+ } catch (IllegalStateException expected) {
}
// Methods where we expect NullPointerException to be thrown
@@ -1063,7 +1065,8 @@
defl.getBytesWritten();
fail("defl.getBytesWritten() can still be used after " + desc
+ " is called in test_" + desc);
- } catch (NullPointerException e) {
+ } catch (NullPointerException expected) {
+ } catch (IllegalStateException expected) {
}
// Methods that should be allowed to be called after end() is called
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
index e80b41b..6d54d30 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
@@ -1097,21 +1097,23 @@
try{
inflate.getAdler();
fail("IllegalStateException expected");
- }catch(IllegalStateException ise){
+ }catch(IllegalStateException expected){
//expected
}
try{
inflate.getBytesRead();
fail("NullPointerException expected");
- }catch(NullPointerException ise){
+ }catch(IllegalStateException expected){
+ }catch(NullPointerException expected){
//expected
}
try{
inflate.getBytesWritten();
fail("NullPointerException expected");
- }catch(NullPointerException ise){
+ }catch(NullPointerException expected){
+ }catch(IllegalStateException expected){
//expected
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
index 31c6766..fd96ea4 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
@@ -226,9 +226,19 @@
// Regression for HARMONY-4405
try {
zip.write(null, 0, -2);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
+ }
+ try {
+ zip.write(null, 0, 2);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ try {
+ zip.write(new byte[2], 0, -2);
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
// Close stream because ZIP is invalid
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java
index 4b58058..8a27c92 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java
@@ -329,22 +329,22 @@
try {
bos.write(byteArray, -1, -1);
fail();
- } catch (IndexOutOfBoundsException e) {
- // expected IndexOutOfBoundsException
+ } catch (IOException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
bos.write(null, -1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected NullPointerException.
+ fail();
+ } catch (IOException expected) {
+ } catch (NullPointerException expected) {
}
try {
bos.write(null, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected NullPointerException.
+ fail();
+ } catch (IOException expected) {
+ } catch (NullPointerException expected) {
}
}
@@ -823,11 +823,12 @@
// Regression test for flush on closed stream
public void test_flush_on_closed_stream() throws IOException {
- BufferedOutputStream bos =
- new BufferedOutputStream(
- new ByteArrayOutputStream());
+ BufferedOutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream());
bos.close();
- bos.flush(); // RI does not throw exception
+ try {
+ bos.flush(); // RI does not throw exception
+ } catch (IOException expected) { // but Android does
+ }
}
/**
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
index 6f0ef40..f101c73 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
@@ -380,16 +380,16 @@
try {
br.read(nullCharArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
br.read(nullCharArray, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java
index adc7ebe..c28ddd9 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java
@@ -161,8 +161,8 @@
try {
bWriter.write(nullCharArray, -1, -1);
fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayOutputStreamTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayOutputStreamTest.java
index 9a4b415..98c5b1f 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayOutputStreamTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ByteArrayOutputStreamTest.java
@@ -189,11 +189,8 @@
ByteArrayOutputStream obj = new ByteArrayOutputStream();
try {
obj.write(new byte[] { (byte) 0x00 }, -1, 0);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/CharArrayWriterTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/CharArrayWriterTest.java
index 7a065b1..a188add 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/CharArrayWriterTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/CharArrayWriterTest.java
@@ -124,11 +124,8 @@
CharArrayWriter obj = new CharArrayWriter();
try {
obj.write(new char[] { '0' }, 0, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/DataInputStreamTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/DataInputStreamTest.java
index f737b7e..c9241dc 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/DataInputStreamTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/DataInputStreamTest.java
@@ -214,23 +214,23 @@
try {
is.readFully(nullByteArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
is.readFully(nullByteArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
is.readFully(nullByteArray, 1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
is.readFully(nullByteArray, -1, 0);
@@ -239,9 +239,9 @@
try {
is.readFully(nullByteArray, -1, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
@@ -275,23 +275,23 @@
try {
is.readFully(byteArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
is.readFully(byteArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
is.readFully(byteArray, 1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
is.readFully(byteArray, -1, 0);
@@ -336,23 +336,23 @@
try {
is.readFully(nullByteArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
is.readFully(nullByteArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
is.readFully(nullByteArray, 1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
is.readFully(nullByteArray, -1, 0);
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
index cd5b374..f85befb 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
@@ -471,19 +471,17 @@
*/
public void test_read$CII_1() throws IOException {
try {
- // Throws IndexOutOfBoundsException before NullPointerException
reader.read(null, -1, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
- // Throws NullPointerException before IndexOutOfBoundsException
reader.read(null, 0, -1);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
- // expected
+ } catch (IndexOutOfBoundsException expected) {
}
try {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
index 837b443..a788568 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
@@ -114,17 +114,17 @@
// Throws IndexOutOfBoundsException if offset is negative
try {
writer.write((char[]) null, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
+ fail();
+ } catch (NullPointerException exception) {
+ } catch (IndexOutOfBoundsException exception) {
}
// throws NullPointerException though count is negative
try {
writer.write((char[]) null, 1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
+ fail();
+ } catch (NullPointerException exception) {
+ } catch (IndexOutOfBoundsException exception) {
}
try {
@@ -243,21 +243,19 @@
// Expected
}
- // Throws IndexOutOfBoundsException before NullPointerException if count
- // is negative
try {
writer.write((String) null, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
// Throws NullPointerException before StringIndexOutOfBoundsException
try {
writer.write((String) null, -1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
writer.write("abc", 1, 2);
@@ -271,16 +269,16 @@
// Throws IndexOutOfBoundsException first if count is negative
try {
writer.write((String) null, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
writer.write((String) null, -1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
index 8503df5..6295de5 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
@@ -90,10 +90,7 @@
pis.read();
t.interrupt();
}
- } catch (IOException e) {
- if (!e.getMessage().contains("Write end dead")) {
- throw e;
- }
+ } catch (IOException expected) {
} finally {
try {
pis.close();
@@ -222,11 +219,8 @@
PipedInputStream obj = new PipedInputStream();
try {
obj.read(new byte[0], 0, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
@@ -237,10 +231,8 @@
PipedInputStream obj = new PipedInputStream();
try {
obj.read(new byte[0], -1, 0);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
@@ -251,10 +243,8 @@
PipedInputStream obj = new PipedInputStream();
try {
obj.read(new byte[0], -1, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
index 36c315c..a2e4084 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
@@ -167,11 +167,8 @@
try {
pos = new PipedOutputStream(pis);
pos.write(new byte[0], -1, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
// Regression for HARMONY-4311
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedWriterTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedWriterTest.java
index 9d3b344..cc0881a 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedWriterTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedWriterTest.java
@@ -201,10 +201,7 @@
obj = new java.io.PipedWriter(pr);
obj.write(new char[0], (int) 0, (int) -1);
fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
+ } catch (IndexOutOfBoundsException expected) {
}
}
@@ -217,10 +214,8 @@
try {
obj = new java.io.PipedWriter(pr);
obj.write(new char[0], (int) -1, (int) 0);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {}
+ fail();
+ } catch (IndexOutOfBoundsException expected) {}
}
/**
@@ -232,10 +227,8 @@
try {
obj = new java.io.PipedWriter(pr);
obj.write(new char[0], (int) -1, (int) -1);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {}
+ fail();
+ } catch (IndexOutOfBoundsException expected) {}
}
/**
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringWriterTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringWriterTest.java
index 7adcbb7..e7b21b7 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringWriterTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringWriterTest.java
@@ -98,11 +98,8 @@
try {
obj = new StringWriter();
obj.write(new char[0], (int) 0, (int) -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
@@ -114,10 +111,8 @@
try {
obj = new StringWriter();
obj.write(new char[0], (int) -1, (int) 0);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
@@ -129,10 +124,8 @@
try {
obj = new StringWriter();
obj.write(new char[0], (int) -1, (int) -1);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterImplTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterImplTest.java
index 7d9b3af..83a02e7 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterImplTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterImplTest.java
@@ -22,7 +22,7 @@
public void test_valueOfC() {
// test the cache range
- for (char c = '\u0000'; c < 512; c++) {
+ for (char c = '\u0000'; c < 128; c++) {
Character e = new Character(c);
Character a = Character.valueOf(c);
assertEquals(e, a);
@@ -31,7 +31,7 @@
assertSame(Character.valueOf(c), Character.valueOf(c));
}
// test the rest of the chars
- for (int c = '\u0512'; c <= Character.MAX_VALUE; c++) {
+ for (int c = 128; c <= Character.MAX_VALUE; c++) {
assertEquals(new Character((char) c), Character.valueOf((char) c));
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterTest.java
index b8db707..2f3d4a6 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/CharacterTest.java
@@ -22,19 +22,6 @@
public class CharacterTest extends TestCase {
- public void test_valueOfC() {
- // test the cache range
- for (char c = '\u0000'; c < 512; c++) {
- Character e = new Character(c);
- Character a = Character.valueOf(c);
- assertEquals(e, a);
- }
- // test the rest of the chars
- for (int c = 512; c <= Character.MAX_VALUE; c++) {
- assertEquals(new Character((char) c), Character.valueOf((char) c));
- }
- }
-
public void test_isValidCodePointI() {
assertFalse(Character.isValidCodePoint(-1));
assertTrue(Character.isValidCodePoint(0));
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java
index fc7726c..540ffe2 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/ProcessBuilderTest.java
@@ -121,10 +121,10 @@
// expected;
}
try {
- env.get(new Object());
- fail("should throw ClassCastException.");
- } catch (ClassCastException e) {
- // expected;
+ assertNull(env.get(new Object()));
+ // Android's get doesn't throw (because it's just a regular HashMap).
+ // fail("should throw ClassCastException.");
+ } catch (ClassCastException thrownByRi) {
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
index f79503e..e359d4f 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
@@ -347,18 +347,8 @@
// Test for method byte [] java.lang.String.getBytes()
byte[] sbytes = hw1.getBytes();
- boolean isEbcdic = Charset.defaultCharset().equals(Charset.forName("IBM1047"));
- if (!isEbcdic) {
- for (int i = 0; i < hw1.length(); i++)
- assertTrue("Returned incorrect bytes", sbytes[i] == (byte) hw1
- .charAt(i));
- } else {
- // On EBCDIC platforms, getBytes() returns different values
- // Reference values taken from J9 5.0
- byte[] expectedValues = {-56, -123, -109, -109, -106, -26, -106,
- -103, -109, -124};
- for (int i = 0; i < hw1.length(); i++)
- assertEquals(expectedValues[i], sbytes[i]);
+ for (int i = 0; i < hw1.length(); i++) {
+ assertTrue("Returned incorrect bytes", sbytes[i] == (byte) hw1.charAt(i));
}
char[] chars = new char[1];
@@ -435,17 +425,7 @@
// int)
byte[] buf = new byte[5];
"Hello World".getBytes(6, 11, buf, 0);
-
- boolean isEbcdic = Charset.defaultCharset().equals(Charset.forName("IBM1047"));
- if (!isEbcdic) {
- assertEquals("Returned incorrect bytes", "World", new String(buf));
- } else {
- // On EBCDIC platforms, getBytes() returns different values
- // Reference values taken from J9 5.0
- byte[] expectedValues = {87, 111, 114, 108, 100};
- for (int i = 0; i < 5; i++)
- assertEquals(expectedValues[i], buf[i]);
- }
+ assertEquals("Returned incorrect bytes", "World", new String(buf));
try {
"Hello World".getBytes(-1, 1, null, 0);
@@ -498,8 +478,8 @@
try {
"abc".getBytes((String) null);
fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
+ } catch (UnsupportedEncodingException whatTheRiDocumentsAndWeThrow) {
+ } catch (NullPointerException whatTheRiActuallyThrows) {
}
try {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java
index 6085b36..2ef6812 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java
@@ -352,9 +352,9 @@
StringBuffer buf1 = new StringBuffer("abcd");
try {
buf1.insert(-1, (char[]) null, 0, 0);
- fail("Should throw StringIndexOutOfBoundsException");
- } catch (StringIndexOutOfBoundsException e) {
- //expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (StringIndexOutOfBoundsException expected) {
}
try {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringTest.java
index bec23fd..e0a84a1 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/StringTest.java
@@ -20,6 +20,7 @@
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.nio.charset.Charset;
+import java.util.Arrays;
import java.util.SortedMap;
import junit.framework.TestCase;
@@ -633,15 +634,15 @@
}
try {
new String(null, -1, 0, Charset.defaultCharset());
- fail("should throw StringIndexOutOfBoundsException");
- } catch (StringIndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (StringIndexOutOfBoundsException expected) {
}
try {
new String(null, 0, -1, Charset.defaultCharset());
- fail("should throw StringIndexOutOfBoundsException");
- } catch (StringIndexOutOfBoundsException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (StringIndexOutOfBoundsException expected) {
}
try {
new String(null, 0, 9, Charset.defaultCharset());
@@ -663,15 +664,15 @@
}
try {
new String(new byte[8], -1, 0, (Charset)null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (StringIndexOutOfBoundsException expected) {
}
try {
new String(new byte[8], 0, 9, (Charset)null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
+ fail();
+ } catch (NullPointerException expected) {
+ } catch (StringIndexOutOfBoundsException expected) {
}
try {
new String(new byte[8], 0, 4, (Charset)null);
@@ -736,24 +737,9 @@
}
assertTrue(bytesEquals(someBytes,new String(someBytes, Charset.defaultCharset()).getBytes(Charset.defaultCharset())));
SortedMap<String, Charset> charsets = Charset.availableCharsets();
-
- Charset ascii = charsets.get("US-ASCII");
- Charset utf8 = charsets.get("UTF-8");
- if (charsets.size() >= 2){
- assertTrue(bytesEquals(someBytes,new String(someBytes, charsets.get(charsets.firstKey())).getBytes(charsets.get(charsets.lastKey()))));
- assertFalse(bytesEquals("\u4f60\u597d".getBytes(ascii), "\u4f60\u597d".getBytes(utf8)));
- }
}
boolean bytesEquals(byte[] bytes1, byte[] bytes2){
- if (bytes1.length == bytes2.length){
- for (int i = 0; i < bytes1.length; i++){
- if (bytes1[i] != bytes2[i]){
- return false;
- }
- }
- return true;
- }
- return false;
+ return Arrays.toString(bytes1).equals(Arrays.toString(bytes2));
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/SystemTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/SystemTest.java
index 900e258..9b8b699 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/SystemTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/SystemTest.java
@@ -125,8 +125,6 @@
public void test_getProperties() {
// Test for method java.util.Properties java.lang.System.getProperties()
Properties p = System.getProperties();
- assertTrue("Incorrect properties returned", p.getProperty(
- "java.version").indexOf("1.", 0) >= 0);
// Ensure spec'ed properties are non-null. See System.getProperties()
// spec.
@@ -150,8 +148,6 @@
public void test_getPropertyLjava_lang_String() {
// Test for method java.lang.String
// java.lang.System.getProperty(java.lang.String)
- assertTrue("Failed to return correct property value", System
- .getProperty("java.version").indexOf("1.", 0) >= 0);
boolean is8859_1 = true;
String encoding = System.getProperty("file.encoding");
@@ -208,9 +204,7 @@
public void test_getPropertyLjava_lang_StringLjava_lang_String() {
// Test for method java.lang.String
// java.lang.System.getProperty(java.lang.String, java.lang.String)
- assertTrue("Failed to return correct property value: "
- + System.getProperty("java.version", "99999"), System
- .getProperty("java.version", "99999").indexOf("1.", 0) >= 0);
+ assertTrue(!System.getProperty("java.version", "99999").equals("99999"));
assertEquals("Failed to return correct property value", "bogus", System
.getProperty("bogus.prop", "bogus"));
}
@@ -387,9 +381,9 @@
try {
map.remove(null);
- fail("Should throw UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // expected
+ // Android isn't as strict about requiring this exception; no modification takes place anyway
+ // fail("Should throw UnsupportedOperationException.");
+ } catch (UnsupportedOperationException expected) {
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
index d705804..85ef09e 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
@@ -47,7 +47,7 @@
InetAddress.getByName("unknown.unknown.bad");
fail("An UnknownHostException should have been thrown");
} catch (UnknownHostException e) {
- assertEquals("unknown.unknown.bad", e.getMessage());
+ assertTrue(e.getMessage().contains("unknown.unknown.bad"));
}
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
index 7d24765..639097c 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
@@ -853,6 +853,7 @@
Vector v = new Vector();
v.add("a");
ArrayList al = new ArrayList(v);
+ al.add("b");
Iterator it = al.iterator();
al.trimToSize();
try {
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/CollectionsTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
index 0555a78..1b13380 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
@@ -43,7 +43,6 @@
import java.util.TreeSet;
import java.util.Arrays;
-import org.apache.harmony.luni.internal.nls.Messages;
import org.apache.harmony.testframework.serialization.SerializationTest;
import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
@@ -1977,11 +1976,8 @@
try {
m.invoke(null, new Object(), int.class);
- fail("should throw InvocationTargetException");
- } catch (InvocationTargetException e) {
- String errMsg = Messages.getString(
- "luni.05", Object.class, int.class);
- assertEquals(errMsg, e.getCause().getMessage());
+ fail();
+ } catch (InvocationTargetException expected) {
}
}
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java
index 5468914..92698bb 100644
--- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java
+++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java
@@ -991,21 +991,23 @@
Formatter f = null;
String oldSeparator = System.getProperty("line.separator");
- System.setProperty("line.separator", "!\n");
+ try {
+ System.setProperty("line.separator", "!\n");
- f = new Formatter(Locale.US);
- f.format("%1$n", 1);
- assertEquals("!\n", f.toString());
+ f = new Formatter(Locale.US);
+ f.format("%1$n", 1);
+ assertEquals("!\n", f.toString());
- f = new Formatter(Locale.KOREAN);
- f.format("head%1$n%2$n", 1, new Date());
- assertEquals("head!\n!\n", f.toString());
+ f = new Formatter(Locale.KOREAN);
+ f.format("head%1$n%2$n", 1, new Date());
+ assertEquals("head!\n!\n", f.toString());
- f = new Formatter(Locale.US);
- f.format("%n%s", "hello");
- assertEquals("!\nhello", f.toString());
-
- System.setProperty("line.separator", oldSeparator);
+ f = new Formatter(Locale.US);
+ f.format("%n%s", "hello");
+ assertEquals("!\nhello", f.toString());
+ } finally {
+ System.setProperty("line.separator", oldSeparator);
+ }
f = new Formatter(Locale.US);
try {
@@ -2752,48 +2754,38 @@
*/
f = new Formatter(Locale.US);
try {
- // compare IllegalFormatConversionException and
- // FormatFlagsConversionMismatchException
f.format("%(o", false);
- fail("should throw IllegalFormatConversionException");
- } catch (IllegalFormatConversionException e) {
- // expected
+ fail();
+ } catch (FormatFlagsConversionMismatchException expected) {
+ } catch (IllegalFormatConversionException expected) {
}
try {
- // compare IllegalFormatPrecisionException and
- // IllegalFormatConversionException
f.format("%.4o", false);
- fail("should throw IllegalFormatPrecisionException");
- } catch (IllegalFormatPrecisionException e) {
- // expected
+ fail();
+ } catch (IllegalFormatPrecisionException expected) {
+ } catch (IllegalFormatConversionException expected) {
}
try {
- // compare IllegalFormatFlagsException and
- // IllegalFormatPrecisionException
f.format("%+ .4o", big);
- fail("should throw IllegalFormatFlagsException");
- } catch (IllegalFormatFlagsException e) {
- // expected
+ fail();
+ } catch (IllegalFormatPrecisionException expected) {
+ } catch (IllegalFormatFlagsException expected) {
}
try {
- // compare MissingFormatWidthException and
- // IllegalFormatFlagsException
f.format("%+ -o", big);
- fail("should throw MissingFormatWidthException");
- } catch (MissingFormatWidthException e) {
- // expected
+ fail();
+ } catch (MissingFormatWidthException expected) {
+ } catch (IllegalFormatFlagsException expected) {
}
try {
- // compare UnknownFormatConversionException and
- // MissingFormatWidthException
f.format("%-O", big);
- fail("should throw UnknownFormatConversionException");
- } catch (UnknownFormatConversionException e) {
- // expected
+ fail();
+ } catch (MissingFormatWidthException expected) {
+ } catch (UnknownFormatConversionException expected) {
}
}
diff --git a/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java b/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java
index 8421fc5..3838991 100644
--- a/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java
+++ b/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java
@@ -244,8 +244,6 @@
new BigDecimal(a);
fail("NumberFormatException has not been caught");
} catch (NumberFormatException e) {
- assertEquals("Improper exception message", "Infinite or NaN", e
- .getMessage());
}
}
@@ -258,8 +256,6 @@
new BigDecimal(a);
fail("NumberFormatException has not been caught");
} catch (NumberFormatException e) {
- assertEquals("Improper exception message", "Infinite or NaN",
- e.getMessage());
}
}
@@ -272,8 +268,6 @@
new BigDecimal(a);
fail("NumberFormatException has not been caught");
} catch (NumberFormatException e) {
- assertEquals("Improper exception message", "Infinite or NaN",
- e.getMessage());
}
}
@@ -491,8 +485,6 @@
new BigDecimal(a);
fail("NumberFormatException expected");
} catch (NumberFormatException e) {
- assertEquals("Improper exception message","Scale out of range.",
- e.getMessage());
}
}
diff --git a/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java b/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java
index 3dd7417..6c74dee 100644
--- a/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java
+++ b/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java
@@ -332,7 +332,6 @@
aNumber.movePointRight(shift);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "Underflow", e.getMessage());
}
}
diff --git a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java
index ac3eb16..051ba5e 100644
--- a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java
+++ b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java
@@ -40,7 +40,6 @@
new BigInteger(aBytes);
fail("NumberFormatException has not been caught");
} catch (NumberFormatException e) {
- assertEquals("Improper exception message", "Zero length BigInteger", e.getMessage());
}
}
@@ -198,7 +197,6 @@
new BigInteger(aSign, aBytes);
fail("NumberFormatException has not been caught");
} catch (NumberFormatException e) {
- assertEquals("Improper exception message", "Invalid signum value", e.getMessage());
}
}
@@ -580,7 +578,6 @@
new BigInteger(value, radix);
fail("NumberFormatException has not been caught");
} catch (NumberFormatException e) {
- assertEquals("Improper exception message", "Radix out of range", e.getMessage());
}
}
diff --git a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java
index 7656d87..3f2ab51 100644
--- a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java
+++ b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java
@@ -42,7 +42,6 @@
aNumber.divide(bNumber);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
}
}
@@ -58,7 +57,6 @@
aNumber.divide(bNumber);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
}
}
@@ -411,7 +409,6 @@
aNumber.remainder(bNumber);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
}
}
@@ -624,7 +621,6 @@
aNumber.mod(bNumber);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
}
}
diff --git a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java
index a5985c3..4af4d9d 100644
--- a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java
+++ b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java
@@ -45,7 +45,6 @@
aNumber.modPow(exp, modulus);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
}
try {
@@ -139,7 +138,6 @@
aNumber.modInverse(modulus);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
}
}
@@ -157,7 +155,6 @@
aNumber.modInverse(modulus);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "BigInteger not invertible.", e.getMessage());
}
}
diff --git a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java
index 1912345..0bfcbf0 100644
--- a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java
+++ b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java
@@ -285,7 +285,6 @@
aNumber.pow(exp);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "Negative exponent", e.getMessage());
}
}
diff --git a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java
index abc934f..9b7c198 100644
--- a/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java
+++ b/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java
@@ -133,7 +133,6 @@
aNumber.clearBit(number);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "Negative bit address", e.getMessage());
}
}
@@ -440,7 +439,6 @@
aNumber.flipBit(number);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "Negative bit address", e.getMessage());
}
}
@@ -730,7 +728,6 @@
aNumber.setBit(number);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "Negative bit address", e.getMessage());
}
}
@@ -1307,7 +1304,6 @@
aNumber.testBit(number);
fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
- assertEquals("Improper exception message", "Negative bit address", e.getMessage());
}
}
diff --git a/math/src/test/java/tests/api/java/math/BigDecimalTest.java b/math/src/test/java/tests/api/java/math/BigDecimalTest.java
index c6be15e..4fd27bf 100644
--- a/math/src/test/java/tests/api/java/math/BigDecimalTest.java
+++ b/math/src/test/java/tests/api/java/math/BigDecimalTest.java
@@ -912,12 +912,11 @@
((notrailingzerotest.stripTrailingZeros()).scale() == 0)
);
+ // BEGIN android-changed: preserve RI compatibility, so BigDecimal.equals (which checks
+ // value *and* scale) continues to work. https://issues.apache.org/jira/browse/HARMONY-4623
/* Zero */
- //regression for HARMONY-4623, NON-BUG DIFF with RI
BigDecimal zerotest = new BigDecimal("0.0000");
- assertTrue("stripTrailingZero failed for 0.0000",
- ((zerotest.stripTrailingZeros()).scale() == 0)
- );
+ assertEquals("stripTrailingZero failed for 0.0000", 4, zerotest.stripTrailingZeros().scale());
}
public void testMathContextConstruction() {
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
index aa9c63e..8a7c5f3 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
@@ -381,8 +381,8 @@
try {
buf.get(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferUnderflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
buf.get(array, Integer.MAX_VALUE, 1);
@@ -540,8 +540,8 @@
try {
buf.put(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferOverflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
assertEquals(buf.position(), 0);
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
index 5759b36..40ff2e0 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
@@ -349,8 +349,8 @@
try {
buf.get(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferUnderflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
buf.get(array, Integer.MAX_VALUE, 1);
@@ -510,8 +510,8 @@
try {
buf.put(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferOverflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
assertEquals(buf.position(), 0);
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
index d88a188..cfef096 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
@@ -347,8 +347,8 @@
try {
buf.get(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferUnderflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
buf.get(array, Integer.MAX_VALUE, 1);
@@ -515,8 +515,8 @@
try {
buf.put(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferOverflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
assertEquals(buf.position(), 0);
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
index db53516..97babcf 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
@@ -325,8 +325,8 @@
try {
buf.get(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferUnderflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
buf.get(array, Integer.MAX_VALUE, 1);
@@ -491,8 +491,8 @@
try {
buf.put(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferOverflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
assertEquals(buf.position(), 0);
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
index 44ca39e..371351b 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
@@ -326,8 +326,8 @@
try {
buf.get(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferUnderflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
buf.get(array, Integer.MAX_VALUE, 1);
@@ -498,8 +498,8 @@
try {
buf.put(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferOverflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
assertEquals(buf.position(), 0);
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
index e84cc9c..f951962 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
@@ -173,14 +173,14 @@
try {
buf.put((String) null, 0, 0);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (NullPointerException e) {
- // expected
+ } catch (ReadOnlyBufferException expected) {
+ } catch (NullPointerException expected) {
}
try {
buf.put(str, -1, str.length());
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (ReadOnlyBufferException expected) {
+ } catch (NullPointerException expected) {
}
String longStr = String.valueOf(new char[buf.capacity()+1]);
try {
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
index 6ff3ce3..98d7659 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
@@ -312,8 +312,8 @@
try {
buf.get(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferUnderflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
buf.get(array, Integer.MAX_VALUE, 1);
@@ -478,8 +478,8 @@
try {
buf.put(array, 1, Integer.MAX_VALUE);
fail("Should throw Exception"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (BufferOverflowException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
assertEquals(buf.position(), 0);
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
index 1e98d63..c0a4aac 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
@@ -88,20 +88,20 @@
try {
buf.put((char[]) null, 0, 1);
fail("Should throw NullPointerException"); //$NON-NLS-1$
- } catch (NullPointerException e) {
- // expected
+ } catch (ReadOnlyBufferException expected) {
+ } catch (NullPointerException expected) {
}
try {
buf.put(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
fail("Should throw BufferOverflowException"); //$NON-NLS-1$
- } catch (BufferOverflowException e) {
- // expected
+ } catch (ReadOnlyBufferException expected) {
+ } catch (BufferOverflowException expected) {
}
try {
buf.put(array, -1, array.length);
fail("Should throw IndexOutOfBoundsException"); //$NON-NLS-1$
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (ReadOnlyBufferException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
}
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java
index 35ecebf..4223fb8 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java
@@ -116,13 +116,12 @@
ByteBuffer byteBuf = ByteBuffer.allocate(this.testNum);
this.fins = null;
int readres = this.testNum;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- assertNotNull(rbChannel);
try {
+ ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
+ assertNotNull(rbChannel);
readres = rbChannel.read(byteBuf);
fail();
- } catch (NullPointerException e) {
- // correct
+ } catch (NullPointerException expected) {
}
assertEquals(this.testNum, readres);
}
@@ -188,15 +187,15 @@
writebuf.putChar((char) (val + 64));
}
this.fouts = null;
- WritableByteChannel rbChannel = Channels.newChannel(this.fouts);
- writeres = rbChannel.write(writebuf);
- assertEquals(0, writeres);
-
- writebuf.flip();
try {
+ WritableByteChannel rbChannel = Channels.newChannel(this.fouts);
+ writeres = rbChannel.write(writebuf);
+ assertEquals(0, writeres);
+
+ writebuf.flip();
writeres = rbChannel.write(writebuf);
fail("Should throw NPE.");
- } catch (NullPointerException e) {
+ } catch (NullPointerException expected) {
}
}
@@ -275,23 +274,14 @@
ReadableByteChannel readbc = this.fins.getChannel();
assertEquals(this.fileSize, this.fins.available());
assertTrue(readbc.isOpen());
- InputStream testins = Channels.newInputStream(null);
- assertNotNull(testins);
try {
+ InputStream testins = Channels.newInputStream(null);
+ assertNotNull(testins);
testins.read(readbuf);
fail();
- } catch (NullPointerException e) {
- // correct
+ } catch (NullPointerException expected) {
}
- assertEquals(0, testins.available());
- try {
- testins.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
-
}
public void testNewInputStreamReadableByteChannel() throws Exception {
@@ -324,29 +314,20 @@
public void testNewOutputStreamWritableByteChannel_InputNull()
throws Exception {
byte[] writebuf = new byte[this.testNum];
- OutputStream testouts = Channels.newOutputStream(null);
- assertNotNull(testouts);
try {
+ OutputStream testouts = Channels.newOutputStream(null);
+ assertNotNull(testouts);
testouts.write(writebuf);
fail();
- } catch (NullPointerException e) {
- // correct
+ } catch (NullPointerException expected) {
}
- testouts.flush();
try {
- testouts.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- WritableByteChannel writebc = Channels.newChannel((OutputStream) null);
- assertTrue(writebc.isOpen());
- OutputStream testoutputS = Channels.newOutputStream(writebc);
- try {
+ WritableByteChannel writebc = Channels.newChannel((OutputStream) null);
+ assertTrue(writebc.isOpen());
+ OutputStream testoutputS = Channels.newOutputStream(writebc);
testoutputS.write(writebuf);
fail();
- } catch (NullPointerException e) {
- // correct
+ } catch (NullPointerException expected) {
}
}
@@ -414,33 +395,25 @@
CharBuffer charBuf = CharBuffer.allocate(bufSize);
this.fins = new FileInputStream(tmpFile);
// channel null
- Reader testReader = Channels.newReader(null, Charset.forName(CODE_SET)
- .newDecoder(), -1);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
+ Reader testReader;
try {
+ testReader = Channels.newReader(null, Charset.forName(CODE_SET).newDecoder(), -1);
+ assertNotNull(testReader);
+ assertFalse(testReader.ready());
readres = testReader.read((CharBuffer) null);
fail();
} catch (NullPointerException e) {
// correct
}
assertEquals(0, readres);
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
this.fins = null;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
// channel with null inputs
- testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET)
- .newDecoder(), //$NON-NLS-1$
- -1);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
try {
+ ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
+ testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET).newDecoder(), -1);
+ assertNotNull(testReader);
+ assertFalse(testReader.ready());
readres = testReader.read(charBuf);
fail();
} catch (NullPointerException e) {
@@ -459,33 +432,24 @@
CharBuffer charBuf = CharBuffer.allocate(bufSize);
this.fins = new FileInputStream(tmpFile);
// channel null
- Reader testReader = Channels.newReader(null, Charset.forName(CODE_SET)
- .newDecoder(), //$NON-NLS-1$
- 0);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
+ Reader testReader;
try {
+ testReader = Channels.newReader(null, Charset.forName(CODE_SET).newDecoder(), 0);
+ assertNotNull(testReader);
+ assertFalse(testReader.ready());
readres = testReader.read((CharBuffer) null);
fail();
- } catch (NullPointerException e) {
- // correct
+ } catch (NullPointerException expected) {
}
assertEquals(0, readres);
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
+
this.fins = null;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
// channel with null inputs
- testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET)
- .newDecoder(), //$NON-NLS-1$
- -1);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
try {
+ ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
+ testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET).newDecoder(), -1);
+ assertNotNull(testReader);
+ assertFalse(testReader.ready());
readres = testReader.read(charBuf);
fail();
} catch (NullPointerException e) {
@@ -541,43 +505,16 @@
writebuf = writebuf + ((char) (val + 64));
}
// null channel
- Writer testWriter = Channels.newWriter(null, Charset.forName(CODE_SET)
- .newEncoder(), //$NON-NLS-1$
- -1);
- // can write to buffer
- testWriter.write(writebuf);
try {
- testWriter.flush();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- try {
- testWriter.close();
- fail();
- } catch (NullPointerException e) {
- // correct
+ Writer testWriter = Channels.newWriter(null, Charset.forName(CODE_SET).newEncoder(), -1);
+ } catch (NullPointerException expected) {
}
// channel with null input
this.fouts = null;
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- testWriter = Channels.newWriter(wbChannel, Charset.forName(CODE_SET)
- .newEncoder(), //$NON-NLS-1$
- -1);
- // can write to buffer
- testWriter.write(writebuf);
try {
- testWriter.flush();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- try {
- testWriter.close();
- fail();
- } catch (NullPointerException e) {
- // correct
+ WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
+ } catch (NullPointerException expected) {
}
}
@@ -668,14 +605,16 @@
assertFalse(sc.isBlocking());
Reader reader = Channels.newReader(sc, "UTF16");
- int i = reader.read();
- assertEquals(-1, i);
+ try {
+ int i = reader.read();
+ fail("should throw IllegalBlockingModeException");
+ } catch (IllegalBlockingModeException expected) {
+ }
try {
Channels.newInputStream(sc).read();
fail("should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
+ } catch (IllegalBlockingModeException expected) {
}
sc.close();
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
index 9875753..91d7eff 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
@@ -356,7 +356,7 @@
assertFalse(s.getBroadcast());
assertFalse(s.getReuseAddress());
assertNull(s.getInetAddress());
- assertEquals(s.getLocalAddress().getHostAddress(), "0.0.0.0");
+ assertEquals(s.getLocalAddress().isAnyLocalAddress());
assertEquals(s.getLocalPort(), 0);
assertNull(s.getLocalSocketAddress());
assertEquals(s.getPort(), -1);
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java
index e94d76e..100085b 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java
@@ -610,8 +610,8 @@
Calendar.JANUARY, 1, 0, 0, 59).getTime(), 0, 4);
test.parse("m:s", "59:0", new GregorianCalendar(1970, Calendar.JANUARY,
1, 0, 59, 0).getTime(), 0, 4);
-// test.parse("ms", "059", new GregorianCalendar(1970, Calendar.JANUARY,
-// 1, 0, 0, 59).getTime(), 0, 3);
+ test.parse("ms", "059", new GregorianCalendar(1970, Calendar.JANUARY,
+ 1, 0, 0, 59).getTime(), 0, 3);
cal = new GregorianCalendar(1970, Calendar.JANUARY, 1);
test.parse("S", "0", cal.getTime(), 0, 1);
@@ -621,7 +621,7 @@
cal = new GregorianCalendar(1970, Calendar.JANUARY, 1);
cal.set(Calendar.ERA, GregorianCalendar.BC);
-// test.parse("G", "Bc ", cal.getTime(), 0, 2);
+ test.parse("G", "Bc ", cal.getTime(), 0, 2);
test.parse("y", "00", new GregorianCalendar(2000, Calendar.JANUARY, 1)
.getTime(), 0, 2);