|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.testing.NullPointerTester
@Beta public final class NullPointerTester
A test utility that verifies that your methods and constructors throw NullPointerException
or UnsupportedOperationException
whenever null
is passed to a parameter that isn't annotated with Nullable
.
The tested methods and constructors are invoked -- each time with one
parameter being null and the rest not null -- and the test fails if no
expected exception is thrown. NullPointerTester
uses best effort to
pick non-null default values for many common JDK and Guava types, and also
for interfaces and public classes that have public parameter-less
constructors. When the non-null default value for a particular parameter type
cannot be provided by NullPointerTester
, the caller can provide a
custom non-null default value for the parameter type via setDefault(java.lang.Class
.
Nested Class Summary | |
---|---|
static class |
NullPointerTester.Visibility
Visibility of any method or constructor. |
Constructor Summary | |
---|---|
NullPointerTester()
|
Method Summary | ||
---|---|---|
NullPointerTester |
ignore(Member member)
Deprecated. Use ignore(Method) instead. This method will be
removed from Guava in Guava release 13.0. |
|
NullPointerTester |
ignore(Method method)
Ignore method in the tests that follow. |
|
|
setDefault(Class<T> type,
T value)
Sets a default value that can be used for any parameter of type type . |
|
void |
testAllPublicConstructors(Class<?> c)
Runs testConstructor(java.lang.reflect.Constructor>) on every public constructor in class c . |
|
void |
testAllPublicInstanceMethods(Object instance)
Runs testMethod(java.lang.Object, java.lang.reflect.Method) on every public instance method of the class of
instance , including those inherited from superclasses of the same
package. |
|
void |
testAllPublicStaticMethods(Class<?> c)
Runs testMethod(java.lang.Object, java.lang.reflect.Method) on every public static method of class c ,
including those "inherited" from superclasses of the same package. |
|
void |
testConstructor(Constructor<?> ctor)
Verifies that ctor produces a NullPointerException or
UnsupportedOperationException whenever any of its
non-Nullable parameters are null. |
|
void |
testConstructorParameter(Constructor<?> ctor,
int paramIndex)
Verifies that ctor produces a NullPointerException or
UnsupportedOperationException when the parameter in position paramIndex is null. |
|
void |
testConstructors(Class<?> c,
NullPointerTester.Visibility minimalVisibility)
Runs testConstructor(java.lang.reflect.Constructor>) on every constructor in class c that
has at least minimalVisibility . |
|
void |
testInstanceMethods(Object instance,
NullPointerTester.Visibility minimalVisibility)
Runs testMethod(java.lang.Object, java.lang.reflect.Method) on every instance method of the class of
instance with at least minimalVisibility , including those
inherited from superclasses of the same package. |
|
void |
testMethod(Object instance,
Method method)
Verifies that method produces a NullPointerException
or UnsupportedOperationException whenever any of its
non-Nullable parameters are null. |
|
void |
testMethodParameter(Object instance,
Method method,
int paramIndex)
Verifies that method produces a NullPointerException or
UnsupportedOperationException when the parameter in position paramIndex is null. |
|
void |
testStaticMethods(Class<?> c,
NullPointerTester.Visibility minimalVisibility)
Runs testMethod(java.lang.Object, java.lang.reflect.Method) on every static method of class c that has
at least minimalVisibility , including those "inherited" from
superclasses of the same package. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NullPointerTester()
Method Detail |
---|
public <T> NullPointerTester setDefault(Class<T> type, T value)
type
. Returns this object.
@Deprecated public NullPointerTester ignore(Member member)
ignore(Method)
instead. This method will be
removed from Guava in Guava release 13.0.
member
in the tests that follow. Returns this object.
public NullPointerTester ignore(Method method)
method
in the tests that follow. Returns this object.
public void testConstructors(Class<?> c, NullPointerTester.Visibility minimalVisibility)
testConstructor(java.lang.reflect.Constructor>)
on every constructor in class c
that
has at least minimalVisibility
.
public void testAllPublicConstructors(Class<?> c)
testConstructor(java.lang.reflect.Constructor>)
on every public constructor in class c
.
public void testStaticMethods(Class<?> c, NullPointerTester.Visibility minimalVisibility)
testMethod(java.lang.Object, java.lang.reflect.Method)
on every static method of class c
that has
at least minimalVisibility
, including those "inherited" from
superclasses of the same package.
public void testAllPublicStaticMethods(Class<?> c)
testMethod(java.lang.Object, java.lang.reflect.Method)
on every public static method of class c
,
including those "inherited" from superclasses of the same package.
public void testInstanceMethods(Object instance, NullPointerTester.Visibility minimalVisibility)
testMethod(java.lang.Object, java.lang.reflect.Method)
on every instance method of the class of
instance
with at least minimalVisibility
, including those
inherited from superclasses of the same package.
public void testAllPublicInstanceMethods(Object instance)
testMethod(java.lang.Object, java.lang.reflect.Method)
on every public instance method of the class of
instance
, including those inherited from superclasses of the same
package.
public void testMethod(Object instance, Method method)
method
produces a NullPointerException
or UnsupportedOperationException
whenever any of its
non-Nullable
parameters are null.
instance
- the instance to invoke method
on, or null if
method
is staticpublic void testConstructor(Constructor<?> ctor)
ctor
produces a NullPointerException
or
UnsupportedOperationException
whenever any of its
non-Nullable
parameters are null.
public void testMethodParameter(Object instance, Method method, int paramIndex)
method
produces a NullPointerException
or
UnsupportedOperationException
when the parameter in position paramIndex
is null. If this parameter is marked Nullable
, this
method does nothing.
instance
- the instance to invoke method
on, or null if
method
is staticpublic void testConstructorParameter(Constructor<?> ctor, int paramIndex)
ctor
produces a NullPointerException
or
UnsupportedOperationException
when the parameter in position paramIndex
is null. If this parameter is marked Nullable
, this
method does nothing.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |