Utils { static <T> T checkNotNull(T object, String message) { if (object == null) { throw new NullPointerException(message); } return object; } private  Utils();   }
@Test public void checkNotNull_valid() { String data = "string"; String sameAsData = Utils.checkNotNull(data, "data == null"); assertEquals(data, sameAsData); Object o1 = Arrays.asList(1, 2, 3); Object sameAsO1 = Utils.checkNotNull(o1, "o1 == null"); assertEquals(o1, sameAsO1); }
@Test(expected = NullPointerException.class) public void checkNotNull_invalid() { Utils.checkNotNull(null, "data == null"); }