Skip to content

Instantly share code, notes, and snippets.

@tonypiazza
Last active September 27, 2015 10:28
Show Gist options
  • Save tonypiazza/1255699 to your computer and use it in GitHub Desktop.
Save tonypiazza/1255699 to your computer and use it in GitHub Desktop.
Example usage of the expected attribute of the org.junit.Test annotation
@Test(expected=ServiceException.class)
public void cannotCreateUserWithSameUsername() throws ServiceException {
User user1 = new User("Jane", "Smith", "jsmith", "venus");
User user2 = new User("John", "Smith", "jsmith", "mars");
AuctionService service = null;
try {
service = new BaseAuctionService();
service.saveUser(user1);
} catch (ServiceException e) {
fail( e.getMessage() );
}
service.saveUser(user2); // this should throw ServiceException
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment