List of utility methods to do Assert
void | assertStringNotEmpty(String str, String name) Check if the string is empty. assertObjectNotNull(str, name); if (str.trim().length() == 0) { throw new IllegalArgumentException("the string " + name + " should not be empty."); |
String | assertStringNotEmpty(String string, String fieldName) Asserts that the string is not empty. assertNotNull(string, fieldName); if (string.isEmpty()) { throw new IllegalArgumentException(String.format("%s cannot be empty", fieldName)); return string; |
void | assertTesting() Assert that we are running JUnit tests. try { Class.forName("junit.framework.TestCase"); } catch (ClassNotFoundException e) { throw new IllegalStateException("This method must only be used by JUnit tests."); |
void | assertThrows(Class extends Exception> exception, Runnable action) assert Throws try { action.run(); throw new AssertionError( "Expected exception: " + exception.getTypeName() + ", but no exception thrown"); } catch (Exception e) { if (!e.getClass().equals(exception)) { throw new AssertionError("Expected exception: " + exception.getTypeName() + ", but was " + e.getClass().getTypeName()); ... |
void | assertTwoParameters(Class clz, String method, double... args) assert Two Parameters if (args == null || args.length != 2) throw new IllegalArgumentException(clz.getName() + "." + method + "(...) is only supported for two parameters (got " + args.length + ")"); |
T | assertUnreachable() assert Unreachable throw new AssertionError("Unreachable."); |
void | assertValid(int piece) assert Valid if (!isValid(piece)) { throw new IllegalArgumentException("Invalid piece: " + piece); |
void | assertValidBrowserType(int aBrowserType) assert Valid Browser Type switch (aBrowserType) { case BROWSER_WAP: case BROWSER_COMPANY: case BROWSER_WIFI: case BROWSER_UNITE: return; throw new IllegalArgumentException("Not a valid browser type"); ... |
void | assertValidColumnName(String name) assert Valid Column Name for (char c : name.toCharArray()) { if (c == '.') continue; if (Character.isJavaIdentifierPart(c)) continue; throw new IllegalArgumentException("invalid character in field name"); |
void | assertValidItemName(String itemName) Ensures that the specified name of the item is valid. if (!isValidItemName(itemName)) { throw new IllegalArgumentException("The specified name of the item '" + itemName + "' is not valid!"); |