Cell API
    Preparing search index...

    Class AssertAbstract

    Index
    • Assert that the given text does not contain the given substring.

      Parameters

      • textToSearch: string | undefined

        the text to search

      • substring: string

        the substring to find within the text

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the text contains the substring

      Assert.doesNotContain(name, forbidden, "Name must not contain '" + forbidden + "'");
      Assert.doesNotContain(name, forbidden,
      () => "Name must not contain '" + forbidden + "'");
    • Assert that the given String is not empty; that is, it must not be undefined and not the empty String.

      Parameters

      • text: string | undefined

        the String to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the text is empty

      Assert.hasLength(name, "Name must not be empty");
      Assert.hasLength(name, () => "Name for account '" + account.getId() + "' must not be empty");
    • Assert that the given String contains valid text content; that is, it must not be undefined and must contain at least one non-whitespace character.

      Parameters

      • text: string | undefined

        the String to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the text does not contain valid text content

      Assert.hasText(account.getName(), "Name must not be empty");
      Assert.hasText(account.getName(),
      () => "Name for account '" + account.getId() + "' must not be empty");
    • Assert that superType.isAssignableFrom(subType) is true.

      Parameters

      • superType: unknown

        the supertype to check against

      • subType: any

        the subtype to check

      • Optionalmessage: string | (() => string)

        a message which will be prepended to provide further context. If it is empty or ends in ":" or ";" or "," or ".", a full exception message will be appended. If it ends in a space, the name of the offending subtype will be appended. In any other case, a ":" with a space and the name of the offending subtype will be appended.

      Returns void

      IllegalStateError if the classes are not assignable

      Assert.isAssignable(Number, myClass, "Number expected");
      Assert.isAssignable(Number, myClass, () => "Processing " + myAttributeName + ":");
    • Assert that the provided object is an instance of the provided class.

      Parameters

      • type: any

        the type to check against

      • obj: unknown

        the object to check

      • Optionalmessage: string | (() => string)

        a message which will be prepended to provide further context. If it is empty or ends in ":" or ";" or "," or ".", a full exception message will be appended. If it ends in a space, the name of the offending object's type will be appended. In any other case, a ":" with a space and the name of the offending object's type will be appended.

      Returns void

      IllegalStateError if the object is not an instance of type

      Assert.instanceOf(Foo, foo, "Foo expected");
      Assert.instanceOf(Foo, foo, () => "Processing " + Foo.name + ":");
      Assert.instanceOf(Foo, foo);
    • Assert that an object is undefined.

      Parameters

      • object: any

        the object to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the object is not undefined

      Assert.isNull(value, "The value must be null");
      Assert.isNull(value, () => "The value '" + value + "' must be null");
    • Assert a boolean expression, throwing an IllegalStateError if the expression evaluates to false.

      Parameters

      • expression: boolean

        a boolean expression

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if expression is false

      Assert.isTrue(i > 0, "The value must be greater than zero");
      Assert.isTrue(i > 0, () => "The value '" + i + "' must be greater than zero");
    • Assert that an array contains no undefined elements.

      Note: Does not complain if the array is empty!

      Parameters

      • array: unknown[] | undefined

        the array to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the object array contains a undefined element

      Assert.noNullElements(array, "The array must contain non-null elements");
      Assert.noNullElements(array, () => "The " + arrayType + " array must contain non-null elements");
    • Assert that a collection contains no undefined elements.

      Note: Does not complain if the collection is empty!

      Parameters

      • collection: unknown[] | undefined

        the collection to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the collection contains a undefined

      Assert.noNullElements(collection, "Collection must contain non-null elements");
      Assert.noNullElements(collection, () => "The " + collectionName + " must contain non-null elements");
    • Assert that an array contains elements; that is, it must not be undefined and must contain at least one element.

      Parameters

      • array: unknown[] | undefined

        the array to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the object array is undefined or contains no elements

      Assert.notEmpty(array, "The array must contain elements");
      Assert.notEmpty(array, () => "The " + arrayType + " array must contain elements");
    • Assert that a collection contains elements; that is, it must not be undefined and must contain at least one element.

      Parameters

      • collection: unknown[] | undefined

        the collection to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the collection is undefined or contains no elements

      Assert.notEmpty(collection, "Collection must contain elements");
      Assert.notEmpty(collection, () => "The " + collectionType + " collection must contain elements");
    • Assert that a Map contains entries; that is, it must not be undefined and must contain at least one entry.

      Parameters

      • map: Map<unknown, unknown> | undefined

        the map to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the map is undefined or contains no entries

      Assert.notEmpty(map, "The map must contain entries");
      Assert.notEmpty(map, () => "The " + mapType + " map must contain entries");
    • Assert that an object is not undefined.

      Parameters

      • object: unknown

        the object to check

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if the object is undefined

      Assert.notNull(clazz, "The class must not be null");
      Assert.notNull(entity.getId(),
      () => "ID for entity " + entity.getName() + " must not be null");
    • Assert a boolean expression, throwing an IllegalStateError if the expression evaluates to false.

      Parameters

      • expression: boolean

        a boolean expression

      • message: string | (() => string)

        the exception message to use if the assertion fails

      Returns void

      IllegalStateError if expression is false

      Assert.state(id === undefined, "The id property must not already be initialized");
      Assert.state(entity.getId() === undefined,
      () => "ID for entity " + entity.getName() + " must not already be initialized");