ArgCheck { static public long requirePostive(long l) throws IllegalArgumentException { return requirePostive(l, "long value must be positive"); } 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 testRequirePositiveLong() { ArgCheck.requirePostive(1L); ArgCheck.requirePostive(0L); try { ArgCheck.requirePostive(-1L); Assert.fail("Should have thrown an NPE"); } catch (IllegalArgumentException e) { } String msg = "msg"; ArgCheck.requirePostive(1L, msg); ArgCheck.requirePostive(0L, msg); try { ArgCheck.requirePostive(-1L, msg); Assert.fail("Should have thrown an NPE"); } catch (IllegalArgumentException e) { Assert.assertEquals(msg, e.getMessage()); } }
@Test public void testRequirePositiveInteger() { ArgCheck.requirePostive(1); ArgCheck.requirePostive(0); try { ArgCheck.requirePostive(-1); Assert.fail("Should have thrown an NPE"); } catch (IllegalArgumentException e) { } String msg = "msg"; ArgCheck.requirePostive(1, msg); ArgCheck.requirePostive(0, msg); try { ArgCheck.requirePostive(-1, msg); Assert.fail("Should have thrown an NPE"); } catch (IllegalArgumentException e) { Assert.assertEquals(msg, e.getMessage()); } }