Java Utililty Methods Assert

List of utility methods to do Assert

Description

The list of methods to do Assert are organized into topic(s).

Method

voidassertIOThread(Thread t, boolean flag)
assert IO Thread
if (flag) {
    assert t.equals(Thread.currentThread()) : "Management NOT on IO thread when expected"; 
} else {
    assert !(t.equals(Thread.currentThread())) : "Management on IO thread when not expected"; 
voidassertIsClass(Class klazz)
assert Is Class
assertionIllegalArgument(isClass(klazz), "Type " + klazz + " must not be an interface.");
voidassertIsNotEmptyString(String string)
assert Is Not Empty String
if (string.isEmpty()) {
    throw new IllegalArgumentException("string can't be empty.");
voidassertIsPermutation(int[] perm)
assert Is Permutation
boolean hit[] = new boolean[perm.length];
for (int i : perm) {
    assert !hit[i];
    hit[i] = true;
intassertIsPositive(int num, String fieldName)
Asserts that the given number is positive (non-negative and non-zero).
if (num <= 0) {
    throw new IllegalArgumentException(String.format("%s must be positive", fieldName));
return num;
voidassertIsProb(double x)
assert Is Prob
assert isProb(x) : "Not a probability [0, 1]: " + x;
voidassertIsProbability(final double probability)
Checks to make sure that probability is between 0.0 and 1.0.
if (probability < 0.0 || probability > 1.0) {
    throw new IllegalArgumentException("Probability (" + probability + ") must be in [0.0, 1.0]");
voidassertIsProperlyQuoted(String header, String tag)
assert Is Properly Quoted
if (tag.length() < 2 || !tag.startsWith(QUOTATION_MARK) || !tag.endsWith(QUOTATION_MARK)) {
    throw new IllegalArgumentException(MISFORMATTED_ENTITY_TAG + header);
voidassertIsReady()
assert Is Ready
if (!ready) {
    throw new IllegalStateException("System is not ready for remote calls. "
            + "When beans are making remote calls in initialization, it's better to "
            + "implement io.servicecomb.core.BootListener and do it after EventType.AFTER_REGISTRY.");
voidassertLegal(Object underAssertion, String message)
assert Legal
assertionIllegalArgument(underAssertion != null, message);