org.valid4j:valid4j

Simple assertion and validation library for Java

Лицензия

Лицензия

Группа

Группа

org.valid4j
Идентификатор

Идентификатор

valid4j
Последняя версия

Последняя версия

0.5.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

org.valid4j:valid4j
Simple assertion and validation library for Java
Ссылка на сайт

Ссылка на сайт

http://valid4j.org
Организация-разработчик

Организация-разработчик

valid4j
Система контроля версий

Система контроля версий

http://github.com/valid4j/valid4j/tree/master

Скачать valid4j

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.valid4j/valid4j/ -->
<dependency>
    <groupId>org.valid4j</groupId>
    <artifactId>valid4j</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.valid4j/valid4j/
implementation 'org.valid4j:valid4j:0.5.0'
// https://jarcasting.com/artifacts/org.valid4j/valid4j/
implementation ("org.valid4j:valid4j:0.5.0")
'org.valid4j:valid4j:jar:0.5.0'
<dependency org="org.valid4j" name="valid4j" rev="0.5.0">
  <artifact name="valid4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.valid4j', module='valid4j', version='0.5.0')
)
libraryDependencies += "org.valid4j" % "valid4j" % "0.5.0"
[org.valid4j/valid4j "0.5.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.hamcrest : hamcrest-core jar 1.3

test (3)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.hamcrest : hamcrest-library jar 1.3
org.mockito : mockito-core jar 1.10.17

Модули Проекта

Данный проект не имеет модулей.

valid4j

Build Status Coverage Status Maven Central

A simple assertion and validation library for Java which makes it possible to use your favorite hamcrest-matchers to express pre- and post-conditions in your code. Use the global default policy to signal logical violations in your code or optionally specify your own handling.

Full documentation is available at www.valid4j.org.

This library is available at Maven Central Repository. Add this dependency to your pom.xml

<dependency>
  <groupId>org.valid4j</groupId>
  <artifactId>valid4j</artifactId>
  <version>0.5.0</version>
</dependency>

Design-by-contract (assertions)

Statically import the library entry point:

import static org.valid4j.Assertive.*;

Use assertive preconditions to check for programming errors in calling clients:

// Express your preconditions using plain boolean expressions, with a helpful error message (optional)
require(v > 0.0, "The value (%f) must be positive", v);

// Or use hamcrest-matchers
require(v, containsString("great!"));

Use assertive postconditions to check for programming errors in your supplied code:

ensure(result != null);
ensure(result, greaterThan(3.0));

Make use of the convenient pass-through of valid objects:

// Initialize members with valid arguments
this.member = require(argument, notNullValue());

// Return valid results
return ensure(result, notNullValue());

Contract violations will contain a descriptive error message:

// E.g this contract
require("This message is bad", containsString("good"));

// Will yield this error
org.valid4j.exceptions.RequireViolation: expected: a string containing "good"
 but: was "This message is bad"

Validation (e.g. input validation)

Statically import the library entry point:

import static org.valid4j.Validation.*;

Use expressive hamcrest-matchers to validate input

validate(argument, isValid(), otherwiseThrowing(InvalidException.class));

Make use of the convenient pass-through of valid objects:

// Initialize members with valid arguments
this.member = validate(arg, isValid(), otherwiseThrowing(InvalidException.class));

Failed validations will contain a descriptive message:

// E.g this validation
validate("This message is bad", containsString("good"), IllegalArgumentException.class);

// Will yield this exception with message
// (NOTE: Exception class must accept one String argument in constructor for this feature to be supported)
java.lang.IllegalArgumentException: expected: a string containing "good"
 but: was "This message is bad"
org.valid4j

Версии библиотеки

Версия
0.5.0
0.4.0
0.3.0