Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/KentBeck/junit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Glick committed Jan 31, 2012
2 parents 5d9e002 + 45eaab7 commit f0319c2
Show file tree
Hide file tree
Showing 25 changed files with 1,224 additions and 154 deletions.
13 changes: 8 additions & 5 deletions 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.10" />
<property name="version-base" value="4.11" />
<property name="version-status" value="-SNAPSHOT" />
<property name="version" value="${version-base}${version-status}" />
<property name="dist" value="junit${version}" />
Expand Down Expand Up @@ -133,7 +133,8 @@

<target name="release-notes">
<property name="basename" value="doc/ReleaseNotes${version-base}" />
<exec executable="build/Markdown.pl" failonerror="true">
<exec executable="perl" failonerror="true">
<arg file="build/Markdown.pl"/>
<arg file="${basename}.txt"/>
<redirector output="${basename}.html" />
</exec>
Expand Down Expand Up @@ -270,7 +271,7 @@
url="@{url}" repo.id="@{repo.id}" />

<if>
<equals arg1="${is.snapshot}" arg2="false" />
<equals arg1="@{is.snapshot}" arg2="false" />
<then>
<push.maven.jar jar="${m.sources.jar}" pom="${m.pom}"
url="@{url}" repo.id="@{repo.id}">
Expand All @@ -293,10 +294,12 @@

<push.maven.artifact artifactId="junit"
url="${stage.url}"
repo.id="${stage.repo.id}" />
repo.id="${stage.repo.id}"
is.snapshot="false" />
<push.maven.artifact artifactId="junit-dep"
url="${stage.url}"
repo.id="${stage.repo.id}" />
repo.id="${stage.repo.id}"
is.snapshot="false" />
</target>

<target name="snapshot.maven" depends="all.maven.jars">
Expand Down
89 changes: 82 additions & 7 deletions doc/ReleaseNotes4.10.html
@@ -1,18 +1,93 @@
<h2>Summary of Changes in version 4.10 [unreleased!]</h2>

<h3>Bug fixes</h3>
<p>A full summary of commits between 4.9 and 4.10 is on <a href="https://github.com/KentBeck/junit/compare/r4.9...4.10">github</a></p>

<h3>Minor changes</h3>
<h3>junit-dep has correct contents</h3>

<p>junit-dep-4.9.jar incorrectly contained hamcrest classes, which could lead to version conflicts in projects that depend on hamcrest directly. This is fixed in 4.10 [@dsaff, closing gh-309]</p>

<h3>RuleChain</h3>

<p>The RuleChain rule allows ordering of TestRules:</p>

<pre><code>public static class UseRuleChain {
@Rule
public TestRule chain= RuleChain
.outerRule(new LoggingRule("outer rule")
.around(new LoggingRule("middle rule")
.around(new LoggingRule("inner rule");

<p>Thanks to <code>@rodolfoliviero</code> for:</p>
@Test
public void example() {
assertTrue(true);
}
}
</code></pre>

<p>writes the log</p>

<pre><code>starting outer rule
starting middle rule
starting inner rule
finished inner rule
finished middle rule
finished outer rule
</code></pre>

<h3>TemporaryFolder</h3>

<ul>
<li>github#283: Feature to create recursive temporary folders.</li>
<li><code>TemporaryFolder#newFolder(String... folderNames)</code> creates recursively deep temporary folders
[@rodolfoliviero, closing gh-283]</li>
<li><code>TemporaryFolder#newFile()</code> creates a randomly named new file, and <code>#newFolder()</code> creates a randomly named new folder
[@Daniel Rothmaler, closing gh-299]</li>
</ul>

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

<p>The <code>Theories</code> runner does not anticipate theory parameters that have generic
types, as reported by github#64. Fixing this won't happen until <code>Theories</code> 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 <code>Theories</code> runner uses, <code>FrameworkMethod</code>#producesType().
The Common Public License that JUnit is released under is now included
in the source repository.</p>

<p>Thanks to <code>@pholser</code> for identifying a potential resolution for github#64
and initiating work on it.</p>

<h3>Bug fixes</h3>

<ul>
<li>Built-in Rules implementations
<ul>
<li>TemporaryFolder should not create files in the current working directory if applying the rule fails
[@orfjackal, fixing gh-278]</li>
<li>TestWatcher and TestWatchman should not call failed for AssumptionViolatedExceptions
[@stefanbirkner, fixing gh-296]</li>
</ul></li>
<li>Javadoc bugs
<ul>
<li>Assert documentation [@stefanbirkner, fixing gh-134]</li>
<li>ClassRule [@stefanbirkner, fixing gh-254]</li>
<li>Parameterized [@stefanbirkner, fixing gh-89]</li>
<li>Parameterized, again [@orfjackal, fixing gh-285]</li>
</ul></li>
<li>Miscellaneous
<ul>
<li>Useless code in RunAfters [@stefanbirkner, fixing gh-289]</li>
<li>Parameterized test classes should be able to have <code>@Category</code> annotations
[@dsaff, fixing gh-291]</li>
<li>Error count should be initialized in junit.tests.framework.TestListenerTest [@stefanbirkner, fixing gh-225]</li>
<li>AssertionFailedError constructor shouldn't call super with null message [@stefanbirkner, fixing gh-318]</li>
<li>Clearer error message for non-static inner test classes [@stefanbirkner, fixing gh-42]</li>
</ul></li>
</ul>

<h3>Minor changes</h3>

<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>
<li>Description, Result and Failure are Serializable [@ephox-rob, closing gh-101]</li>
<li>FailOnTimeout is reusable, allowing for retrying Rules [@stefanbirkner, closing gh-265]</li>
<li>New <code>ErrorCollector.checkThat</code> overload, that allows you to specify a reason [@drothmaler, closing gh-300]</li>
</ul>
84 changes: 77 additions & 7 deletions doc/ReleaseNotes4.10.txt
@@ -1,14 +1,84 @@
## Summary of Changes in version 4.10 [unreleased!] ##
## Summary of Changes in version 4.10 ##

Thanks to a full cast of contributors of bug fixes and new features.

A full summary of commits between 4.9 and 4.10 is on [github](https://github.com/KentBeck/junit/compare/r4.9...4.10)

### junit-dep has correct contents ###

junit-dep-4.9.jar incorrectly contained hamcrest classes, which could lead to version conflicts in projects that depend on hamcrest directly. This is fixed in 4.10 [@dsaff, closing gh-309]

### RuleChain ###

The RuleChain rule allows ordering of TestRules:

public static class UseRuleChain {
@Rule
public TestRule chain= RuleChain
.outerRule(new LoggingRule("outer rule")
.around(new LoggingRule("middle rule")
.around(new LoggingRule("inner rule");

@Test
public void example() {
assertTrue(true);
}
}

writes the log

starting outer rule
starting middle rule
starting inner rule
finished inner rule
finished middle rule
finished outer rule

### TemporaryFolder ###

- `TemporaryFolder#newFolder(String... folderNames)` creates recursively deep temporary folders
[@rodolfoliviero, closing gh-283]
- `TemporaryFolder#newFile()` creates a randomly named new file, and `#newFolder()` creates a randomly named new folder
[@Daniel Rothmaler, closing gh-299]

### 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.

### Bug fixes ###


- Built-in Rules implementations
- TemporaryFolder should not create files in the current working directory if applying the rule fails
[@orfjackal, fixing gh-278]
- TestWatcher and TestWatchman should not call failed for AssumptionViolatedExceptions
[@stefanbirkner, fixing gh-296]
- Javadoc bugs
- Assert documentation [@stefanbirkner, fixing gh-134]
- ClassRule [@stefanbirkner, fixing gh-254]
- Parameterized [@stefanbirkner, fixing gh-89]
- Parameterized, again [@orfjackal, fixing gh-285]
- Miscellaneous
- Useless code in RunAfters [@stefanbirkner, fixing gh-289]
- Parameterized test classes should be able to have `@Category` annotations
[@dsaff, fixing gh-291]
- Error count should be initialized in junit.tests.framework.TestListenerTest [@stefanbirkner, fixing gh-225]
- AssertionFailedError constructor shouldn't call super with null message [@stefanbirkner, fixing gh-318]
- Clearer error message for non-static inner test classes [@stefanbirkner, fixing gh-42]

### Minor changes ###

Thanks to `@rodolfoliviero` for:
- Description, Result and Failure are Serializable [@ephox-rob, closing gh-101]
- FailOnTimeout is reusable, allowing for retrying Rules [@stefanbirkner, closing gh-265]
- New `ErrorCollector.checkThat` overload, that allows you to specify a reason [@drothmaler, closing gh-300]

- 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
1 change: 1 addition & 0 deletions doc/ReleaseNotes4.11.html
@@ -0,0 +1 @@
<h2>Summary of Changes in version 4.11 [unreleased!]</h2>
1 change: 1 addition & 0 deletions doc/ReleaseNotes4.11.txt
@@ -0,0 +1 @@
## Summary of Changes in version 4.11 [unreleased!] ##
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.10-SNAPSHOT";
return "4.11-SNAPSHOT";
}

public static void main(String[] args) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/junit/Assert.java
Expand Up @@ -721,6 +721,11 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
* // got value: &lt;0&gt;
* assertThat(0, is(not(1))) // passes
* </pre>
*
* <code>org.hamcrest.Matcher</code> does not currently document the meaning
* of its type parameter <code>T</code>. This method assumes that a matcher
* typed as <code>Matcher&lt;T&gt;</code> can be meaningfully applied only
* to values that could be assigned to a variable of type <code>T</code>.
*
* @param <T>
* the static type accepted by the matcher (this can flag obvious
Expand All @@ -734,7 +739,7 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
* @see org.hamcrest.CoreMatchers
* @see org.junit.matchers.JUnitMatchers
*/
public static <T> void assertThat(T actual, Matcher<T> matcher) {
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
assertThat("", actual, matcher);
}

Expand All @@ -753,6 +758,11 @@ public static <T> void assertThat(T actual, Matcher<T> matcher) {
* assertThat(&quot;Zero is one&quot;, 0, is(not(1))) // passes
* </pre>
*
* <code>org.hamcrest.Matcher</code> does not currently document the meaning
* of its type parameter <code>T</code>. This method assumes that a matcher
* typed as <code>Matcher&lt;T&gt;</code> can be meaningfully applied only
* to values that could be assigned to a variable of type <code>T</code>.
*
* @param reason
* additional information about the error
* @param <T>
Expand All @@ -768,7 +778,7 @@ public static <T> void assertThat(T actual, Matcher<T> matcher) {
* @see org.junit.matchers.JUnitMatchers
*/
public static <T> void assertThat(String reason, T actual,
Matcher<T> matcher) {
Matcher<? super T> matcher) {
if (!matcher.matches(actual)) {
Description description= new StringDescription();
description.appendText(reason);
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/org/junit/ClassRule.java
Expand Up @@ -6,8 +6,9 @@
import java.lang.annotation.Target;

/**
* Annotates static fields that contain rules. Such a field must be public,
* static, and a subtype of {@link org.junit.rules.TestRule}.
* Annotates static fields that contain rules or methods that return them. A field must be public,
* static, and a subtype of {@link org.junit.rules.TestRule}. A method must be public static, and return
* a subtype of {@link org.junit.rules.TestRule}
* The {@link org.junit.runners.model.Statement} passed
* to the {@link org.junit.rules.TestRule} will run any {@link BeforeClass} methods,
* then the entire body of the test class (all contained methods, if it is
Expand All @@ -25,13 +26,13 @@
* If there are multiple
* annotated {@link ClassRule}s on a class, they will be applied in an order
* that depends on your JVM's implementation of the reflection API, which is
* undefined, in general.
* undefined, in general. However, Rules defined by fields will always be applied
* before Rules defined by methods.
*
* For example, here is a test suite that connects to a server once before
* all the test classes run, and disconnects after they are finished:
*
* <pre>
*
* &#064;RunWith(Suite.class)
* &#064;SuiteClasses({A.class, B.class, C.class})
* public class UsesExternalResource {
Expand All @@ -52,9 +53,34 @@
* }
* </pre>
*
* and the same using a method
*
* <pre>
* &#064;RunWith(Suite.class)
* &#064;SuiteClasses({A.class, B.class, C.class})
* public class UsesExternalResource {
* public static Server myServer= new Server();
*
* &#064;ClassRule
* public static ExternalResource getResource() {
* return new ExternalResource() {
* &#064;Override
* protected void before() throws Throwable {
* myServer.connect();
* }
*
* &#064;Override
* protected void after() {
* myServer.disconnect();
* }
* };
* }
* }
* </pre>
*
* For more information and more examples, see {@link org.junit.rules.TestRule}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface ClassRule {
}

0 comments on commit f0319c2

Please sign in to comment.