Skip to content

Commit

Permalink
Merge pull request junit-team#263 from rojotek/4.9.1
Browse files Browse the repository at this point in the history
4.9.1
  • Loading branch information
dsaff committed Jul 19, 2011
2 parents d94d5c8 + 5075815 commit fea0643
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
2 changes: 2 additions & 0 deletions acknowledgements.txt
Expand Up @@ -108,3 +108,5 @@
Paul Holser (pholser@alumni.rice.edu): Beginnings of fix for GH-64:
Theories doesn't honor parameterized types

2011 July 16
Rob Dawson: Submitted a patch that makes Results serlializable.
6 changes: 4 additions & 2 deletions src/main/java/org/junit/runner/Description.java
@@ -1,5 +1,6 @@
package org.junit.runner;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -24,8 +25,9 @@
* @see org.junit.runner.Request
* @see org.junit.runner.Runner
*/
public class Description {

public class Description implements Serializable {
private static final long serialVersionUID = 1L;

/**
* Create a <code>Description</code> named <code>name</code>.
* Generally, you will add children to this <code>Description</code>.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/junit/runner/Result.java
@@ -1,5 +1,6 @@
package org.junit.runner;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
Expand All @@ -13,7 +14,8 @@
* tests. Since tests are expected to run correctly, successful tests are only noted in
* the count of tests that ran.
*/
public class Result {
public class Result implements Serializable {
private static final long serialVersionUID = 1L;
private AtomicInteger fCount = new AtomicInteger();
private AtomicInteger fIgnoreCount= new AtomicInteger();
private final List<Failure> fFailures= Collections.synchronizedList(new ArrayList<Failure>());
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/junit/runner/notification/Failure.java
@@ -1,6 +1,7 @@
package org.junit.runner.notification;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;

import org.junit.runner.Description;
Expand All @@ -12,7 +13,8 @@
* test (for example, if a {@link org.junit.BeforeClass} method is not static), it may describe
* something other than a single test.
*/
public class Failure {
public class Failure implements Serializable {
private static final long serialVersionUID = 1L;
private final Description fDescription;
private final Throwable fThrownException;

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/junit/tests/runner/AllTests.java
Expand Up @@ -16,6 +16,7 @@ public static void main(String[] args) {
public static Test suite() { // Collect tests manually because we have to test class collection code
TestSuite suite= new TestSuite("Framework Tests");
suite.addTestSuite(StackFilterTest.class);
suite.addTestSuite(ResultTest.class);
suite.addTestSuite(BaseTestRunnerTest.class);
suite.addTestSuite(TextFeedbackTest.class);
suite.addTestSuite(TextRunnerSingleMethodTest.class);
Expand All @@ -27,4 +28,4 @@ static boolean isJDK11() {
String version= System.getProperty("java.version");
return version.startsWith("1.1");
}
}
}
37 changes: 37 additions & 0 deletions src/test/java/junit/tests/runner/ResultTest.java
@@ -0,0 +1,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);
}
}

0 comments on commit fea0643

Please sign in to comment.