com.google.common.testing
Class NullPointerTester

java.lang.Object
  extended by com.google.common.testing.NullPointerTester

@Beta
public final class NullPointerTester
extends Object

A test utility that verifies that your methods throw NullPointerException or UnsupportedOperationException whenever any of their parameters are null. To use it, you must first provide valid default values for the parameter types used by the class.

Since:
10.0
Author:
Kevin Bourrillion

Nested Class Summary
static class NullPointerTester.Visibility
          Visibility of any method or constructor.
 
Constructor Summary
NullPointerTester()
           
 
Method Summary
 NullPointerTester ignore(Member member)
          Ignore a member (constructor or method) in testAllXxx methods.
<T> NullPointerTester
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

NullPointerTester

public NullPointerTester()
Method Detail

setDefault

public <T> NullPointerTester setDefault(Class<T> type,
                                        T value)
Sets a default value that can be used for any parameter of type type. Returns this object.


ignore

public NullPointerTester ignore(Member member)
Ignore a member (constructor or method) in testAllXxx methods. Returns this object.


testConstructors

public void testConstructors(Class<?> c,
                             NullPointerTester.Visibility minimalVisibility)
Runs testConstructor(java.lang.reflect.Constructor) on every constructor in class c that has at least minimalVisibility.


testAllPublicConstructors

public void testAllPublicConstructors(Class<?> c)
Runs testConstructor(java.lang.reflect.Constructor) on every public constructor in class c.


testStaticMethods

public 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.


testAllPublicStaticMethods

public 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.


testInstanceMethods

public 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.


testAllPublicInstanceMethods

public 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.


testMethod

public void testMethod(Object instance,
                       Method method)
Verifies that method produces a NullPointerException or UnsupportedOperationException whenever any of its non-Nullable parameters are null.

Parameters:
instance - the instance to invoke method on, or null if method is static

testConstructor

public void testConstructor(Constructor<?> ctor)
Verifies that ctor produces a NullPointerException or UnsupportedOperationException whenever any of its non-Nullable parameters are null.


testMethodParameter

public void testMethodParameter(Object instance,
                                Method method,
                                int paramIndex)
Verifies that method produces a NullPointerException or UnsupportedOperationException when the parameter in position paramIndex is null. If this parameter is marked Nullable, this method does nothing.

Parameters:
instance - the instance to invoke method on, or null if method is static

testConstructorParameter

public void testConstructorParameter(Constructor<?> ctor,
                                     int paramIndex)
Verifies that ctor produces a NullPointerException or UnsupportedOperationException when the parameter in position paramIndex is null. If this parameter is marked Nullable, this method does nothing.



Copyright © 2010-2012. All Rights Reserved.