incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r931208 - in /incubator/bval/sandbox/guice-integration/src: main/java/org/apache/bval/extentions/guice/ test/java/org/apache/bval/extentions/guice/
Date Tue, 06 Apr 2010 16:17:17 GMT
Author: simonetripodi
Date: Tue Apr  6 16:17:17 2010
New Revision: 931208

URL: http://svn.apache.org/viewvc?rev=931208&view=rev
Log:
no needs to define a proper ValidationException, reused the javax.validation.ConstraintViolation
instead
test refactored using a proper DI

Removed:
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationException.java
Modified:
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
    incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java

Modified: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java?rev=931208&r1=931207&r2=931208&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
(original)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
Tue Apr  6 16:17:17 2010
@@ -19,6 +19,7 @@ import java.util.HashSet;
 import java.util.Set;
 
 import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
 import javax.validation.Validator;
 
 import org.aopalliance.intercept.MethodInterceptor;
@@ -52,14 +53,14 @@ public final class ValidateMethodInterce
      * {@inheritDoc}
      */
     public Object invoke(MethodInvocation invocation) throws Throwable {
-        Set<ConstraintViolation<Object>> constraintViolations = new HashSet<ConstraintViolation<Object>>();
+        Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();
 
         for (Object arg : invocation.getArguments()) {
             constraintViolations.addAll(this.validator.validate(arg));
         }
 
         if (!constraintViolations.isEmpty()) {
-            throw new ValidationException(constraintViolations);
+            throw new ConstraintViolationException(constraintViolations);
         }
 
         return invocation.proceed();

Modified: incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java?rev=931208&r1=931207&r2=931208&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java
(original)
+++ incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java
Tue Apr  6 16:17:17 2010
@@ -24,6 +24,7 @@ import javax.validation.Validator;
 import junit.framework.TestCase;
 
 import com.google.inject.Guice;
+import com.google.inject.Inject;
 import com.google.inject.Injector;
 
 /**
@@ -33,16 +34,33 @@ import com.google.inject.Injector;
  */
 public final class GuiceAwareValidationTestCase extends TestCase {
 
+    @Inject
+    private Validator validator;
+
+    @Inject
+    private DummyCountryDao dummyCountryDao;
+
+    public void setValidator(Validator validator) {
+        this.validator = validator;
+    }
+
+    public void setDummyCountryDao(DummyCountryDao dummyCountryDao) {
+        this.dummyCountryDao = dummyCountryDao;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        Injector injector = Guice.createInjector(new ValidationModule());
+        injector.injectMembers(this);
+    }
+
     public void testInjectedValidation() {
         Country country = new Country();
         country.setName("Italy");
         country.setIso2Code("it");
         country.setIso3Code("ita");
 
-        Injector injector = Guice.createInjector(new ValidationModule());
-        Validator validator = injector.getInstance(Validator.class);
-
-        Set<ConstraintViolation<Country>> violations = validator.validate(country);
+        Set<ConstraintViolation<Country>> violations = this.validator.validate(country);
         assertTrue(violations.isEmpty());
     }
 
@@ -52,12 +70,9 @@ public final class GuiceAwareValidationT
         country.setIso2Code("ita");
         country.setIso3Code("ita");
 
-        Injector injector = Guice.createInjector(new ValidationModule());
-        DummyCountryDao dummyCountryDao = injector.getInstance(DummyCountryDao.class);
-
         try {
-            dummyCountryDao.insertCountry(country);
-            fail("org.apache.bval.extentions.guice.ValidationException expected");
+            this.dummyCountryDao.insertCountry(country);
+            fail("javax.validation.ConstraintViolationException expected");
         } catch (Throwable t) {
             // do nothing
         }



Mime
View raw message