CVS: junit/src/org/junit/experimental/test/imposterization ThrownMatcherTest.java, NONE, 1.1 AssumePassingTest.java, NONE, 1.1 PopperImposterizerTest.java, NONE, 1.1
David Saff <[email protected]> Thu, 12 Jul 2007 10:08:24 -0700
| Newsgroups | gmane.comp.java.junit.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/junit/junit/src/org/junit/experimental/test/imposterization
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26134/src/org/junit/experimental/test/imposterization
Added Files:
ThrownMatcherTest.java AssumePassingTest.java
PopperImposterizerTest.java
Log Message:
Re-organize theory packages
--- NEW FILE: ThrownMatcherTest.java ---
package org.junit.experimental.test.imposterization;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.matchers.StringContains.containsString;
import java.util.ArrayList;
import org.junit.Test;
import org.junit.experimental.imposterization.ThrownMatcher;
import org.junit.experimental.imposterization.ThrownMatcher.IncorrectThrownException;
import org.junit.experimental.theories.runner.api.Theories;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
public class ThrownMatcherTest {
@Test
public void assertThrownVerifiesExceptionThrown() throws Exception {
ArithmeticException ae= new ArithmeticException();
try {
ThrownMatcher.assertThrownException(is(ae)).when(
new ArrayList<String>()).get(0);
fail("should have thrown exception");
} catch (IncorrectThrownException e) {
assertThat(e.getMessage(), containsString(ae.toString()));
}
}
@Test
public void assertThrownVerifiesExceptionThrownWithRequirements()
throws Exception {
ArithmeticException ae= new ArithmeticException();
try {
ThrownMatcher.assertThrownException(is(ae)).when(
new ArrayList<String>()).get(0);
fail("should have thrown exception");
} catch (IncorrectThrownException e) {
assertThat(e.getMessage(), containsString(ae.toString()));
}
}
public static class ExceptionThrowing {
public static Throwable EXCEPTION= new NullPointerException();
public void liveDangerously() throws Throwable {
throw EXCEPTION;
}
}
@Test
public void stackTraceOnAssertThrown() {
try {
ThrownMatcher.assertThrownException(is(new RuntimeException()))
.when(new ExceptionThrowing()).liveDangerously();
fail("should have thrown exception");
} catch (Throwable e) {
assertThat(e.getCause(), is(ExceptionThrowing.EXCEPTION));
}
}
}
--- NEW FILE: AssumePassingTest.java ---
package org.junit.experimental.test.imposterization;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.experimental.imposterization.AssumePassing.assumePasses;
import java.util.List;
import org.junit.Test;
import org.junit.Assume.AssumptionViolatedException;
import org.junit.experimental.imposterization.AssumePassing;
import org.junit.experimental.theories.runner.api.Theories;
import org.junit.runner.JUnitCore;
import org.junit.runner.RunWith;
import org.junit.runner.notification.Failure;
@RunWith(Theories.class)
public class AssumePassingTest {
public static class OnlyIfPassingButDoesnt {
@Test
public void failing() {
fail();
}
@SuppressWarnings("deprecation")
@Test
public void willIgnore() {
((OnlyIfPassingButDoesnt) AssumePassing.assumePasses(this
.getClass())).failing();
fail();
}
}
@Test
public void onlyIfPassingButDoesnt() {
assertThat(onlyIfPassingFailures().size(), is(1));
}
@SuppressWarnings("unchecked")
@Test
public void removedParameterizedFailureWhenZeroParams() {
assertThat(onlyIfPassingFailures().get(0).getException(), is(AssertionError.class));
}
private List<Failure> onlyIfPassingFailures() {
return JUnitCore.runClasses(OnlyIfPassingButDoesnt.class).getFailures();
}
@RunWith(Theories.class)
public static class OnlyIfPassesAndDoes {
@Test
public void passing() {
}
@SuppressWarnings("deprecation")
@Test
public void wontIgnore() {
assumePasses(OnlyIfPassesAndDoes.class).passing();
fail();
}
}
@Test
public void onlyIfPassesAndDoes() {
assertThat(JUnitCore.runClasses(OnlyIfPassesAndDoes.class)
.getFailures().size(), is(1));
}
@RunWith(Theories.class)
public static class OnlyIfPassesWithInvalidTheory {
@Test
public void throwsInvalidTheory() {
throw new AssumptionViolatedException(null, is("a"));
}
@SuppressWarnings("deprecation")
@Test
public void wontIgnore() {
assumePasses(OnlyIfPassesWithInvalidTheory.class)
.throwsInvalidTheory();
}
}
@Test
public void onlyIfPassesWithInvalidTheory() {
assertThat(JUnitCore.runClasses(OnlyIfPassesWithInvalidTheory.class)
.getIgnoreCount(), is(0));
}
}
--- NEW FILE: PopperImposterizerTest.java ---
package org.junit.experimental.test.imposterization;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.junit.Test;
import org.junit.experimental.imposterization.PopperImposterizer;
public class PopperImposterizerTest {
@Test
public void canWrapImposterizedObjects() {
List<?> list= new PopperImposterizer(null).imposterize(List.class);
assertThat(new PopperImposterizer(null).imposterize(list.getClass()),
notNullValue());
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/