Skip to content

Commit

Permalink
- Moved InitializationError to ParentRunner, since it was only used by
Browse files Browse the repository at this point in the history
  subclasses of ParentRunner.
- Broke up TestMethod into FrameworkMethod (which makes it more clear
  that these methods can also be Before, After, etc.), and
  TestAnnotation (for specific information only available on the @test
  annotation).
- Created TestMethodElement to encapsulate the relationship between
  @test, @before, and @after.  This class may go away again quickly
- Updated version in docs to 4.5
- Included docs about junit-dep jar
  • Loading branch information
dsaff committed Nov 14, 2007
1 parent 53e85db commit 8bed6c9
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 179 deletions.
34 changes: 22 additions & 12 deletions README.html
Expand Up @@ -4,13 +4,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="Author" content="Erich Gamma, Kent Beck, and David Saff">
<title>JUnit 4.4</title>
<title>JUnit 4.5</title>
</head>
<body>

<h1>
<b><font color="#00CC00">J</font><font color="#FF0000">U</font><font color="#000000">nit
4.4</b></h1>
4.5</b></h1>
<br>Brought to you by <a href="http://www.threeriversinstitute.org">Kent Beck</a>, Erich

Gamma, and <a href="http://david.saff.net">David Saff</a>.
Expand All @@ -19,7 +19,7 @@ <h1>
<br>(see also <a href="http://www.junit.org">JUnit.org</a>)

<hr WIDTH="100%">
<br>18 July 2007
<br>[old date] 18 July 2007
<p>JUnit is a simple framework to write repeatable tests. It is an instance
of the xUnit architecture for unit testing frameworks.
<ul>
Expand All @@ -42,7 +42,7 @@ <h1>
</ul>

<a NAME="Summary of">
<h2>Summary of Changes in version 4.4</h2>
<h2>Summary of Changes in version 4.5</h2>

<p>JUnit is designed to efficiently capture developers' intentions about
their code, and quickly check their code matches those intentions.
Expand Down Expand Up @@ -122,6 +122,9 @@ <h3>assertThat</h3>
we have decided to include the classes from hamcrest-core,
from the <a href="http://code.google.com/p/hamcrest/">Hamcrest</a> project. This is the first time that
third-party classes have been included in JUnit. </p></li>
<li><p>To allow developers to maintain full control of the classpath contents, the JUnit distribution also provides an unbundled junit-dep jar,
ie without hamcrest-core classes included. This is intended for situations when using other libraries that also depend on hamcrest-core, to
avoid classloading conflicts or issues. Developers using junit-dep should ensure a compatible version of hamcrest-core jar (ie 1.1+) is present in the classpath.</p></li>
<li><p>JUnit currently ships with a few matchers, defined in
<code>org.hamcrest.CoreMatchers</code> and <code>org.junit.matchers.JUnitMatchers</code>. <br />
To use many, many more, consider downloading the <a href="http://hamcrest.googlecode.com/files/hamcrest-all-1.1.jar">full hamcrest package</a>.</p></li>
Expand Down Expand Up @@ -360,13 +363,20 @@ <h2>
</tr>

<tr>
<td><tt>junit-4.4.jar</tt></td>
<td><tt>junit-4.5.jar</tt></td>

<td>a jar file with the JUnit framework</td>
<td>a jar file with the JUnit framework, bundled with the hamcrest-core-1.1 dependency.</td>
</tr>

<tr>
<td><tt>junit-4.4-src.jar</tt></td>
<td><tt>junit-dep-4.5.jar</tt></td>

<td>a jar file with the JUnit framework, unbundled from any external dependencies.
Choosing to use this jar developers will need to also provide in the classpath a compatible version of external dependencies (ie hamcrest-core-1.1+)</td>
</tr>

<tr>
<td><tt>junit-4.5-src.jar</tt></td>

<td>a jar file with the source code of the JUnit framework</td>
</tr>
Expand Down Expand Up @@ -407,20 +417,20 @@ <h2>
Below are the installation steps for installing JUnit:
<ol>
<li>
unzip the junit4.4.zip file</li>
unzip the junit4.5.zip file</li>

<li>
add<i> </i><b>junit-4.4.jar</b> to the CLASSPATH. For example:
<tt> set classpath=%classpath%;INSTALL_DIR\junit-4.4.jar;INSTALL_DIR</tt></li>
add<i> </i><b>junit-4.5.jar</b> to the CLASSPATH. For example:
<tt> set classpath=%classpath%;INSTALL_DIR\junit-4.5.jar;INSTALL_DIR</tt></li>

<li>
test the installation by running <tt>java org.junit.runner.JUnitCore org.junit.tests.AllTests.</tt></li>

<br><b><font color="#FF0000">Notice</font></b>: that the tests are not
contained in the junit-4.4.jar but in the installation directory directly.
contained in the junit-4.5.jar but in the installation directory directly.
Therefore make sure that the installation directory is on the class path
</ol>
<b><font color="#FF0000">Important</font></b>: don't install junit-4.4.jar
<b><font color="#FF0000">Important</font></b>: don't install junit-4.5.jar
into the extension directory of your JDK installation. If you do so the
test class on the files system will not be found.
<h2>
Expand Down
99 changes: 56 additions & 43 deletions src/org/junit/experimental/theories/Theories.java
Expand Up @@ -15,7 +15,7 @@
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.internal.runners.links.Statement;
import org.junit.internal.runners.model.InitializationError;
import org.junit.internal.runners.model.TestMethod;
import org.junit.internal.runners.model.FrameworkMethod;

@SuppressWarnings("restriction")
public class Theories extends JUnit4ClassRunner {
Expand All @@ -28,62 +28,63 @@ protected void collectInitializationErrors(List<Throwable> errors) {
}

@Override
protected List<TestMethod> computeTestMethods() {
protected List<FrameworkMethod> computeTestMethods() {
// TODO: (Jul 20, 2007 2:02:44 PM) Only get methods once, even if they
// have both @Test and @Theory

List<TestMethod> testMethods= super.computeTestMethods();
List<FrameworkMethod> testMethods= super.computeTestMethods();
testMethods.addAll(getTestClass().getAnnotatedMethods(Theory.class));
return testMethods;
}

@Override
public Statement childBlock(final TestMethod method) {
public Statement childBlock(final FrameworkMethod method) {
return new TheoryAnchor(method);
}

public class TheoryAnchor extends Statement {
private int successes= 0;

private TestMethod fTestMethod;
private FrameworkMethod fTestMethod;

private List<AssumptionViolatedException> fInvalidParameters= new ArrayList<AssumptionViolatedException>();

public TheoryAnchor(TestMethod method) {
public TheoryAnchor(FrameworkMethod method) {
fTestMethod= method;
}

@Override
public void evaluate() throws Throwable {
runWithAssignment(Assignments.allUnassigned(
fTestMethod.getMethod(), fTestMethod.getTestClass()
.getJavaClass()));
fTestMethod.getMethod(), fTestClass.getJavaClass()));

if (successes == 0)
Assert
.fail("Never found parameters that satisfied method. Violated assumptions: "
+ fInvalidParameters);
}

protected void runWithAssignment(Assignments parameterAssignment) throws Throwable {
protected void runWithAssignment(Assignments parameterAssignment)
throws Throwable {
if (!parameterAssignment.isComplete()) {
runWithIncompleteAssignment(parameterAssignment);
} else {
runWithCompleteAssignment(parameterAssignment);
}
}

protected void runWithIncompleteAssignment(Assignments incomplete) throws InstantiationException,
IllegalAccessException, Throwable {
protected void runWithIncompleteAssignment(Assignments incomplete)
throws InstantiationException, IllegalAccessException,
Throwable {
for (PotentialAssignment source : incomplete
.potentialsForNextUnassigned()) {
runWithAssignment(incomplete.assignNext(source));
}
}

protected void runWithCompleteAssignment(final Assignments complete) throws InstantiationException,
IllegalAccessException, InvocationTargetException,
NoSuchMethodException, Throwable {
protected void runWithCompleteAssignment(final Assignments complete)
throws InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException, Throwable {
try {
new JUnit4ClassRunner(getTestClass().getJavaClass()) {
@Override
Expand All @@ -92,65 +93,75 @@ protected void collectInitializationErrors(
// TODO: (Oct 12, 2007 12:08:03 PM) DUP
// do nothing
}

@Override
public Statement childBlock(TestMethod method) {
public Statement childBlock(FrameworkMethod method) {
// TODO: (Oct 12, 2007 2:00:52 PM) Name this Link
final Statement link= super.childBlock(method);
return new Statement() {

@Override
public void evaluate() throws Throwable {
try {
link.evaluate();
successes++;
} catch (AssumptionViolatedException e) {
// TODO: (Oct 12, 2007 2:07:01 PM) DUP? even correct?
// TODO: (Oct 12, 2007 2:07:01 PM) DUP? even
// correct?
// do nothing
} catch (Throwable e) {
// TODO: (Oct 12, 2007 2:04:01 PM) nullsOk as argument to Assignments constructor
// TODO: (Oct 12, 2007 2:04:01 PM) nullsOk
// as argument to Assignments constructor

reportParameterizedError(e, complete.getAllArguments(nullsOk()));
}
reportParameterizedError(e, complete
.getAllArguments(nullsOk()));
}
}

};
}

@Override
protected Statement invoke(TestMethod method, Object test) {
protected Statement invoke(FrameworkMethod method, Object test) {
// TODO: (Oct 12, 2007 12:07:28 PM) push method in
return methodCompletesWithParameters(complete, test);
}

@Override
protected Statement ignoreViolatedAssumptions(final Statement next) {
protected Statement ignoreViolatedAssumptions(
final Statement next) {
// TODO: (Oct 12, 2007 2:15:02 PM) name this

return new Statement() {

@Override
public void evaluate() throws Throwable {
try {
next.evaluate();
next.evaluate();
} catch (AssumptionViolatedException e) {
// TODO: (Oct 12, 2007 2:19:52 PM) This feels hacky
// TODO: (Oct 12, 2007 2:19:52 PM) This
// feels hacky

successes--;
handleAssumptionViolation(e);
// TODO: (Oct 12, 2007 2:15:44 PM) Can I remove other calls?
// TODO: (Oct 12, 2007 2:15:44 PM) Can I
// remove other calls?

}
}
};
}

@Override
public Object createTest() throws Exception {
// TODO: (Oct 12, 2007 12:31:12 PM) DUP
// TODO: (Oct 12, 2007 12:40:33 PM) honor assumption violations in JUnit4ClassRunner constructor invocations
// TODO: (Oct 12, 2007 12:40:33 PM) honor assumption
// violations in JUnit4ClassRunner constructor
// invocations

return getTestClass().getJavaClass().getConstructors()[0].newInstance(complete.getConstructorArguments(nullsOk()));
return getTestClass().getJavaClass().getConstructors()[0]
.newInstance(complete
.getConstructorArguments(nullsOk()));
}
}.childBlock(fTestMethod).evaluate();
} catch (AssumptionViolatedException e) {
Expand All @@ -160,29 +171,31 @@ public Object createTest() throws Exception {
}
}

private Statement methodCompletesWithParameters(final Assignments complete,
final Object freshInstance) {
private Statement methodCompletesWithParameters(
final Assignments complete, final Object freshInstance) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
invokeWithActualParameters(freshInstance, complete);
} catch (CouldNotGenerateValueException e) {
// ignore
// TODO: (Oct 12, 2007 9:58:11 AM) Do I ignore this elsewhere?
// ignore
// TODO: (Oct 12, 2007 9:58:11 AM) Do I ignore this
// elsewhere?
}
}
};
}

private void invokeWithActualParameters(Object target,
Assignments complete) throws Throwable {
final Object[] values= complete.getMethodArguments(nullsOk(), target);
// try {
fTestMethod.invokeExplosively(target, values);
// } catch (AssumptionViolatedException e) {
// handleAssumptionViolation(e);
// }
final Object[] values= complete.getMethodArguments(nullsOk(),
target);
// try {
fTestMethod.invokeExplosively(target, values);
// } catch (AssumptionViolatedException e) {
// handleAssumptionViolation(e);
// }
}

protected void handleAssumptionViolation(AssumptionViolatedException e) {
Expand Down

0 comments on commit 8bed6c9

Please sign in to comment.