### Question:
JpaUtil { public static <T> T getSingleResult(List<T> list) { if (list == null) { return null; } switch(list.size()) { case 0: return null; case 1: return list.get(0); default: throw new IncorrectResultSizeDataAccessException(1); } } private  JpaUtil(); static T getSingleResult(List<T> list); static T saveOrUpdate(I id, EntityManager entityManager, T entity); static List<T> getPagedResultList(TypedQuery<T> query, int offset, int pageSize); static void clearAndAdd(List<T> target, List<E> newList, Class<T> clazz);  }### Answer:
@Test public void getSingleResult_emptyList() { List<Object> list = new ArrayList<Object>(); Object object = JpaUtil.getSingleResult(list); assertNull(object); }
@Test public void getSingleResult_nullList() { Object object = JpaUtil.getSingleResult(null); assertNull(object); }
@Test public void getSingleResult_singleObjectPopulatedList() { List<Object> populatedList = generatePopulatedList(1); Object object = JpaUtil.getSingleResult(populatedList); assertSame(object, populatedList.get(0)); }
@Test (expected = IncorrectResultSizeDataAccessException.class) public void getSingleResult_multipleObjectPopulatedList() { List<Object> populatedList = generatePopulatedList(5); JpaUtil.getSingleResult(populatedList); }