Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KentBeck/junit
Browse files Browse the repository at this point in the history
Conflicts:
	build.xml
	src/main/java/junit/runner/Version.java
  • Loading branch information
dsaff committed Sep 14, 2011
2 parents 05fe0fb + 96df21c commit e76c5f0
Show file tree
Hide file tree
Showing 28 changed files with 898 additions and 85 deletions.
33 changes: 33 additions & 0 deletions acknowledgements.txt
Expand Up @@ -104,9 +104,18 @@
Samuel Le Berrigaud (sleberrigaud@github): Report for GH-248:
protected BlockJUnit4ClassRunner#rules method removed from 4.8.2

2011 Jun 24
Daniel Rothmaler (drothmaler@github):
#299: random temp file/folder creation
#300: ErrorCollector.checkThat overload

2011 Jul 06
Stefan Birkner: Fixed wrong documentation of ClassRule (github#254).

2011 Jul 08
Paul Holser (pholser@alumni.rice.edu): Beginnings of fix for GH-64:
Theories doesn't honor parameterized types

2011 Jul 09
Nigel Charman: Reported Rules bugs github#257 and gihub#258.

Expand All @@ -116,11 +125,35 @@
2011 Jul 09
Stefan Birkner: Fixed rules bugs (github#257, gihub#258, github#260).

2011 Jul 16
Rob Dawson: Submitted a patch that makes Results serlializable.

2011 Jul 20
Asaf Ary, Stefan Birkner: Fixed FailOnTimeout class (github#265).

2011 Jul 22
Andreas Köhler, Stefan Birkner: Fixed wrong documentation of Parameterized (github#89).

2011 Jul 28
electrickery, Stefan Birkner: Fixed typo in JavaDoc (github#134).

2011 Aug 07
Esko Luontola: Fixed TemporaryFolder creating files in the current working directory (github#278).

2011 Aug 09
Stefan Birkner: Fixed JavaDoc links.

2011 Aug 10
rodolfoliviero@github and JoseRibeiro@github: feature to create recursive temporary folders.

2011 Aug 12
Esko Luontola: Fixed syntax error in Parameterized's usage example (github#285).

2011 Sep 09
Robert Munteanu, Stefan Birkner:
TestWatcher and TestWatchman don't call failed when assumption is violated (github#296).
digulla@github, Stefan Birkner: Removed useless code (github#289).

== NOTE: as of September 2011, we have stopped recording contributions here.
For a full list of everyone who has contributed great bug reports and code, please see
http://github.com/KentBeck/junit
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -7,7 +7,7 @@
<property name="src" value="src/main/java" />
<property name="target" location="target" />
<property name="bin" location="${target}/main" />
<property name="version-base" value="4.9.1" />
<property name="version-base" value="4.10" />
<property name="version-status" value="-SNAPSHOT" />
<property name="version" value="${version-base}${version-status}" />
<property name="dist" value="junit${version}" />
Expand Down
18 changes: 18 additions & 0 deletions doc/ReleaseNotes4.10.html
@@ -0,0 +1,18 @@
<h2>Summary of Changes in version 4.10 [unreleased!]</h2>

<h3>Bug fixes</h3>

<h3>Minor changes</h3>

<p>Thanks to <code>@rodolfoliviero</code> for:</p>

<ul>
<li>github#283: Feature to create recursive temporary folders.</li>
</ul>

<p>Thanks to <code>@drothmaler</code> for:</p>

<ul>
<li>github#299: Random temporary file/folder creation</li>
<li>github#300: New <code>ErrorCollector.checkThat</code> overload, that allows you to specify a reason</li>
</ul>
14 changes: 14 additions & 0 deletions doc/ReleaseNotes4.10.txt
@@ -0,0 +1,14 @@
## Summary of Changes in version 4.10 [unreleased!] ##

### Bug fixes ###

### Minor changes ###

Thanks to `@rodolfoliviero` for:

- github#283: Feature to create recursive temporary folders.

Thanks to `@drothmaler` for:

- github#299: Random temporary file/folder creation
- github#300: New `ErrorCollector.checkThat` overload, that allows you to specify a reason
14 changes: 14 additions & 0 deletions doc/ReleaseNotes4.9.1.txt
@@ -0,0 +1,14 @@
## Summary of Changes in version 4.9.1 [unreleased!] ##

### Theories ###

The `Theories` runner does not anticipate theory parameters that have generic
types, as reported by github#64. Fixing this won't happen until `Theories` is
moved to junit-contrib. In anticipation of this, 4.9.1 adds some of the
necessary machinery to the runner classes, and deprecates a method that only
the `Theories` runner uses, `FrameworkMethod`#producesType().
The Common Public License that JUnit is released under is now included
in the source repository.

Thanks to `@pholser` for identifying a potential resolution for github#64
and initiating work on it.
2 changes: 1 addition & 1 deletion src/main/java/junit/runner/Version.java
Expand Up @@ -9,7 +9,7 @@ private Version() {
}

public static String id() {
return "4.9.1-SNAPSHOT";
return "4.10-SNAPSHOT";
}

public static void main(String[] args) {
Expand Down
Expand Up @@ -6,41 +6,66 @@
import org.junit.runners.model.Statement;

public class FailOnTimeout extends Statement {
private Statement fNext;
private final Statement fOriginalStatement;

private final long fTimeout;

private boolean fFinished= false;

private Throwable fThrown= null;

public FailOnTimeout(Statement next, long timeout) {
fNext= next;
public FailOnTimeout(Statement originalStatement, long timeout) {
fOriginalStatement= originalStatement;
fTimeout= timeout;
}

@Override
public void evaluate() throws Throwable {
Thread thread= new Thread() {
@Override
public void run() {
try {
fNext.evaluate();
fFinished= true;
} catch (Throwable e) {
fThrown= e;
}
}
};
StatementThread thread= evaluateStatement();
if (!thread.fFinished)
throwExceptionForUnfinishedThread(thread);
}

private StatementThread evaluateStatement() throws InterruptedException {
StatementThread thread= new StatementThread(fOriginalStatement);
thread.start();
thread.join(fTimeout);
if (fFinished)
return;
if (fThrown != null)
throw fThrown;
thread.interrupt();
return thread;
}

private void throwExceptionForUnfinishedThread(StatementThread thread)
throws Throwable {
if (thread.fExceptionThrownByOriginalStatement != null)
throw thread.fExceptionThrownByOriginalStatement;
else
throwTimeoutException(thread);
}

private void throwTimeoutException(StatementThread thread) throws Exception {
Exception exception= new Exception(String.format(
"test timed out after %d milliseconds", fTimeout));
exception.setStackTrace(thread.getStackTrace());
throw exception;
}

private static class StatementThread extends Thread {
private final Statement fStatement;

private boolean fFinished= false;

private Throwable fExceptionThrownByOriginalStatement= null;

public StatementThread(Statement statement) {
fStatement= statement;
}

@Override
public void run() {
try {
fStatement.evaluate();
fFinished= true;
} catch (InterruptedException e) {
//don't log the InterruptedException
} catch (Throwable e) {
fExceptionThrownByOriginalStatement= e;
}
}
}
}
Expand Up @@ -26,7 +26,6 @@ public RunAfters(Statement next, List<FrameworkMethod> afters, Object target) {
@Override
public void evaluate() throws Throwable {
List<Throwable> errors = new ArrayList<Throwable>();
errors.clear();
try {
fNext.evaluate();
} catch (Throwable e) {
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/org/junit/rules/ErrorCollector.java
Expand Up @@ -52,25 +52,34 @@ public void addError(Throwable error) {
* Execution continues, but the test will fail at the end if the match fails.
*/
public <T> void checkThat(final T value, final Matcher<T> matcher) {
checkThat("", value, matcher);
}

/**
* Adds a failure with the given {@code reason}
* to the table if {@code matcher} does not match {@code value}.
* Execution continues, but the test will fail at the end if the match fails.
*/
public <T> void checkThat(final String reason, final T value, final Matcher<T> matcher) {
checkSucceeds(new Callable<Object>() {
public Object call() throws Exception {
assertThat(value, matcher);
assertThat(reason, value, matcher);
return value;
}
});
}

/**
* Adds to the table the exception, if any, thrown from {@code callable}.
* Execution continues, but the test will fail at the end if {@code callable}
* threw an exception.
* Adds to the table the exception, if any, thrown from {@code callable}.
* Execution continues, but the test will fail at the end if
* {@code callable} threw an exception.
*/
public Object checkSucceeds(Callable<Object> callable) {
try {
return callable.call();
} catch (Throwable e) {
addError(e);
return null;
}
}
}
}
40 changes: 31 additions & 9 deletions src/main/java/org/junit/rules/TemporaryFolder.java
Expand Up @@ -42,39 +42,61 @@ protected void after() {
* for testing purposes only. Do not use.
*/
public void create() throws IOException {
folder= File.createTempFile("junit", "");
folder.delete();
folder.mkdir();
folder= newFolder();
}

/**
* Returns a new fresh file with the given name under the temporary folder.
*/
public File newFile(String fileName) throws IOException {
File file= new File(folder, fileName);
File file= new File(getRoot(), fileName);
file.createNewFile();
return file;
}

/**
* Returns a new fresh file with a random name under the temporary folder.
*/
public File newFile() throws IOException {
return File.createTempFile("junit", null, folder);
}

/**
* Returns a new fresh folder with the given name under the temporary folder.
*/
public File newFolder(String folderName) {
File file= new File(folder, folderName);
file.mkdir();
public File newFolder(String... folderNames) {
File file = getRoot();
for (String folderName : folderNames) {
file = new File(file, folderName);
file.mkdir();
}
return file;
}

/**
* Returns a new fresh folder with a random name under the temporary
* folder.
*/
public File newFolder() throws IOException {
File createdFolder= File.createTempFile("junit", "", folder);
createdFolder.delete();
createdFolder.mkdir();
return createdFolder;
}

/**
* @return the location of this temporary folder.
*/
public File getRoot() {
if (folder == null) {
throw new IllegalStateException("the temporary folder has not yet been created");
}
return folder;
}

/**
* Delete all files and folders under the temporary folder.
* Usually not called directly, since it is automatically applied
* Usually not called directly, since it is automatically applied
* by the {@link Rule}
*/
public void delete() {
Expand All @@ -88,4 +110,4 @@ private void recursiveDelete(File file) {
recursiveDelete(each);
file.delete();
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/junit/rules/TestWatcher.java
@@ -1,5 +1,6 @@
package org.junit.rules;

import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

Expand Down Expand Up @@ -45,6 +46,8 @@ public void evaluate() throws Throwable {
try {
base.evaluate();
succeeded(description);
} catch (AssumptionViolatedException e) {
throw e;
} catch (Throwable t) {
failed(t, description);
throw t;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/junit/rules/TestWatchman.java
@@ -1,5 +1,6 @@
package org.junit.rules;

import org.junit.internal.AssumptionViolatedException;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

Expand Down Expand Up @@ -51,6 +52,8 @@ public void evaluate() throws Throwable {
try {
base.evaluate();
succeeded(method);
} catch (AssumptionViolatedException e) {
throw e;
} catch (Throwable t) {
failed(t, method);
throw t;
Expand Down
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

0 comments on commit e76c5f0

Please sign in to comment.