1 package junit.tests.runner; 2 3 import java.io.ByteArrayInputStream; 4 import java.io.ByteArrayOutputStream; 5 import java.io.IOException; 6 import java.io.ObjectInputStream; 7 import java.io.ObjectOutputStream; 8 9 import junit.framework.TestCase; 10 import junit.tests.framework.Success; 11 import org.junit.runner.JUnitCore; 12 import org.junit.runner.Result; 13 import org.junit.tests.running.methods.AnnotationTest; 14 15 public class ResultTest extends TestCase { 16 17 public void testRunFailureResultCanBeSerialised() throws Exception { 18 JUnitCore runner = new JUnitCore(); 19 Result result = runner.run(AnnotationTest.FailureTest.class); 20 assertResultSerializable(result); 21 } 22 23 public void testRunSuccessResultCanBeSerialised() throws Exception { 24 JUnitCore runner = new JUnitCore(); 25 Result result = runner.run(Success.class); 26 assertResultSerializable(result); 27 } 28 29 private void assertResultSerializable(Result result) throws IOException, ClassNotFoundException { 30 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 31 new ObjectOutputStream(byteArrayOutputStream).writeObject(result); 32 byte[] bytes = byteArrayOutputStream.toByteArray(); 33 ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)); 34 Result fromStream = (Result) objectInputStream.readObject(); 35 assertNotNull(fromStream); 36 } 37 }