modified: javaxval/.gitignore

new file:   javaxval/bin/.gitignore
	new file:   javaxval/bin/pom.xml
	deleted:    javaxval/src/test/java/sample/ValidationTest.java
This commit is contained in:
mnkartik 2015-10-18 12:35:45 +05:30
parent a1c6203179
commit c96ac1059a
4 changed files with 58 additions and 69 deletions

2
javaxval/.gitignore vendored
View File

@ -2,5 +2,5 @@
.project
.settings/
target/
bin/

6
javaxval/bin/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.classpath
.project
.settings/
target/

51
javaxval/bin/pom.xml Normal file
View File

@ -0,0 +1,51 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>javaxval</artifactId>
<version>0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>5.2.1.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies>
</project>

View File

@ -1,68 +0,0 @@
package sample;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import org.junit.Assert;
import org.junit.Test;
import sample.model.User;
public class ValidationTest {
@Test
public void ifNameIsNull_nameValidationFails() {
User user = new User();
user.setWorking(true);
user.setAboutMe("Its all about me!!");
user.setAge(50);
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<User>> violations = validator.validate(user);
Assert.assertEquals(violations.isEmpty(), false);
}
@Test
public void ifSizeNotInRange_aboutMeValidationFails() {
User user = new User();
user.setName("MyName");
user.setAboutMe("Its all about me!!");
user.setAge(50);
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<User>> violations = validator.validate(user);
Assert.assertEquals(violations.isEmpty(), false);
}
@Test
public void ifWorkingIsFalse_workingValidationFails() {
User user = new User();
user.setName("MyName");
user.setAboutMe("Its all about me!!");
user.setAge(50);
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<User>> violations = validator.validate(user);
Assert.assertEquals(violations.isEmpty(), false);
}
@Test
public void ifAgeNotRange_ageValidationFails() {
User user = new User();
user.setName("MyName");
user.setAboutMe("Its all about me!!");
user.setAge(8);
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<User>> violations = validator.validate(user);
Assert.assertEquals(violations.isEmpty(), false);
}
}