summaryrefslogtreecommitdiffstats
path: root/junit4/src/test/java/junit/tests/runner/ResultTest.java
blob: ba3b509b3abb82d4749d2ba38857e61cf5b7e196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package junit.tests.runner;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import junit.framework.TestCase;
import junit.tests.framework.Success;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.tests.running.methods.AnnotationTest;

public class ResultTest extends TestCase {

	public void testRunFailureResultCanBeSerialised() throws Exception {
		JUnitCore runner = new JUnitCore();
		Result result = runner.run(AnnotationTest.FailureTest.class);
		assertResultSerializable(result);
	}

	public void testRunSuccessResultCanBeSerialised() throws Exception {
		JUnitCore runner = new JUnitCore();
		Result result = runner.run(Success.class);
		assertResultSerializable(result);
	}

	private void assertResultSerializable(Result result) throws IOException, ClassNotFoundException {
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		new ObjectOutputStream(byteArrayOutputStream).writeObject(result);
		byte[] bytes = byteArrayOutputStream.toByteArray();
		ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes));
		Result fromStream = (Result) objectInputStream.readObject();
		assertNotNull(fromStream);
	}
}