ArrayUtils { public static <T> T getElement(int index, Object[] array, Class<T> expectedType) { return getElement(index, array, expectedType, null, false); }  static T getElement(int index, Object[] array, Class<T> expectedType); static T getElement(int index, Object[] array, Class<T> expectedType, T defaultValue); static T getElement(
      int index, Object[] array, Class<T> expectedType, boolean errorIfNull);  }
@Test public void test() { Assert.assertNull(ArrayUtils.getElement(-1, null, Integer.class)); Assert.assertNull(ArrayUtils.getElement(3, array, Integer.class)); Assert.assertEquals((Integer) 1, ArrayUtils.getElement(0, array, Integer.class)); Assert.assertEquals("Test", ArrayUtils.getElement(1, array, String.class)); Assert.assertEquals("default", ArrayUtils.getElement(3, array, String.class, "default")); Assert.assertEquals((Character) '4', ArrayUtils.getElement(2, array, Character.class)); }
@Test(expected = ExchangeException.class) public void testFailedType() { ArrayUtils.getElement(0, array, String.class); }
@Test(expected = ExchangeException.class) public void testFailedMandatory() { ArrayUtils.getElement(3, array, String.class, true); }