<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Home</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>Recent changes to Home</description><atom:link href="https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 02 Feb 2015 13:23:23 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/feed" rel="self" type="application/rss+xml"/><item><title>Home modified by Mestrez Matthieu</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v7
+++ v8
@@ -165,6 +165,22 @@
     }

 The jodaTimeGenerator must implement org.unitils.objectvalidation.objectcreator.generator.Generator and generate random objects.
+
+        public static class JodaTimeGenerator implements Generator {
+ 
+        /**
+         * Returns now.
+         */
+        @Override
+        public Object generateObject(Class clazz, List&amp;lt;Object&amp;gt; input, List&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; inputClasses, List&amp;lt;TreeNode&amp;gt; genericSubTypes) throws Exception {
+            if (DateTimeZone.class.equals(clazz)) {
+                return DateTimeZone.getDefault();
+            } else if (DateTime.class.equals(clazz)) {
+                return DateTime.now();
+            }
+           
+            return null;
+        }

 # Extending Rules

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mestrez Matthieu</dc:creator><pubDate>Mon, 02 Feb 2015 13:23:23 -0000</pubDate><guid>https://sourceforge.net27507b81ffaf3dd32e4af624a8d8df467c5ffe88</guid></item><item><title>Home modified by Willemijn Wouters</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v6
+++ v7
@@ -85,7 +85,8 @@

 Out of the box it exists two basic rule collection :

-- SunBeanRules, it will check that :
+SunBeanRules, it will check that :
+
 * The Equals method is complient to Sun rules (Reflexive, Symmetric, Transitive, Consistent, Fails in the case of null value, Inequality when other instance of object, inequality when other object)
 * The HashCode method is complient to Sun rules : Same objects must produce the same hashCode number, Equals object have the same number (Note than an object is not obligated to have a different hashCode in the case of different value, this logic is not developped)
 * That the getter and the setter are complient : validate that every field is accessible with a getter and a setter, also that if we set an object to the field that the getter will return it
@@ -94,7 +95,12 @@

         org.unitils.objectvalidation.rules.collection=org.unitils.objectvalidation.rulescollection.SunBeanRules

--  UtilityClassRules, it will check that :
+SunBeanRulesWithMocks does almost the same as the SunBeanRules, but it won't generate the entire object graph. It creates an object with primitives and mocks. 
+
+org.unitils.objectvalidation.rules.collection=org.unitils.objectvalidation.rulescollection.SunBeanRulesWithMocks
+
+UtilityClassRules, it will check that :
+
 * The class only have one private constructor
 * That the class only have static methods
 * That the class is final
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Willemijn Wouters</dc:creator><pubDate>Fri, 12 Dec 2014 10:02:14 -0000</pubDate><guid>https://sourceforge.net67d379dc3d67105dd91b9b5e288ef8bef1287dbf</guid></item><item><title>Home modified by Willemijn Wouters</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v5
+++ v6
@@ -55,9 +55,9 @@
         @Test
         public void validateBeans() {
             objectValidator.
-                 classToValidate(ValidBean.class).validatingEqualsAndHashCode().withAllFields().
-                 classToValidate(ValidBeanWithByteArray.class).validatingEqualsAndHashCode().withFieldNames("firstField", "secondField", "byteArray").
-                 classToValidate(ValidBeanOnlyId.class).validatingEqualsAndHashCode().withFieldNames("id").
+                 classToValidate(ValidBean.class).checkingAllPossibilities().withAllFields().
+                 classToValidate(ValidBeanWithByteArray.class).checkingAllPossibilities().withFieldNames("firstField", "secondField", "byteArray").
+                 classToValidate(ValidBeanOnlyId.class).checkingAllPossibilities().withFieldNames("id").
                  validate();
        }
     }
@@ -74,7 +74,7 @@
         public void validateUtilsClass() {
             utilityValidator.
                 classToValidate(Utils.class).
-                withoutValidatingEqualsAndHashCode().
+                withoutCheckingAllPossibilities().
                 validate();
         }

@@ -109,7 +109,7 @@
 If you want to validate the class equals and hashCode method, you need to implement it this way :

     objectValidator.classToValidate(ValidBean.class).
-        validatingEqualsAndHashCode().
+        checkingAllPossibilities().
         withAllFields().
         validate();

@@ -118,22 +118,22 @@
 If you don't want to validate it (for example in the case of an utility method) :

     objectValidator.classToValidate(Utils.class).
-            withoutValidatingEqualsAndHashCode().
+            withoutCheckingAllPossibilities().
             validate();

 What if in your class Person you have a simple identity equals and don't look at other fields ?

     objectValidator.classToValidate(Person.class).
-        validatingEqualsAndHashCode().
+        checkingAllPossibilities().
         withFieldNames("id").
         validate();

 You can also add several classes at the same time :

    objectValidator.
-             classToValidate(ValidBean.class).validatingEqualsAndHashCode().withAllFields().
-             classToValidate(ValidBeanWithByteArray.class).validatingEqualsAndHashCode().withAllFields().
-             classToValidate(ValidBeanOnlyId.class).validatingEqualsAndHashCode().withFieldNames("id").
+             classToValidate(ValidBean.class).checkingAllPossibilities().withAllFields().
+             classToValidate(ValidBeanWithByteArray.class).checkingAllPossibilities().withAllFields().
+             classToValidate(ValidBeanOnlyId.class).checkingAllPossibilities().withFieldNames("id").
              validate();

 # Object Creator and generators
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Willemijn Wouters</dc:creator><pubDate>Fri, 12 Dec 2014 09:57:20 -0000</pubDate><guid>https://sourceforge.netb6fd8df88e97a80c26f9ae2e6d080fed7a15dd86</guid></item><item><title>Home modified by Mestrez Matthieu</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v4
+++ v5
@@ -41,6 +41,45 @@
    unitils.module.objectvalidation.className=org.unitils.objectvalidation.ValidationModule
    unitils.module.objectvalidation.runAfter=
    unitils.module.objectvalidation.enabled=true
+
+# Examples
+
+This first example tests three objects and checks their equals and hashcode method
+
+    @RunWith(UnitilsJUnit4TestClassRunner.class)
+    public class ValidatesBeanWithAnnotationTest {
+
+        @ObjectValidationRules
+        private ObjectValidator objectValidator;
+
+        @Test
+        public void validateBeans() {
+            objectValidator.
+                 classToValidate(ValidBean.class).validatingEqualsAndHashCode().withAllFields().
+                 classToValidate(ValidBeanWithByteArray.class).validatingEqualsAndHashCode().withFieldNames("firstField", "secondField", "byteArray").
+                 classToValidate(ValidBeanOnlyId.class).validatingEqualsAndHashCode().withFieldNames("id").
+                 validate();
+       }
+    }
+
+This example is to show how to test a simple utility method
+
+    @RunWith(UnitilsJUnit4TestClassRunner.class)
+    public class ValidatesUtilityClassWithAnnotationTest {
+
+        @ObjectValidationRules(replacementRules = {UtilityClassRules.class})
+        private ObjectValidator utilityValidator;
+    
+        @Test
+        public void validateUtilsClass() {
+            utilityValidator.
+                classToValidate(Utils.class).
+                withoutValidatingEqualsAndHashCode().
+                validate();
+        }
+    
+    }
+

 # Existing Rules

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mestrez Matthieu</dc:creator><pubDate>Fri, 07 Feb 2014 10:39:45 -0000</pubDate><guid>https://sourceforge.netd45be29d6d9b9e13d16634ff8705efde97caba9b</guid></item><item><title>Home modified by Mestrez Matthieu</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v3
+++ v4
@@ -1,31 +1,71 @@
 Unitils Object validation Module
 ====================================
-This unitils module makes it easy to validate objects against predefined rules (SunJavaBean rules are provided out of the box) or your own rules.

-### Validation Module load artifact (maven)
+[TOC] 
+
+# Purpose
+
+The purpose of this module is to 'automatically' test the basics of java classes such as getters and setters, constructors, equals and hashcode methods and other basic compliency rules.
+Other purpose is to have all this code covered without hard work.
+
+After having done a small configuration of your project, you simply have to annotate an ObjectValidator with @ObjectValidationRules and tell him which classes he has to verify
+
+
+# Concepts
+
+- Unitils (refer to unitils documentation : )
+- Rule : A rule is a java class which purpose is to validate something on another class, it could be verify that the toString method is well written and overriden for instance.
+- RuleCollection : Is a set of rules used as configuration of your project. Out of the box there is the SunBeanRules that verifies that objects are written with Sun compliency.
+- EqualsHashCodeValidator : Utility that will check that the equals and hashCode uses all the specified fields, it will cover the conditions of the equals and hashCode totally.
+
+# Basic configuration
+
+For this to be used you need a basic understanding on how unitils works. 
+Simply put, a unitils.properties files has to be found at the root of test/resources folder of the project you want to test,
+and annotate your test class with @RunWith(UnitilsJUnit4TestClassRunner.class).
+
+This additional maven dependency has to be added :
+
+## Validation Module load artifact (maven)
        
            org.unitils.objectvalidation
            unitils-objectvalidation
-           1.1.2
+           1.1.4
        

-### Validation Module project config
-Please create unitils-local.properties, and add mail to unitils.modules. Code as following:
+## Validation Module project config
+Please create unitils-local.properties, and add objectvalidation to unitils.modules. Code as following:

     unitils.modules=objectvalidation

    unitils.module.objectvalidation.className=org.unitils.objectvalidation.ValidationModule
    unitils.module.objectvalidation.runAfter=
    unitils.module.objectvalidation.enabled=true
-   
-To use the default rule validation you simply have to define an ObjectValidator object annotaded like this :

-    @ObjectValidationRules
-    private ObjectValidator objectValidator;
+# Existing Rules
+
+Out of the box it exists two basic rule collection :
+
+- SunBeanRules, it will check that :
+* The Equals method is complient to Sun rules (Reflexive, Symmetric, Transitive, Consistent, Fails in the case of null value, Inequality when other instance of object, inequality when other object)
+* The HashCode method is complient to Sun rules : Same objects must produce the same hashCode number, Equals object have the same number (Note than an object is not obligated to have a different hashCode in the case of different value, this logic is not developped)
+* That the getter and the setter are complient : validate that every field is accessible with a getter and a setter, also that if we set an object to the field that the getter will return it
+* That the class must be serializable and the serialVersionUID is defined.
+* That there is a public empty constructor
+    
+        org.unitils.objectvalidation.rules.collection=org.unitils.objectvalidation.rulescollection.SunBeanRules
+
+-  UtilityClassRules, it will check that :
+* The class only have one private constructor
+* That the class only have static methods
+* That the class is final
+    
+        org.unitils.objectvalidation.rules.collection=org.unitils.objectvalidation.rulescollection.UtilityClassRules
+
+# Equals and hashCode validator

-With or without Equals and HashCode tests ?
--------------------------------------------
+You can choose to use or not the equals and hashCode validator. If you want to have maximum coverage on your overriden equals and hashCode methods then it's advised to use it.

 If you want to validate the class equals and hashCode method, you need to implement it this way :

@@ -42,3 +82,108 @@
             withoutValidatingEqualsAndHashCode().
             validate();

+What if in your class Person you have a simple identity equals and don't look at other fields ?
+
+    objectValidator.classToValidate(Person.class).
+        validatingEqualsAndHashCode().
+        withFieldNames("id").
+        validate();
+        
+You can also add several classes at the same time :
+
+   objectValidator.
+             classToValidate(ValidBean.class).validatingEqualsAndHashCode().withAllFields().
+             classToValidate(ValidBeanWithByteArray.class).validatingEqualsAndHashCode().withAllFields().
+             classToValidate(ValidBeanOnlyId.class).validatingEqualsAndHashCode().withFieldNames("id").
+             validate();
+
+# Object Creator and generators
+
+For the objectvalidation being able to work it exists an ObjectCreator that will create randomized instance of classes.
+They are defined inside the RulesCollection, it's a field. For the SunBeanRules for example the org.unitils.objectvalidation.objectcreator.ObjectCreatorFactory.createDefaultObjectCreator() is used.
+
+If you use something else than the default types of object (for example use joda.time) then you need to override this objectCreator like this :
+
+   private static ObjectCreator createProjectObjectCreator() {
+        return ObjectCreatorFactory.createObjectCreator(new Generator[] {new ProjectCompositeGenerator()});
+    }
+    
+    public static class ProjectCompositeGenerator extends CompositeGenerator {
+        public ProjectCompositeGenerator() {
+            addGenerators(new Generator[] {new JodaTimeGenerator(),
+                                           new EnumGenerator(),
+                                           new PrimitiveGenerator(),
+                                           new CollectionGenerator(),
+                                           new BuilderGenerator(),
+                                           new LastResortGenerator()});
+        }
+    }
+    
+The jodaTimeGenerator must implement org.unitils.objectvalidation.objectcreator.generator.Generator and generate random objects.
+
+# Extending Rules
+
+If in your project you have specific rules that you want to test ? Check that on each class you have overriden the toString method for example ? 
+
+You simply create a class implementing org.unitils.objectvalidation.Rule like this :
+
+   public class ToStringHasToBeOverridenRule implements Rule {
+   
+       @Override
+       public void validate(Class classToValidate) {
+           Method toStringMethod;
+           try {
+               toStringMethod = classToValidate.getDeclaredMethod("toString");
+               assertNotNull("toString method has to be Overriden", toStringMethod);
+           } catch (SecurityException e) {
+               fail("Could not be read due to security reasons.\n" + e.getMessage());
+           } catch (NoSuchMethodException e) {
+               fail("Does not contain toString method. It should be overriden.");
+           }
+       }
+       
+   }
+
+# Rules Collection
+
+If the rules collection SunBeanRules and UtilityClassRules don't fit your purpose you simply can redefine your rule collection by implementing org.unitils.objectvalidation.ObjectValidationRulesCollection :
+
+You then need to override the method public List getRules(), provide a list of rules for your project, for instance :
+
+   @Override
+    public List getRules() {
+
+        return Arrays.asList(new EqualsComplientRule(objectCreator, objectCloner) ,
+                            new HashCodeComplientRule(objectCreator, objectCloner),
+                            new GetterRctComplientRule(objectCreator, objectCloner),
+                            new NoSetterRule(),
+                            new PrivateConstructorWithBuilderRule(),
+                            new ToStringHasToBeOverridenRule());
+    }
+    
+You see here the use of the objectCreator (see 6. in this document) and the object cloner, you can use the default ones :
+
+   public ProjectRules() {
+        objectCreator = ObjectCreatorFactory.createDefaultObjectCreator();
+        objectCloner = ObjectClonerFactory.createDefaultCloner();
+    }
+    
+Or define your own.
+
+Then you have to override the method public EqualsHashCodeValidator getEqualsHashCodeValidator()
+
+Where you can use the default one :
+
+   return new EqualsHashCodeValidator(objectCreator, objectCloner);
+
+or redefine your own.
+
+# Replacement rules &amp; Additional Rules
+
+If on a project you need for one or several test to don't use the specified rule collection (in the unitils.properties file) and use another instead you can define that at annotation time :
+
+   @ObjectValidationRules(replacementRules = SunBeanRules.class)
+   
+If you want to run the configured one (in the unitils.properties file) and also another set of rules in addition use this parameter of the annotation :
+
+   @ObjectValidationRules(additionalRules = SunBeanRules.class)
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mestrez Matthieu</dc:creator><pubDate>Thu, 19 Dec 2013 07:34:10 -0000</pubDate><guid>https://sourceforge.net3c1f5f1c4fd1254cf33fc87f8fc665bf2262f1c1</guid></item><item><title>Home modified by Mestrez Matthieu</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mestrez Matthieu</dc:creator><pubDate>Mon, 09 Dec 2013 09:37:07 -0000</pubDate><guid>https://sourceforge.net7f78e8c7fc139e5f38e0a6ea910b29cb82165eb4</guid></item><item><title>Home modified by Mestrez Matthieu</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,8 +1,44 @@
-Welcome to your wiki!
+Unitils Object validation Module
+====================================
+This unitils module makes it easy to validate objects against predefined rules (SunJavaBean rules are provided out of the box) or your own rules.

-This is the default page, edit it as you see fit. To add a new page simply reference it within brackets, e.g.: [SamplePage].
+### Validation Module load artifact (maven)
+       
+           org.unitils.objectvalidation
+           unitils-objectvalidation
+           1.1.2
+       

-The wiki uses [Markdown](/p/unitilsobjectvalidation/wiki/markdown_syntax/) syntax.
+### Validation Module project config
+Please create unitils-local.properties, and add mail to unitils.modules. Code as following:

-[[members limit=20]]
-[[download_button]]
+    unitils.modules=objectvalidation
+    
+   unitils.module.objectvalidation.className=org.unitils.objectvalidation.ValidationModule
+   unitils.module.objectvalidation.runAfter=
+   unitils.module.objectvalidation.enabled=true
+   
+To use the default rule validation you simply have to define an ObjectValidator object annotaded like this :
+
+    @ObjectValidationRules
+    private ObjectValidator objectValidator;
+
+
+With or without Equals and HashCode tests ?
+-------------------------------------------
+
+If you want to validate the class equals and hashCode method, you need to implement it this way :
+
+    objectValidator.classToValidate(ValidBean.class).
+        validatingEqualsAndHashCode().
+        withAllFields().
+        validate();
+
+This will take class ValidBean and create a different object per field and compare them against each other to see if the equals and hashCode method are complient.
+
+If you don't want to validate it (for example in the case of an utility method) :
+
+    objectValidator.classToValidate(Utils.class).
+            withoutValidatingEqualsAndHashCode().
+            validate();
+
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mestrez Matthieu</dc:creator><pubDate>Mon, 09 Dec 2013 08:04:21 -0000</pubDate><guid>https://sourceforge.netd4afc3bf00611d3906885253f66eb6fe58fa974f</guid></item><item><title>Home modified by Willemijn Wouters</title><link>https://sourceforge.net/p/unitilsobjectvalidation/wiki/Home/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Welcome to your wiki!&lt;/p&gt;
&lt;p&gt;This is the default page, edit it as you see fit. To add a new page simply reference it within brackets, e.g.: &lt;span&gt;[SamplePage]&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The wiki uses &lt;a class="" href="/p/unitilsobjectvalidation/wiki/markdown_syntax/"&gt;Markdown&lt;/a&gt; syntax.&lt;/p&gt;
&lt;p&gt;&lt;h6&gt;Project Members:&lt;/h6&gt;
&lt;ul class="md-users-list"&gt;
&lt;li&gt;&lt;a href="/u/willemijnw/"&gt;Willemijn Wouters&lt;/a&gt; (admin)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;span class="download-button-5256acc2f1fd8d596cec9861" style="margin-bottom: 1em; display: block;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Willemijn Wouters</dc:creator><pubDate>Thu, 10 Oct 2013 13:33:55 -0000</pubDate><guid>https://sourceforge.net2d7b69b51e378f8c1f828d869eb832081de1593c</guid></item></channel></rss>