Skip to content

Instantly share code, notes, and snippets.

@craigew
Created September 22, 2013 12:50
Show Gist options
  • Save craigew/6659601 to your computer and use it in GitHub Desktop.
Save craigew/6659601 to your computer and use it in GitHub Desktop.
JPA Unit test
public class TestClientManagement {
@Test
public void should_persist_a_customer() {
Customer customer = new Customer("John", "Doe", "123456", 36);
long id=new CustomerManagementService().createCustomer(customer);
Assert.assertEquals("Id is not was expected",5,id);
}
@Test
public void should_return_a_customer() {
Customer customer = new CustomerManagementService().findCustomerByPrimaryKey(1);
Assert.assertEquals("Name is not equal","Jane",customer.getName());
Assert.assertEquals("Surname is not equal","Doe",customer.getSurname());
Assert.assertEquals("Identity number is not equal","654321",customer.getIdentity_number());
Assert.assertEquals("Age number is not equal",36,customer.getAge());
}
@Test
public void should_update_a_customer() {
Customer customer = new CustomerManagementService().findCustomerByPrimaryKey(1);
customer.setAge(37);
new CustomerManagementService().updateCustomer(customer);
customer = new CustomerManagementService().findCustomerByPrimaryKey(1);
Assert.assertEquals("Age is not updated",37,customer.getAge());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment