CashierInfoTest.java
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
...
@BeforeClass
public static void setupClass() {
final ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
validator = vf.getValidator();
}
...
@Test
public void testCashierInfo() throws Exception {
final char[] arr = new char[50];
Arrays.fill(arr, 'S');
final CashierInfo info = new CashierInfo(0, new String(arr), "0123456789012345");
final Set<ConstraintViolation<CashierInfo>> violations = validator.validate(info);
assertFalse(violations.isEmpty());
}
=====
pom.xml
---
...
<validation-api.version>1.1.0.Final</validation-api.version>
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
<el-api.version>2.2.4</el-api.version>
...
<!-- Validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${validation-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>${el-api.version}</version>
<scope>test</scope>
</dependency>