List of utility methods to do Assert
void | assertContains(String needle, String haystack) assert Contains if (haystack.contains(needle)) return; throw new AssertionError("The string '" + haystack + "' does not contain '" + needle + "'."); |
void | assertDescriptorName(String key) assert Descriptor Name assert key != null; assert key.indexOf(GROUP_SEPARATOR) == -1 : key + " contains invalid chars"; assert key.indexOf(GROUPS_SEPARATOR) == -1 : key + " contains invalid chars"; assert key.indexOf(GROUP_VALUE_SEPARATOR) == -1 : key + " contains invalid chars"; assert !key.contains("=") : key + " contains invalid chars"; assert !key.contains("'") : key + " contains invalid chars"; assert !key.contains("\"") : key + " contains invalid chars"; |
void | assertDidNotThrow(final Runnable r) If Java assertions are enabled, execute the given Runnable , and assert(false) if it throws any Throwable . Can be used for asserting upon stuff which does not return false upon error but throws: A regular Java assert could only consume boolean-returning functions. The Throwable will be passed as message to the assert, it will not be thrown. boolean execute = false; assert (execute = true); if (execute) { try { r.run(); } catch (Throwable t) { assert (false) : t; |
void | assertDifferentInstance(final Object o1, final Object o2) assert Different Instance if (o1 == o2) { throw new AssertionError("The compared objects are the same instance of a class"); |
void | assertDotted(String name) assert Dotted if (name.indexOf("/") != -1) { throw new IllegalStateException("Expected a dotted name but was passed " + name); |
int | assertEntryCount(final long entryCount) Dynamic sharding operations are not currently supported for indices with more than MAX_INT tuples. if (entryCount >= Integer.MAX_VALUE) throw new UnsupportedOperationException("More than GT MAX_INT tuples: n=" + entryCount); return (int) entryCount; |
void | assertEnvVarPresent(String envVarKey, String errorMessage) assert Env Var Present if (System.getenv(envVarKey) == null) { throw new IllegalArgumentException(errorMessage); |
void | assertException(Runnable task, Class> clazz) assert Exception try { task.run(); throw new AssertionError(String.format("expected exception of type %s", clazz.getSimpleName())); } catch (Exception ex) { if (!ex.getClass().isAssignableFrom(clazz)) { new AssertionError(String.format("expected exception of type %s but found exception of type %s", clazz.getCanonicalName(), ex.getClass().getCanonicalName())); |
void | assertFact(boolean truth, String failure) assert Fact if (!truth) { System.err.println("assertion failed: " + failure); System.exit(1); |
void | assertFailed(Object expression, Object message) assert Failed if (message == null || "".equals(message)) { throw new AssertionError("Expression: " + expression); } else { throw new AssertionError("" + message + ". Expression: " + expression); |