Skip to content

Instantly share code, notes, and snippets.

@brunokrebs
Created July 11, 2016 00:07
Show Gist options
  • Save brunokrebs/89ab787c71d30cfed45f69f8072bc8ba to your computer and use it in GitHub Desktop.
Save brunokrebs/89ab787c71d30cfed45f69f8072bc8ba to your computer and use it in GitHub Desktop.
package com.someaddress.test;
import com.someaddress.model.Product;
import com.someaddress.intent.DetailsUpdateIntent;
import java.math.BigDecimal;
import org.testng.Assert;
import org.testng.annotations.Test;
public class ProductTest {
@Test
public void testUpdateDetails() {
DetailsUpdateIntent intent = new DetailsUpdateIntent();
intent.setId("xy12");
intent.setName("White Cow Milk");
intent.setDescription("Very fresh milk ready to consume");
intent.setPrice(BigDecimal.valueOf(-1));
Product product = new Product();
try {
product.handleDetailsUpdate(intent);
Assert.fail("Should not accept negative prices.");
} catch (IllegalArgumentException e) {}
BigDecimal newPrice = BigDecimal.valueOf(2.42);
intent.setPrice();
product.handleDetailsUpdate(intent);
Assert.assertEquals(product.getPrice(), newPrice, "Should have 2.42 as price.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment