ConsistencyUtils { public static String checkEmptyString(String object, String message) { object = checkNotNull(object, message); if (object.trim() == "") { throw new NullPointerException(message); } return object; } private  ConsistencyUtils(); static T checkNotNull(T object); static T checkNotNull(T object, String message); static String checkEmptyString(String object, String message); static String checkEmptyString(String object); static T checkInstance(Object obj, Class<T> type); static Collection<T> checkNotEmpty(Collection<T> container); static Collection<T> containsNoNulls(Collection<T> container);  }
@Test public void utilsEmptyStringTestNull() { thrown.expect(Exception.class); thrown.expectMessage("This String cannot be null"); ConsistencyUtils.checkEmptyString(null, "This String cannot be null"); }
@Test public void utilsEmptyStringTestEmpty() { thrown.expect(Exception.class); thrown.expectMessage("This String cannot be empty"); ConsistencyUtils.checkEmptyString("", "This String cannot be empty"); }
@Test public void utilsEmptyStringTestNullNoMessage() { thrown.expect(NullPointerException.class); ConsistencyUtils.checkEmptyString(null); }
@Test public void utilsEmptyStringTestOK() { String testString = ConsistencyUtils.checkEmptyString("Hello World"); assertEquals(testString, "Hello World"); }