Author: kkolinko
Date: Tue Jan 5 13:53:27 2016
New Revision: 1723071
URL: http://svn.apache.org/viewvc?rev=1723071&view=rev
Log:
Convert the test to JUnit 4 and backport a working testcase from Tomcat 7.
I am not backporting testEmptyArray() fix (r1143022). Added a comment
explaining this decision.
Modified:
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/io/TestXByteBuffer.java
Modified:
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/io/TestXByteBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/io/TestXByteBuffer.java?rev=1723071&r1=1723070&r2=1723071&view=diff
==============================================================================
---
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/io/TestXByteBuffer.java
(original)
+++
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/io/TestXByteBuffer.java
Tue Jan 5 13:53:27 2016
@@ -16,24 +16,42 @@
*/
package org.apache.catalina.tribes.io;
-import junit.framework.TestCase;
+import org.junit.Test;
-public class TestXByteBuffer extends TestCase {
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- public void testEmptyArray() throws Exception {
-
- }
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public static void main(String[] args) throws Exception {
- //XByteBuffer.deserialize(new byte[0]);
- XByteBuffer.deserialize(new byte[] {-84, -19, 0, 5, 115, 114, 0, 17,
106});
+public class TestXByteBuffer {
+
+ // In Tomcat 6 the testEmptyArray() test fails with a java.io.EOFException.
+ //
+ // Backporting r1143022 (support for 0-length array in deserialize())
+ // to Tomcat 6 is probably a bad idea, as
+ //
+ // 1. All valid use cases already check for (length == 0) case before
+ // calling deserialize(), so adding a second check there is redundant
+ //
+ // 2. It will change behaviour of GroupChannel.messageReceived(),
+ // as deserialize() call there will no longer fail with an exception.
+ //
+ // The change will be that instead of logging an error and returning
+ // doing nothing, the messageReceived() method will go on and will notify
+ // a channelListener. I do not know whether the listener is able to handle
+ // a null argument.
+ //
+ // @Test
+ // public void testEmptyArray() throws Exception {
+ // Object obj = XByteBuffer.deserialize(new byte[0]);
+ // assertNull(obj);
+ // }
+
+ @Test
+ public void testSerializationString() throws Exception {
+ String test = "This is as test.";
+ byte[] msg = XByteBuffer.serialize(test);
+ Object obj = XByteBuffer.deserialize(msg);
+ assertTrue(obj instanceof String);
+ assertEquals(test, obj);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]