-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-1863 Add an annotation processor test for records
Signed-off-by: Jan Schatteman <[email protected]>
- Loading branch information
Showing
6 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...est/java17/org/hibernate/validator/ap/record/RecordConstraintValidationProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.ap.record; | ||
|
||
import java.io.File; | ||
import java.util.EnumSet; | ||
|
||
import javax.tools.Diagnostic; | ||
|
||
import org.hibernate.validator.ap.ConstraintValidationProcessor; | ||
import org.hibernate.validator.ap.ConstraintValidationProcessorTestBase; | ||
import org.hibernate.validator.ap.testutil.CompilerTestHelper; | ||
import org.hibernate.validator.ap.util.DiagnosticExpectation; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.hibernate.validator.ap.testutil.CompilerTestHelper.assertThatDiagnosticsMatch; | ||
import static org.testng.Assert.assertFalse; | ||
|
||
/** | ||
* @author Jan Schatteman | ||
*/ | ||
public class RecordConstraintValidationProcessorTest extends ConstraintValidationProcessorTestBase { | ||
|
||
@Test | ||
public void testRecordWithInvalidConstraints() { | ||
|
||
File sourceFile = compilerHelper.getSourceFile( RecordWithInvalidConstraints.class, "/src/test/java17" ); | ||
|
||
boolean compilationResult = | ||
compilerHelper.compile( | ||
new ConstraintValidationProcessor(), | ||
diagnostics, | ||
EnumSet.of( CompilerTestHelper.Library.VALIDATION_API ), | ||
sourceFile | ||
); | ||
|
||
assertFalse( compilationResult ); | ||
|
||
assertThatDiagnosticsMatch( | ||
diagnostics, | ||
new DiagnosticExpectation( Diagnostic.Kind.ERROR, 15 ) | ||
); | ||
} | ||
|
||
@Test | ||
public void testRecordWithInvalidConstructorConstraints() { | ||
|
||
File sourceFile = compilerHelper.getSourceFile( RecordWithInvalidConstructorConstraints.class, "/src/test/java17" ); | ||
|
||
boolean compilationResult = | ||
compilerHelper.compile( | ||
new ConstraintValidationProcessor(), | ||
diagnostics, | ||
EnumSet.of( CompilerTestHelper.Library.VALIDATION_API ), | ||
sourceFile | ||
); | ||
|
||
assertFalse( compilationResult ); | ||
|
||
assertThatDiagnosticsMatch( | ||
diagnostics, | ||
new DiagnosticExpectation( Diagnostic.Kind.ERROR, 16 ) | ||
); | ||
} | ||
|
||
@Test | ||
public void testRecordWithInvalidMethodConstraints() { | ||
|
||
File sourceFile = compilerHelper.getSourceFile( RecordWithInvalidMethodConstraints.class, "/src/test/java17" ); | ||
|
||
boolean compilationResult = | ||
compilerHelper.compile( | ||
new ConstraintValidationProcessor(), | ||
diagnostics, | ||
EnumSet.of( CompilerTestHelper.Library.VALIDATION_API ), | ||
sourceFile | ||
); | ||
|
||
assertFalse( compilationResult ); | ||
|
||
assertThatDiagnosticsMatch( | ||
diagnostics, | ||
new DiagnosticExpectation( Diagnostic.Kind.ERROR, 19 ) | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...essor/src/test/java17/org/hibernate/validator/ap/record/RecordWithInvalidConstraints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.ap.record; | ||
|
||
import java.util.Date; | ||
import javax.validation.constraints.FutureOrPresent; | ||
|
||
/** | ||
* @author Jan Schatteman | ||
*/ | ||
public record RecordWithInvalidConstraints(/* Not allowed */ @FutureOrPresent String string, @FutureOrPresent Date date) { | ||
} |
20 changes: 20 additions & 0 deletions
20
...est/java17/org/hibernate/validator/ap/record/RecordWithInvalidConstructorConstraints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.ap.record; | ||
|
||
import java.util.Date; | ||
import javax.validation.constraints.FutureOrPresent; | ||
|
||
/** | ||
* @author Jan Schatteman | ||
*/ | ||
public record RecordWithInvalidConstructorConstraints(String string, Date date) { | ||
public RecordWithInvalidConstructorConstraints(@FutureOrPresent String string, @FutureOrPresent Date date) { | ||
this.string = string; | ||
this.date = date; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...src/test/java17/org/hibernate/validator/ap/record/RecordWithInvalidMethodConstraints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.validator.ap.record; | ||
|
||
import java.util.Date; | ||
import javax.validation.constraints.FutureOrPresent; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.Positive; | ||
|
||
/** | ||
* @author Jan Schatteman | ||
*/ | ||
public record RecordWithInvalidMethodConstraints(@NotBlank String string, @FutureOrPresent Date date) { | ||
|
||
public void doNothing(@Positive String s) { | ||
// | ||
} | ||
} |