You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/08/18 05:37:29 UTC
svn commit: r432476 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java:
io/ lang/
Author: ndbeyer
Date: Thu Aug 17 20:37:28 2006
New Revision: 432476
URL: http://svn.apache.org/viewvc?rev=432476&view=rev
Log:
Cleanup tests, remove compiler warning, correct JUnit usage and deleted duplicate test
Removed:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayCopyTest.java
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java?rev=432476&r1=432475&r2=432476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java Thu Aug 17 20:37:28 2006
@@ -95,6 +95,7 @@
count = bytes.length;
}
+ @Override
public int read() {
if (count == 0) {
return -1;
@@ -103,6 +104,7 @@
return bytes[bytes.length - count];
}
+ @Override
public int read(byte[] buffer, int offset, int length) {
if (count == 0) {
return -1;
@@ -115,6 +117,7 @@
return 1;
}
+ @Override
public int available() {
return count;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java?rev=432476&r1=432475&r2=432476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java Thu Aug 17 20:37:28 2006
@@ -82,23 +82,29 @@
length = contents.length;
}
+ @Override
public void close() throws IOException {
contents = null;
}
+ @Override
public int read(char[] buf, int offset, int count) throws IOException {
- if (null == contents)
+ if (null == contents) {
return -1;
- if (length <= current_offset)
+ }
+ if (length <= current_offset) {
return -1;
- if (buf.length < offset + count)
+ }
+ if (buf.length < offset + count) {
throw new IndexOutOfBoundsException();
+ }
count = Math.min(count, length - current_offset);
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++) {
buf[offset + i] = contents[current_offset + i];
+ }
current_offset += count;
return count;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java?rev=432476&r1=432475&r2=432476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java Thu Aug 17 20:37:28 2006
@@ -43,15 +43,18 @@
myLock = lock;
}
- public synchronized void close() throws IOException {
+ @Override
+ public synchronized void close() throws IOException {
// do nothing
}
- public synchronized void flush() throws IOException {
+ @Override
+ public synchronized void flush() throws IOException {
// do nothing
}
- public void write(char[] arg0, int arg1, int arg2) throws IOException {
+ @Override
+ public void write(char[] arg0, int arg1, int arg2) throws IOException {
assertTrue(Thread.holdsLock(myLock));
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java?rev=432476&r1=432475&r2=432476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java Thu Aug 17 20:37:28 2006
@@ -15,55 +15,25 @@
package org.apache.harmony.luni.tests.java.lang;
-public class ArithmeticExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.lang.ArithmeticException#ArithmeticException()
- */
- public void test_Constructor() {
- // Test for method java.lang.ArithmeticException()
- try {
- try {
- int i = 100;
- i /= 0;
- } catch (ArithmeticException e) {
- return;
- }
- fail("Failed to generate expected exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
+public class ArithmeticExceptionTest extends TestCase {
- /**
- * @tests java.lang.ArithmeticException#ArithmeticException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.ArithmeticException(java.lang.String)
- try {
- try {
- int i = 100;
- i /= 0;
- } catch (ArithmeticException e) {
- return;
- }
- fail("Failed to generate expected exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
+ /**
+ * @tests java.lang.ArithmeticException#ArithmeticException()
+ */
+ public void test_Constructor() {
+ ArithmeticException e = new ArithmeticException();
+ assertNull(e.getMessage());
+ assertNull(e.getCause());
+ }
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.lang.ArithmeticException#ArithmeticException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ ArithmeticException e = new ArithmeticException("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java?rev=432476&r1=432475&r2=432476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java Thu Aug 17 20:37:28 2006
@@ -15,70 +15,36 @@
package org.apache.harmony.luni.tests.java.lang;
-public class ArrayIndexOutOfBoundsExceptionTest extends
- junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException()
- */
- public void test_Constructor() {
- // Test for method java.lang.ArrayIndexOutOfBoundsException()
- int r = 0;
- try {
- byte[] b = new byte[1];
- byte z = b[2];
- if (z > 0)
- ; // use z so we don't get an unused variable warning
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("failed to generate ArrayIndexOutOfBoundsException", 1, r);
- }
-
- /**
- * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException(int)
- */
- public void test_ConstructorI() {
- try {
- if (true)
- throw new ArrayIndexOutOfBoundsException(-1);
- } catch (ArrayIndexOutOfBoundsException e) {
- assertTrue(
- "toString of ArrayIndexOutOfBoundsException did not reveal offending position",
- e.toString().indexOf("-1", 0) >= 0);
- }
- }
-
- /**
- * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method
- // java.lang.ArrayIndexOutOfBoundsException(java.lang.String)
- int r = 0;
- try {
- byte[] b = new byte[1];
- byte z = b[2];
- if (z > 0)
- ; // use z so we don't get an unused variable warning
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("failed to generate ArrayIndexOutOfBoundsException", 1, r);
-
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
+public class ArrayIndexOutOfBoundsExceptionTest extends TestCase {
/**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException(int)
+ */
+ public void test_ConstructorI() {
+ ArrayIndexOutOfBoundsException e = new ArrayIndexOutOfBoundsException(-1);
+ assertNotNull(e.getMessage());
+ assertTrue("Unable to find index value in 'message' property.", e.getMessage().indexOf(
+ "-1", 0) >= 0);
+
+ }
+
+ /**
+ * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException()
+ */
+ public void test_Constructor() {
+ ArrayIndexOutOfBoundsException e = new ArrayIndexOutOfBoundsException();
+ assertNull(e.getMessage());
+ assertNull(e.getCause());
+ }
+
+ /**
+ * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ ArrayIndexOutOfBoundsException e = new ArrayIndexOutOfBoundsException("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java?rev=432476&r1=432475&r2=432476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java Thu Aug 17 20:37:28 2006
@@ -15,67 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class ArrayStoreExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.lang.ArrayStoreException#ArrayStoreException()
- */
- public void test_Constructor() {
- // Test for method java.lang.ArrayStoreException()
+public class ArrayStoreExceptionTest extends TestCase {
- class ASClass extends Object {
- void store(Object array[], Object elm) {
- array[0] = elm;
- }
- }
-
- try {
- Exception x[] = new Exception[9];
- new ASClass().store(x, new Object());
- } catch (ArrayStoreException e) {
- return;
- } catch (Exception e) {
- fail("Exception during ArrayStoreException test : "
- + e.getMessage());
- }
- fail("Failed to generate expected exception");
- }
-
- /**
- * @tests java.lang.ArrayStoreException#ArrayStoreException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.ArrayStoreException(java.lang.String)
-
- class ASClass extends Object {
- void store(Object array[], Object elm) {
- array[0] = elm;
- }
- }
-
- try {
- Exception x[] = new Exception[9];
- new ASClass().store(x, new Object());
- } catch (ArrayStoreException e) {
- return;
- } catch (Exception e) {
- fail("Exception during ArrayStoreException test : "
- + e.getMessage());
- }
- fail("Failed to generate expected exception");
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.lang.ArrayStoreException#ArrayStoreException()
+ */
+ public void test_Constructor() {
+ ArrayStoreException e = new ArrayStoreException();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
+ }
+
+ /**
+ * @tests java.lang.ArrayStoreException#ArrayStoreException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ ArrayStoreException e = new ArrayStoreException("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java?rev=432476&r1=432475&r2=432476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java Thu Aug 17 20:37:28 2006
@@ -483,9 +483,7 @@
* @tests java.lang.Byte#doubleValue()
*/
public void test_doubleValue2() {
- // Test for method double java.lang.Byte.doubleValue()
- assertTrue("Returned incorrect double value",
- new Byte((byte) 127).doubleValue() == (double) (127));
+ assertEquals(127D, new Byte((byte) 127).doubleValue(), 0.0);
}
/**
@@ -504,9 +502,7 @@
* @tests java.lang.Byte#floatValue()
*/
public void test_floatValue2() {
- // Test for method float java.lang.Byte.floatValue()
- assertTrue("Returned incorrect float value",
- new Byte((byte) 127).byteValue() == (float) (127));
+ assertEquals(127F, new Byte((byte) 127).floatValue(), 0.0);
}
/**
@@ -537,43 +533,29 @@
* @tests java.lang.Byte#parseByte(java.lang.String)
*/
public void test_parseByteLjava_lang_String2() {
- // Test for method byte java.lang.Byte.parseByte(java.lang.String)
+ assertEquals((byte)127, Byte.parseByte("127"));
+ assertEquals((byte)-128, Byte.parseByte("-128"));
+ assertEquals((byte)0, Byte.parseByte("0"));
+ assertEquals((byte)0x80, Byte.parseByte("-128"));
+ assertEquals((byte)0x7F, Byte.parseByte("127"));
- byte b = Byte.parseByte("127");
- byte bn = Byte.parseByte("-128");
- assertTrue("Invalid parse of byte", b == (byte) 127 && (bn == (byte) -128));
- assertEquals("Returned incorrect value for 0", 0, Byte.parseByte("0"));
- assertTrue("Returned incorrect value for most negative value",
- Byte.parseByte("-128") == (byte) 0x80);
- assertTrue("Returned incorrect value for most positive value",
- Byte.parseByte("127") == 0x7f);
-
- boolean exception = false;
try {
Byte.parseByte("-1000");
+ fail("No NumberFormatException");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception", exception);
- exception = false;
try {
Byte.parseByte("128");
+ fail("No NumberFormatException");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
- exception = false;
try {
Byte.parseByte("-129");
+ fail("No NumberFormatException");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
}
/**
@@ -596,66 +578,48 @@
assertTrue("Returned incorrect value for most positive value decimal", Byte.parseByte(
"127", 10) == 0x7f);
- boolean exception = false;
try {
Byte.parseByte("-1000", 10);
+ fail("Failed to throw exception");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception", exception);
- exception = false;
try {
Byte.parseByte("128", 10);
+ fail("Failed to throw exception for MAX_VALUE + 1");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
- exception = false;
try {
Byte.parseByte("-129", 10);
+ fail("Failed to throw exception for MIN_VALUE - 1");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
- exception = false;
try {
Byte.parseByte("80", 16);
+ fail("Failed to throw exception for hex MAX_VALUE + 1");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
+
try {
Byte.parseByte("-81", 16);
+ fail("Failed to throw exception for hex MIN_VALUE + 1");
} catch (NumberFormatException e) {
- // Correct
- exception = true;
}
- assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
}
/**
* @tests java.lang.Byte#shortValue()
*/
public void test_shortValue2() {
- // Test for method short java.lang.Byte.shortValue()
- assertTrue("Returned incorrect short value",
- new Byte((byte) 127).shortValue() == (short) (127));
+ assertEquals((short)127, new Byte((byte)127).shortValue());
}
/**
* @tests java.lang.Byte#toString()
*/
public void test_toString2() {
- // Test for method java.lang.String java.lang.Byte.toString()
assertEquals("Returned incorrect String", "127", new Byte((byte) 127).toString());
assertEquals("Returned incorrect String", "-127", new Byte((byte) -127).toString());
assertEquals("Returned incorrect String", "-128", new Byte((byte) -128).toString());
@@ -665,7 +629,6 @@
* @tests java.lang.Byte#toString(byte)
*/
public void test_toStringB2() {
- // Test for method java.lang.String java.lang.Byte.toString(byte)
assertEquals("Returned incorrect String", "127", Byte.toString((byte) 127));
assertEquals("Returned incorrect String", "-127", Byte.toString((byte) -127));
assertEquals("Returned incorrect String", "-128", Byte.toString((byte) -128));
@@ -675,8 +638,6 @@
* @tests java.lang.Byte#valueOf(java.lang.String)
*/
public void test_valueOfLjava_lang_String2() {
- // Test for method java.lang.Byte
- // java.lang.Byte.valueOf(java.lang.String)
assertEquals("Returned incorrect byte", 0, Byte.valueOf("0").byteValue());
assertEquals("Returned incorrect byte", 127, Byte.valueOf("127").byteValue());
assertEquals("Returned incorrect byte", -127, Byte.valueOf("-127").byteValue());
@@ -684,19 +645,15 @@
try {
Byte.valueOf("128");
+ fail("Failed to throw exception when passes value > byte");
} catch (NumberFormatException e) {
- // Correct
- return;
}
- fail("Failed to throw exception when passes value > byte");
}
/**
* @tests java.lang.Byte#valueOf(java.lang.String, int)
*/
public void test_valueOfLjava_lang_StringI2() {
- // Test for method java.lang.Byte
- // java.lang.Byte.valueOf(java.lang.String, int)
assertEquals("Returned incorrect byte", 10, Byte.valueOf("A", 16).byteValue());
assertEquals("Returned incorrect byte", 127, Byte.valueOf("127", 10).byteValue());
assertEquals("Returned incorrect byte", -127, Byte.valueOf("-127", 10).byteValue());
@@ -707,10 +664,8 @@
try {
Byte.valueOf("128", 10);
+ fail("Failed to throw exception when passes value > byte");
} catch (NumberFormatException e) {
- // Correct
- return;
}
- fail("Failed to throw exception when passes value > byte");
}
}