BATCH-310: BatchStatus now implements Serializable with a readResolve(). Added a test case for serialization.

This commit is contained in:
lucasward
2008-01-23 17:44:46 +00:00
parent 2731c3299c
commit 1a7fdce73b
2 changed files with 64 additions and 20 deletions

View File

@@ -15,6 +15,11 @@
*/
package org.springframework.batch.core.domain;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import junit.framework.TestCase;
/**
@@ -41,6 +46,27 @@ public class BatchStatusTests extends TestCase {
* Test method for {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}.
*/
public void testGetStatusWrongCode() {
assertEquals(null, BatchStatus.getStatus("foo"));
try{
BatchStatus.getStatus("foo");
fail();
}
catch(IllegalArgumentException ex){
//expected
}
}
public void testSerialization() throws Exception{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream (bout);
out.writeObject (BatchStatus.COMPLETED);
out.flush ();
ByteArrayInputStream bin = new ByteArrayInputStream (bout.toByteArray());
ObjectInputStream in = new ObjectInputStream(bin);
BatchStatus status = (BatchStatus) in.readObject ();
assertEquals(BatchStatus.COMPLETED, status);
}
}