Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
onacit committed Apr 27, 2024
1 parent 85d1eab commit 8626192
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 59 deletions.
139 changes: 98 additions & 41 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -32,7 +33,7 @@
<role>developer</role>
</roles>
<timezone>Asia/Seoul</timezone>
<properties />
<properties/>
</developer>
</developers>

Expand Down Expand Up @@ -214,7 +215,7 @@
<configuration>
<skip>true</skip>
<rules>
<dependencyConvergence />
<dependencyConvergence/>
</rules>
</configuration>
<goals>
Expand Down Expand Up @@ -784,46 +785,101 @@
<id>sub-hibernate-validator-referenceguide</id>
<dependencies>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.2.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>6.2.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>2.0.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>jakarta.interceptor</groupId>
<artifactId>jakarta.interceptor-api</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-jsr223</artifactId>
<version>2.4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>5.3.22</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11.0.2</version>
<!-- <scope>compile</scope>-->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.assertj</groupId>-->
<!-- <artifactId>assertj-core</artifactId>-->
<!-- <version>3.8.0</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.maven-surefire}</version>
<configuration>
<excludes>
<exclude>com.github.jinahya.**.*.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java-sub-hibernate-validator-referenceguide</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>sub-hibernate-validator-referenceguide-chapter01</id>
<build>
<plugins>
<plugin>
Expand All @@ -839,7 +895,8 @@
<configuration>
<sources>
<source>src/test/java-sub-hibernate-validator-referenceguide-chapter01</source>
<source>sub/hibernate-validator/documentation/src/test/java/org/hibernate/validator/referenceguide/chapter01</source>
<!-- <source>sub/hibernate-validator/documentation/src/test/java/org/hibernate/validator/referenceguide/chapter01</source>-->
<source>sub/hibernate-validator/documentation/src/test/java/org</source>
</sources>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ public final SELF isNotValid() {
return myself;
}

@Override
public SELF isNotValid(final Consumer<Set<ConstraintViolation<ACTUAL>>> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
isNotNull();
final Validator validator = delegate.getValidator();
final Class<?>[] groups = delegate.getGroups();
delegate.setViolations(validator.validate(actual, groups));
final Set<ConstraintViolation<ACTUAL>> violations = delegate.getViolations();
assertThat(violations)
.as("%nThe set of constraint violations resulted while validating%n"
+ "\tactual: %s%n"
+ "targeting%n"
+ "\tgroups: %s%n",
actual,
Arrays.asList(groups)
)
.withFailMessage("%nexpected to be not empty but empty")
.isNotEmpty();
consumer.accept(violations);
return myself;
}

@Override
public final SELF hasValidProperty(final String propertyName,
final Consumer<? super Set<ConstraintViolation<ACTUAL>>> consumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.assertj.core.api.AbstractObjectArrayAssert;
import org.assertj.core.api.Assert;
import org.assertj.core.api.AssertFactory;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.ObjectAssertFactory;

import javax.validation.ConstraintViolation;
Expand Down Expand Up @@ -106,6 +107,16 @@ A extractingConstraintDescriptor(
.extracting(ConstraintViolation::getLeafBean, new ObjectAssertFactory<>());
}

// --------------------------------------------------------------------------------------------------------- message

@Override
public SELF hasMessage(final String expectedMessage) {
isNotNull()
.extracting(ConstraintViolation::getMessage, InstanceOfAssertFactories.STRING)
.isEqualTo(expectedMessage);
return (SELF) this;
}

// ---------------------------------------------------------------------------------------------------- propertyPath
@Override
public <ASSERT extends AbstractPathAssert<?, ? extends AbstractPathAssert.AbstractNodeAssert<?>>> ASSERT extractingPropertyPath(final AssertFactory<? super Path, ? extends ASSERT> assertFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,22 @@ default SELF isValid() {
*}
*
* @return this assertion object.
* @throws AssertionError when the {@code actual} is {@code null} or invalid.
* @throws AssertionError when the {@code actual} is {@code null} or <em>valid</em>.
* @see #isValid(Consumer)
* @see #isValid()
*/
SELF isNotValid();

/**
* Verifies that the {@code actual} value is <em>not valid</em>, while accepts a set of constraint violations, which
* should be not empty, to specified consumer.
*
* @return this assertion object.
* @throws AssertionError when the {@code actual} is {@code null} or <em>valid</em>.
* @see #isNotValid()
*/
SELF isNotValid(final Consumer<Set<ConstraintViolation<ACTUAL>>> consumer);

/**
* Verifies that no constraint violations populated while validating all constraints placed on the property of
* specified name of the {@code actual} value, while accepts the set of constraint violations which may be empty to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
*/

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractCharacterAssert;
import org.assertj.core.api.AbstractClassAssert;
import org.assertj.core.api.AbstractObjectArrayAssert;
import org.assertj.core.api.Assert;
import org.assertj.core.api.AssertFactory;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.ObjectArrayAssert;
import org.assertj.core.api.ObjectAssertFactory;
Expand All @@ -42,6 +44,9 @@
* @param <ACTUAL> actual type parameter
* @param <T> root bean type parameter
*/
@SuppressWarnings({
"java:S119" // <SELF ...>
})
public interface ConstraintViolationAssert<
SELF extends ConstraintViolationAssert<SELF, ACTUAL, T>, ACTUAL extends ConstraintViolation<T>, T>
extends Assert<SELF, ACTUAL> {
Expand Down Expand Up @@ -209,6 +214,9 @@ default SELF doesNotHaveLeafBean() {
return hasLeafBean(null);
}

// --------------------------------------------------------------------------------------------------------- message
SELF hasMessage(final String expectedMessage);

// ---------------------------------------------------------------------------------------------------- propertyPath
<ASSERT extends AbstractPathAssert<?, ? extends AbstractPathAssert.AbstractNodeAssert<?>>> ASSERT extractingPropertyPath(
final AssertFactory<? super Path, ? extends ASSERT> assertFactory);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.hibernate.validator.referenceguide.chapter01;

import org.junit.jupiter.api.Test;

import static com.github.jinahya.assertj.validation.ValidationAssertions.assertThatBean;

/**
* .
*
* @see org.hibernate.validator.referenceguide.chapter01.CarTest
*/
class CarTest_Test {

/**
* .
*
* @see CarTest#manufacturerIsNull()
*/
@Test
void manufacturerIsNull__() {
final var car = new Car(null, "DD-AB-123", 4);
assertThatBean(car)
.isNotValid()
.doesNotHaveValidProperty(Car_Constants.PROPERTY_MANUFACTURER)
.hasValidProperty(Car_Constants.PROPERTY_LICENSE_PLATE)
;
}

/**
* .
*
* @see CarTest#licensePlateTooShort()
*/
@Test
void licensePlateTooShort__() {
final var car = new Car("Morris", "D", 4);
assertThatBean(car)
.isNotValid()
.doesNotHaveValidProperty(Car_Constants.PROPERTY_LICENSE_PLATE)
.hasValidProperty(Car_Constants.PROPERTY_MANUFACTURER)
.hasValidProperty(Car_Constants.PROPERTY_MANUFACTURER)
;
}

/**
* .
*
* @see CarTest#seatCountTooLow()
*/
@Test
void seatCountTooLow() {
final var car = new Car("Morris", "DD-AB-123", 1);
assertThatBean(car)
.isNotValid()
.doesNotHaveValidProperty(Car_Constants.PROPERTY_SEAT_COUNT)
.hasValidProperty(Car_Constants.PROPERTY_MANUFACTURER)
.hasValidProperty(Car_Constants.PROPERTY_LICENSE_PLATE)
;
}

/**
* .
*
* @see CarTest#carIsValid()
*/
@Test
void carIsValid() {
final var car = new Car("Morris", "DD-AB-123", 2);
assertThatBean(car)
.isValid()
.hasValidProperty(Car_Constants.PROPERTY_LICENSE_PLATE)
.hasValidProperty(Car_Constants.PROPERTY_MANUFACTURER)
.hasValidProperty(Car_Constants.PROPERTY_SEAT_COUNT)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
* #L%
*/

final class CarConstants {
final class Car_Constants {

static final String PROPERTY_MANUFACTURER = "manufacturer";

static final String PROPERTY_LICENSE_PLATE = "licensePlate";

static final String PROPERTY_SEAT_COUNT = "seatCount";

private CarConstants() {
private Car_Constants() {
throw new AssertionError("instantiation is not allowed");
}
}
Loading

0 comments on commit 8626192

Please sign in to comment.