package org.testory;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.testory.Testory.thenThrown;
import static org.testory.Testory.when;
import static org.testory.testing.Closures.returning;
import static org.testory.testing.Closures.throwing;
import static org.testory.testing.Closures.voidReturning;
import static org.testory.testing.Fakes.newObject;
import static org.testory.testing.Fakes.newThrowable;
import static org.testory.testing.HamcrestMatchers.hasMessageContaining;
import org.junit.Before;
import org.junit.Test;
public class TestThenThrown {
private Throwable throwable;
private Object object;
@Before
public void before() {
throwable = newThrowable("throwable");
object = newObject("object");
}
@Test
public void asserts_throwing() {
when(throwing(throwable));
thenThrown();
}
@Test
public void fails_returning_object() {
when(returning(object));
try {
thenThrown();
fail();
} catch (TestoryAssertionError e) {}
}
@Test
public void fails_returning_void() {
when(voidReturning());
try {
thenThrown();
fail();
} catch (TestoryAssertionError e) {}
}
@Test
public void failure_prints_expectation() {
when(returning(object));
try {
thenThrown();
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(""
+ " expected thrown\n"
+ " \n"));
}
}
}