Nolix logo

a Java library for business and science

← Nolix Validator

Tutorial: Validator

Validate that an argument is positive

public void addAmount(int amount) {
  Validator.assertThat(amount).isPositive();
  ...
}

Include the argument's name in the error message

public void addAmount(int amount) {
  Validator.assertThat(amount).thatIsNamed("amount").isPositive();
  ...
}

Validate that several strings are not empty

public void addAmount(String[] names) {
  Validator.assertThat(names).areNotEmpty();
  ...
}

Copyright © 2021 Silvan Wyss