HerdCollectionHelper { public <T> T safeGet(List<T> list, int index) { if (list != null && index < list.size()) { return list.get(index); } return null; }  T safeGet(List<T> list, int index);  }
@Test public void testSafeGetNotNullElement() { String result = herdCollectionHelper.safeGet(Arrays.asList("A", "B", "C"), 2); Assert.assertEquals("result", "C", result); }
@Test public void testSafeGetNullList() { String result = herdCollectionHelper.safeGet(null, 2); Assert.assertNull("result is not null", result); }
@Test public void testSafeGetOutOfBounds() { String result = herdCollectionHelper.safeGet(Arrays.asList("A", "B", "C"), 3); Assert.assertNull("result is not null", result); }