ArgCheck { static public <T> T requireNonNull(T obj) throws NullPointerException { return requireNonNull(obj, "Reference cannot be null"); } private  ArgCheck(); static T requireNonNull(T obj); static T requireNonNull(T obj, String errMsg); static long requirePostive(long l); static long requirePostive(long l, String msg); static long requireStrictlyPostive(long l); static long requireStrictlyPostive(long l, String msg); static int requirePostive(int i); static int requirePostive(int i, String msg); static int requireStrictlyPostive(int i); static int requireStrictlyPostive(int i, String msg); static Set<T> setWithoutNull(Set<T> set); static Set<T> setWithoutNull(Set<T> set, String msg);  }
@Test public void testRequireNonNull() { ArgCheck.requireNonNull(new Object()); try { ArgCheck.requireNonNull(null); Assert.fail("Should have thrown an NPE"); } catch (NullPointerException e) { } String msg = "msg"; ArgCheck.requireNonNull(new Object(), msg); try { ArgCheck.requireNonNull(null, msg); Assert.fail("Should have thrown an NPE"); } catch (NullPointerException e) { Assert.assertEquals(msg, e.getMessage()); } }