Skip to content

Instantly share code, notes, and snippets.

@fourcube
Created January 29, 2014 17:00
Show Gist options
  • Save fourcube/8692234 to your computer and use it in GitHub Desktop.
Save fourcube/8692234 to your computer and use it in GitHub Desktop.
package svv;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.Mockito.verifyZeroInteractions;
@RunWith(MockitoJUnitRunner.class)
public class ExceptionTester {
Thrower cut;
@Mock
Command c;
@Rule
public ExpectedException exception = ExpectedException.none();
@Before
public void setUp() {
cut = new Thrower();
}
@Test
public void shouldThrow() throws Exception {
exception.expect(Exception.class);
try {
cut.now(true);
} finally {
verifyZeroInteractions(c);
}
}
@Test
public void shouldNotThrow() throws Exception {
cut.now(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment