|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.midwinter.junit.GetterSetterTester
public class GetterSetterTester
Automates JUnit testing of simple getter/setter methods.
It may be used in exclusive or inclusive mode. In exclusive mode, which is the default, all JavaBeans properties (getter/setter method pairs with matching names) are tested unless they are excluded beforehand. For example:
MyClass objectToTest = new MyClass(); GetterSetterTester gst = new GetterSetterTester(objectToTest); gst.exclude("complexProperty"); gst.exclude("anotherProperty"); gst.test();
In inclusive mode, only properties that are explicitly listed are tested. For example:
new GetterSetterTester(new MyClass()). include("aSimpleProperty"). include("secondProperty"). test();
The second example also illustrates how to call this class in as terse a way as possible.
The following property types are supported:
Properties whose types are classes declared final
are not supported;
neither are non-primitive, non-interface properties if you don't
have cglib.
Copyright (c) 2005, Steven Grimm.
This software may be used for any purpose, commercial or noncommercial, so
long as this copyright notice is retained. If you make improvements to the
code, you're encouraged (but not required) to send them to me so I can
make them available to others. For updates, please check
here.
Constructor Summary | |
---|---|
GetterSetterTester(java.lang.Object obj)
Constructs a new getter/setter tester to test objects of a particular class. |
Method Summary | |
---|---|
GetterSetterTester |
exclude(java.lang.String field)
Adds a field to the list of excluded fields. |
GetterSetterTester |
include(java.lang.String field)
Adds a field to the list of tested fields. |
GetterSetterTester |
setVerbose(boolean verbose)
Sets the verbosity flag. |
void |
test()
Walks through the methods in the class looking for getters and setters that are on our include list (if any) and are not on our exclude list. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GetterSetterTester(java.lang.Object obj)
obj
- Object to test.Method Detail |
---|
public GetterSetterTester include(java.lang.String field)
field
- Field name whose getter/setter should be tested.
public GetterSetterTester exclude(java.lang.String field)
field
- Field name to exclude from testing.
public GetterSetterTester setVerbose(boolean verbose)
public void test() throws java.lang.reflect.InvocationTargetException, java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.SecurityException, java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.ClassNotFoundException
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |