Utils { @NonNull static <T> T checkNotNull(@Nullable final T reference, final String message) { if (reference == null) { throw new IllegalArgumentException(message); } return reference; } private  Utils();   }
@Test public void checkNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("param is null"); Utils.checkNotNull(null, "param is null"); }
@Test public void checkNotNull() { Utils.checkNotNull("valid", "null is null"); }
@Test public void checkNotNullNoNull() { assertThat(checkNotNull(5, "should never be")).isEqualTo(5); assertThat(checkNotNull("5", "should never be")).isEqualTo("5"); assertThat(checkNotNull(3f, "should never be")).isEqualTo(3f); }
@Test public void checkNotNullNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("null == null"); checkNotNull(null, "null == null"); }