Skip to content

Instantly share code, notes, and snippets.

View tonypiazza's full-sized avatar

Tony Piazza tonypiazza

View GitHub Profile
@tonypiazza
tonypiazza / JunitTestAnnotationWithExpectedExample.java
Last active September 27, 2015 10:28
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() );
@tonypiazza
tonypiazza / JunitTestAnnotationWithTimeoutExample.java
Last active September 27, 2015 10:28
Example usage of the timeout attribute of the org.junit.Test annotation
@Test(timeout=3000)
public void canGetListOfAllPastAuctions() throws ServiceException {
AuctionService service = new BaseAuctionService();
service.loadAuctionHistory();
Collection<Auction> pastAuctions = service.getPastAuctions();
assertNotNull("unable to get past auctions", pastAuctions);
assertTrue("no past auctions", pastAuctions.size() > 0);
}
@tonypiazza
tonypiazza / JunitIgnoreAnnotationExample.java
Last active September 27, 2015 10:28
Example usage of the org.junit.Ignore annotation
@Ignore @Test
public void canCreateIntegerPropertyAndValidate() {
Property prop =
new IntegerProperty("productRating", "Rating", false, 1, 10);
/***************************************************************
* The following assertions will fail if executed. Remove this *
* comment and the @Ignore annotation once refactoring of the *
* PropertyFactory is complete. *
***************************************************************/
assertFalse("Property value should be invalid", prop.isValid(0));