Skip to content

Latest commit

 

History

History
25 lines (16 loc) · 975 Bytes

assertions.md

File metadata and controls

25 lines (16 loc) · 975 Bytes

Assertions

The Assert class contains some utilities to make some basic input checks.

Those assertions are done at runtime, and they will result in an exception if the condition is not met. Considering the slow feedback loop we recommend first relying on types for input validations (so you'll have a compile time checks).

Those assertions are designed for very simple, technical related checks. If you want to make business facing checks, you should create your own exceptions && check mechanism dedicated to business validations.

Usage

There are 2 ways of doing assertions, the first is "simple checks":

Assert.notNull("field", value);

The first parameter is the name of the parameter (used in the exception message) and the second one is the value to check. In this first usage, you check a simple condition.

You can also use the Assert class with types specific checks:

Assert.field("name", name)
  .notBlank()
  .maxLength(150);