[hibernate-commits] Hibernate SVN: r20120 - validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sun Aug 8 05:53:03 EDT 2010


Author: gunnar.morling
Date: 2010-08-08 05:53:03 -0400 (Sun, 08 Aug 2010)
New Revision: 20120

Added:
   validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
   validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java
Modified:
   validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTest.java
Log:
HV-299: Extract separate test for test cases related to annotation type checking

Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java	2010-08-08 09:53:03 UTC (rev 20120)
@@ -0,0 +1,53 @@
+// $Id: AnnotationTypeValidationTest.java 19525 2010-05-15 16:05:09Z gunnar.morling $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap;
+
+import java.io.File;
+import javax.tools.Diagnostic.Kind;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.ap.testmodel.constrainttypes.ValidCustomerNumber;
+import org.hibernate.validator.ap.util.DiagnosticExpectation;
+
+import static org.hibernate.validator.ap.testutil.CompilerTestHelper.assertThatDiagnosticsMatch;
+import static org.testng.Assert.assertFalse;
+
+/**
+ * Test cases for {@link ConstraintValidationProcessor} testing the checking of constraint
+ * annotation type declarations.
+ *
+ * @author Gunnar Morling.
+ */
+public class AnnotationTypeValidationTest extends ConstraintValidationProcessorTestBase {
+
+	@Test
+	public void testThatSpecifyingConstraintAnnotationAtNonConstraintAnnotationTypeCausesCompilationError() {
+
+		File sourceFile = compilerHelper.getSourceFile( ValidCustomerNumber.class );
+
+		boolean compilationResult =
+				compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
+
+		assertFalse( compilationResult );
+		assertThatDiagnosticsMatch(
+				diagnostics, new DiagnosticExpectation( Kind.ERROR, 28 ), new DiagnosticExpectation( Kind.ERROR, 29 )
+		);
+	}
+
+}

Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTest.java	2010-08-06 22:00:52 UTC (rev 20119)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTest.java	2010-08-08 09:53:03 UTC (rev 20120)
@@ -20,12 +20,7 @@
 import java.io.File;
 import javax.tools.Diagnostic;
 import javax.tools.Diagnostic.Kind;
-import javax.tools.DiagnosticCollector;
-import javax.tools.JavaFileObject;
-import javax.tools.ToolProvider;
 
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import org.hibernate.validator.ap.testmodel.FieldLevelValidationUsingBuiltInConstraints;
@@ -58,59 +53,25 @@
 import org.hibernate.validator.ap.testmodel.inheritedvalidator.CustomConstraint;
 import org.hibernate.validator.ap.testmodel.inheritedvalidator.CustomConstraintValidator;
 import org.hibernate.validator.ap.testmodel.inheritedvalidator.FieldLevelValidationUsingInheritedValidator;
-import org.hibernate.validator.ap.testmodel.invalidcomposedconstraint.ValidCustomerNumber;
 import org.hibernate.validator.ap.testmodel.nouniquevalidatorresolution.NoUniqueValidatorResolution;
 import org.hibernate.validator.ap.testmodel.nouniquevalidatorresolution.SerializableCollection;
 import org.hibernate.validator.ap.testmodel.nouniquevalidatorresolution.Size;
 import org.hibernate.validator.ap.testmodel.nouniquevalidatorresolution.SizeValidatorForCollection;
 import org.hibernate.validator.ap.testmodel.nouniquevalidatorresolution.SizeValidatorForSerializable;
 import org.hibernate.validator.ap.testmodel.nouniquevalidatorresolution.SizeValidatorForSet;
-import org.hibernate.validator.ap.testutil.CompilerTestHelper;
 import org.hibernate.validator.ap.util.DiagnosticExpectation;
 
 import static org.hibernate.validator.ap.testutil.CompilerTestHelper.assertThatDiagnosticsMatch;
 import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
 /**
- * Test for {@link ConstraintValidationProcessor} using the Java compiler
- * API as defined by JSR 199.
+ * Miscellaneous tests for {@link ConstraintValidationProcessor}.
  *
  * @author Gunnar Morling.
  */
-public class ConstraintValidationProcessorTest {
+public class ConstraintValidationProcessorTest extends ConstraintValidationProcessorTestBase {
 
-	private static CompilerTestHelper compilerHelper;
-
-	private DiagnosticCollector<JavaFileObject> diagnostics;
-
-	@BeforeClass
-	public static void setUpCompilerHelper() {
-
-		String testSourceBaseDir = System.getProperty( "testSourceBaseDir" );
-		String pathToBeanValidationApiJar = System.getProperty( "pathToBeanValidationApiJar" );
-
-		assertNotNull(
-				testSourceBaseDir,
-				"The system property testSourceBaseDir has to be set and point to the base directory of the test java sources."
-		);
-		assertNotNull(
-				pathToBeanValidationApiJar,
-				"The system property pathToBeanValidationApiJar has to be set and point to the BV API Jars."
-		);
-
-		compilerHelper =
-				new CompilerTestHelper(
-						ToolProvider.getSystemJavaCompiler(), testSourceBaseDir, pathToBeanValidationApiJar
-				);
-	}
-
-	@BeforeMethod
-	public void setUp() {
-		diagnostics = new DiagnosticCollector<JavaFileObject>();
-	}
-
 	@Test
 	public void fieldLevelValidationUsingBuiltInConstraints() {
 
@@ -302,20 +263,6 @@
 	}
 
 	@Test
-	public void testThatSpecifyingConstraintAnnotationAtNonConstraintAnnotationTypeCausesCompilationError() {
-
-		File sourceFile = compilerHelper.getSourceFile( ValidCustomerNumber.class );
-
-		boolean compilationResult =
-				compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
-
-		assertFalse( compilationResult );
-		assertThatDiagnosticsMatch(
-				diagnostics, new DiagnosticExpectation( Kind.ERROR, 28 ), new DiagnosticExpectation( Kind.ERROR, 29 )
-		);
-	}
-
-	@Test
 	public void testThatNonUniqueValidatorResolutionCausesCompilationError() {
 
 		File sourceFile1 = compilerHelper.getSourceFile( NoUniqueValidatorResolution.class );

Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTestBase.java	2010-08-08 09:53:03 UTC (rev 20120)
@@ -0,0 +1,69 @@
+// $Id: ConstraintValidationProcessorTestBase.java 19033 Aug 8, 2010 11:14:14 AM gunnar.morling $
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap;
+
+import javax.tools.DiagnosticCollector;
+import javax.tools.JavaFileObject;
+import javax.tools.ToolProvider;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+
+import org.hibernate.validator.ap.testutil.CompilerTestHelper;
+
+import static org.testng.Assert.assertNotNull;
+
+/**
+ * Base class providing common functionality for all tests for the constraint validation processor using the Java compiler
+ * API as defined by JSR 199.
+ *
+ * @author Gunnar Morling
+ */
+public abstract class ConstraintValidationProcessorTestBase {
+
+	protected static CompilerTestHelper compilerHelper;
+
+	protected DiagnosticCollector<JavaFileObject> diagnostics;
+
+	@BeforeClass
+	public static void setUpCompilerHelper() {
+
+		String testSourceBaseDir = System.getProperty( "testSourceBaseDir" );
+		String pathToBeanValidationApiJar = System.getProperty( "pathToBeanValidationApiJar" );
+
+		assertNotNull(
+				testSourceBaseDir,
+				"The system property testSourceBaseDir has to be set and point to the base directory of the test java sources."
+		);
+		assertNotNull(
+				pathToBeanValidationApiJar,
+				"The system property pathToBeanValidationApiJar has to be set and point to the BV API Jars."
+		);
+
+		compilerHelper =
+				new CompilerTestHelper(
+						ToolProvider.getSystemJavaCompiler(), testSourceBaseDir, pathToBeanValidationApiJar
+				);
+	}
+
+	@BeforeMethod
+	public void setUpDiagnostics() {
+		diagnostics = new DiagnosticCollector<JavaFileObject>();
+	}
+
+}
\ No newline at end of file



More information about the hibernate-commits mailing list