Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * This software is licensed under the Apache License, Version 2.0
   * (the "License") agreement; 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.force66.beantester;
 
 import java.util.List;
 import java.util.Set;
 

Main user class for the BeanTester product. BeanTester performs monotonous testing on normal java beans for accessors, mutators, equals(), hashcode(), toString() so you don't have to write those tests.

Documentation for the product can be found here.

Author(s):
D. Ashmore
 
 public class BeanTester {
     
     private Set<StringfieldExclusionSet = new HashSet<String>();
     private List<BeanTestbeanTestList = new ArrayList<BeanTest>();
 
     public BeanTester() {
         .add("class"); // Object.class shouldn't be tested.
         .add(new IdentityEqualsTest());
         .add(new ClonableTest());
         .add(new ComparableTest());
         .add(new ToStringTest());
         .add(new HashcodeTest());
     }
    
    
Given field will be excluded from property-level testing

Parameters:
fieldName
 
     public void addExcludedField(String fieldName) {
         Validate.notEmpty(fieldName"Null or blank fieldName not allowed.");
         .add(fieldName);
     }
    
    
Values will be used for property-level testing for fields defined with the given class.

Parameters:
fieldClass
values
 
     public void addTestValues(Class<?> fieldClassObject[] values) {
     	Validate.notNull(fieldClass"Null fieldClass not allowed.");
     	Validate.notEmpty(values"Null values array not allowed.");
     	.registerGenerator(fieldClassnew GenericValueGenerator(values));
     }
    
    
Will perform all bean tests against the class provided. See product documentation for details on the tests performed.

Parameters:
beanClass
 
     public void testBean(Class<?> beanClass)  {
     	this.testBean(beanClassnull);
     }
    
    
Will perform all bean tests against the class provided using the constructor arguments provided. See product documentation for details on the tests performed.

Parameters:
beanClass
constructorArgs
 
     public void testBean(Class<?> beanClassObject[] constructorArgs)  {
         Validate.notNull(beanClass"Null beanClass not allowed.");
         for (BeanTest test) {
     		if (!test.testBeanClass(beanClassconstructorArgs)) {
    			throw new BeanTesterException("FailedTest")
    			.addContextValue("test"test.getClass().getName())
    			.addContextValue("failure reason"test.getFailureReason());
    		}
    	}
    }
New to GrepCode? Check out our FAQ X