@Test(expectedExceptions = DataAccessException.class) public void testTwoServicesWithSameName() { service1.setName("Barum"); service2.setName("Barum"); serviceDao.create(service1); serviceDao.create(service2); }
@BeforeMethod public void setUp() { service1 = new Service(); service1.setName("Engine oil replacement"); service1.setPrice(new BigDecimal("350.00")); service2 = new Service(); service2.setName("Tire balancing"); service2.setPrice(new BigDecimal("560.00")); }
@Test public void testFindById() { serviceDao.create(service1); Service found = serviceDao.findById(service1.getId()); assertEquals(found, service1); }
@Test public void testUpdateService() { serviceDao.create(service1); assertEquals("Engine oil replacement", service1.getName()); service1.setName("Barum"); service1.setPrice(new BigDecimal("333.00")); serviceDao.update(service1); Service updatedService = serviceDao.findById(service1.getId()); assertEquals("Barum", updatedService.getName()); assertEquals(updatedService.getPrice(), new BigDecimal("333.00")); }
@Test(expectedExceptions = ConstraintViolationException.class) public void testNullPrice() { service1.setPrice(null); serviceDao.create(service1); }