* Test of findByName method, of class TyreDAO.
*/
@Test
public void testFindByName() {
System.out.println("findByName");
Tyre t1 = createTyre(19D, "P Zero", "235/40ZR19", "Pirelli", BigDecimal.valueOf(410));
tyreDAO.create(t1);
Tyre t2 = createTyre(17D, "MM22", "EZ256", "Michellin", BigDecimal.valueOf(222));
tyreDAO.create(t2);
String name;
try {
tyreDAO.findByName(null);
fail("String name is null");
} catch (DataAccessException e) {
// ok
} catch (Exception e) {
fail("String name is null - should have been thrown another exception");
}
name = "PZero";
List<Tyre> tyres = tyreDAO.findByName(name);
assertTrue("Tyre is not in DB", tyres.isEmpty());
name = "P Zero";
tyres = tyreDAO.findByName(name);
assertEquals(t1.getId(), tyres.get(0).getId());
assertDeepEquals(t1, tyres.get(0));
Tyre t3 = createTyre(19D, "P Zero", "235/40ZR19", "Pirelli", BigDecimal.valueOf(450));
Tyre t4 = createTyre(20D, "P Zero", "240/50R20", "Goodyear", BigDecimal.valueOf(480));
tyreDAO.create(t3);
tyreDAO.create(t4);
List<Tyre> tyreList = Arrays.asList(new Tyre[]{t1, t2, t3, t4});