Skip to content
This repository
Browse code

Add test for ConstraintUnitTestMixin and add info to the README about…

… testing

Signed-off-by: Geoff Lane <geoff@zorched.net>
  • Loading branch information...
commit 75e932e4ee9fc3a42d289de14473f592157bd0e3 1 parent 24047ae
Geoff Lane authored February 10, 2012
21  README.markdown
Source Rendered
@@ -293,3 +293,24 @@ e.g.
293 293
 		}
294 294
 	}
295 295
 
  296
+
  297
+### Testing ###
  298
+@TestMixin support has been added to make Constraints easy to test using Unit tests.
  299
+
  300
+e.g.
  301
+
  302
+    @TestMixin(ConstraintUnitTestMixin)
  303
+    class UsPhoneConstraintTest {
  304
+        @Test
  305
+        void testUsPhoneValidation() {
  306
+            def constraint = testFor(UsPhoneConstraint)
  307
+
  308
+            // Params are automatically mixed in to the test class and exposed
  309
+            // to the constraint with the call above.
  310
+            params = true
  311
+
  312
+            assertTrue constraint.validate("5135551212")
  313
+            assertFalse constraint.validate("bad")
  314
+        }
  315
+    }
  316
+
27  test/unit/ConstraintUnitTestMixinTest.groovy
... ...
@@ -0,0 +1,27 @@
  1
+import net.zorched.grails.plugins.validation.ConstraintUnitTestMixin
  2
+import grails.test.mixin.TestMixin
  3
+import org.junit.Test
  4
+import net.zorched.constraints.UsPhoneConstraint
  5
+import static org.junit.Assert.assertTrue
  6
+import static org.junit.Assert.assertFalse
  7
+
  8
+/**
  9
+ *
  10
+ * @author geoff
  11
+ * @since 2/10/2012
  12
+ */
  13
+@TestMixin(ConstraintUnitTestMixin)
  14
+class ConstraintUnitTestMixinTest {
  15
+
  16
+    @Test
  17
+    void testThatConstraintIsMixedIn() {
  18
+        def constraint = testFor(UsPhoneConstraint)
  19
+
  20
+        // Params are automatically mixed in to the test class and exposed
  21
+        // to the constraint with the call above.
  22
+        params = true
  23
+
  24
+        assertTrue constraint.validate("5135551212")
  25
+        assertFalse constraint.validate("bad")
  26
+    }
  27
+}

0 notes on commit 75e932e

Please sign in to comment.
Something went wrong with that request. Please try again.