Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2012 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * 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 com.google.common.testing;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import  javax.annotation.Nullable;

Tester that runs automated sanity tests for any given class. A typical use case is to test static factory classes like:
 interface Book {...}
 public class Books {
   public static Book hardcover(String title) {...}
   public static Book paperback(String title) {...}
 }
 

And all the created Book instances can be tested with:

 new ClassSanityTester()
     .forAllPublicStaticMethods(Books.class)
     .thatReturn(Book.class)
     .testEquals(); // or testNulls(), testSerializable() etc.
 

Author(s):
Ben Yu
Since:
14.0
 
 public final class ClassSanityTester {
 
   private static final Ordering<Invokable<?, ?>> BY_METHOD_NAME =
       new Ordering<Invokable<?, ?>>() {
         @Override public int compare(Invokable<?, ?> leftInvokable<?, ?> right) {
           return left.getName().compareTo(right.getName());
         }
       };
 
   private static final Ordering<Invokable<?, ?>> BY_PARAMETERS =
       new Ordering<Invokable<?, ?>>() {
         @Override public int compare(Invokable<?, ?> leftInvokable<?, ?> right) {
           return Ordering.usingToString().compare(left.getParameters(), right.getParameters());
         }
       };
 
   private static final Ordering<Invokable<?, ?>> BY_NUMBER_OF_PARAMETERS =
       new Ordering<Invokable<?, ?>>() {
         @Override public int compare(Invokable<?, ?> leftInvokable<?, ?> right) {
           return Ints.compare(left.getParameters().size(), right.getParameters().size());
         }
      };
      MutableClassToInstanceMap.create();
  private final ListMultimap<Class<?>, ObjectdistinctValues = ArrayListMultimap.create();
  public ClassSanityTester() {
    // TODO(benyu): bake these into ArbitraryInstances.
    setDefault(byte.class, (byte) 1);
    setDefault(Byte.class, (byte) 1);
    setDefault(short.class, (short) 1);
    setDefault(Short.class, (short) 1);
    setDefault(int.class, 1);
    setDefault(Integer.class, 1);
    setDefault(long.class, 1L);
    setDefault(Long.class, 1L);
    setDefault(float.class, 1F);
    setDefault(Float.class, 1F);
    setDefault(double.class, 1D);
    setDefault(Double.class, 1D);
    setDefault(Class.classClass.class);
  }

  
Sets the default value for type. The default value isn't used in testing Object.equals because more than one sample instances are needed for testing inequality. To set sample instances for equality testing, use setSampleInstances instead.
  public <T> ClassSanityTester setDefault(Class<T> type, T value) {
    .setDefault(typevalue);
    .putInstance(typevalue);
    return this;
  }

  
Sets sample instances for type, so that when a class Foo is tested for Object.equals and Object.hashCode, and its construction requires a parameter of type, the sample instances can be passed to create Foo instances that are unequal.

Used for types where ClassSanityTester doesn't already know how to instantiate distinct values. It's usually necessary to add two unequal instances for each type, with the exception that if the sample instance is to be passed to a Nullable parameter, one non-null sample is sufficient. Setting an empty list will clear sample instances for type.

Deprecated:
Use setDistinctValues instead.
  public <T> ClassSanityTester setSampleInstances(Class<T> typeIterable<? extends T> instances) {
    ImmutableList<? extends T> samples = ImmutableList.copyOf(instances);
    Set<ObjectuniqueValues = new HashSet<Object>();
    for (T instance : instances) {
      checkArgument(uniqueValues.add(instance), "Duplicate value: %s"instance);
    }
    .putAll(checkNotNull(type), samples);
    if (!samples.isEmpty()) {
      setDefault(typesamples.get(0));
    }
    return this;
  }

  
Sets distinct values for type, so that when a class Foo is tested for Object.equals and Object.hashCode, and its construction requires a parameter of type, the distinct values of type can be passed as parameters to create Foo instances that are unequal.

Calling setDistinctValues(type, v1, v2) also sets the default value for type that's used for testNulls.

Only necessary for types where ClassSanityTester doesn't already know how to create distinct values.

Returns:
this tester instance
Since:
17.0
  public <T> ClassSanityTester setDistinctValues(Class<T> type, T value1, T value2) {
    checkNotNull(type);
    checkNotNull(value1);
    checkNotNull(value2);
    checkArgument(!Objects.equal(value1value2), "Duplicate value provided.");
    .replaceValues(type, ImmutableList.of(value1value2));
    setDefault(typevalue1);
    return this;
  }

  
Tests that cls properly checks null on all constructor and method parameters that aren't annotated with Nullable. In details:
  • All non-private static methods are checked such that passing null for any parameter that's not annotated with javax.annotation.Nullable should throw NullPointerException.
  • If there is any non-private constructor or non-private static factory method declared by cls, all non-private instance methods will be checked too using the instance created by invoking the constructor or static factory method.
  • If there is any non-private constructor or non-private static factory method declared by cls:
    • Test will fail if default value for a parameter cannot be determined.
    • Test will fail if the factory method returns null so testing instance methods is impossible.
    • Test will fail if the constructor or factory method throws exception.
  • If there is no non-private constructor or non-private static factory method declared by cls, instance methods are skipped for nulls test.
  • Nulls test is not performed on method return values unless the method is a non-private static factory method whose return type is cls or cls's subtype.
  public void testNulls(Class<?> cls) {
    try {
      doTestNulls(cls.);
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
  void doTestNulls(Class<?> clsVisibility visibility)
    if (!Modifier.isAbstract(cls.getModifiers())) {
      .testConstructors(clsvisibility);
    }
    .testStaticMethods(clsvisibility);
    if (hasInstanceMethodToTestNulls(clsvisibility)) {
      Object instance = instantiate(cls);
      if (instance != null) {
        .testInstanceMethods(instancevisibility);
      }
    }
  }
  private boolean hasInstanceMethodToTestNulls(Class<?> cVisibility visibility) {
    for (Method method : .getInstanceMethodsToTest(cvisibility)) {
      for (Parameter param : Invokable.from(method).getParameters()) {
        if (!NullPointerTester.isPrimitiveOrNullable(param)) {
          return true;
        }
      }
    }
    return false;
  }

  
Tests the Object.equals and Object.hashCode of cls. In details:
  • The non-private constructor or non-private static factory method with the most parameters is used to construct the sample instances. In case of tie, the candidate constructors or factories are tried one after another until one can be used to construct sample instances.
  • For the constructor or static factory method used to construct instances, it's checked that when equal parameters are passed, the result instance should also be equal; and vice versa.
  • If a non-private constructor or non-private static factory method exists:
    • Test will fail if default value for a parameter cannot be determined.
    • Test will fail if the factory method returns null so testing instance methods is impossible.
    • Test will fail if the constructor or factory method throws exception.
  • If there is no non-private constructor or non-private static factory method declared by cls, no test is performed.
  • Equality test is not performed on method return values unless the method is a non-private static factory method whose return type is cls or cls's subtype.
  • Inequality check is not performed against state mutation methods such as List.add, or functional update methods such as com.google.common.base.Joiner.skipNulls.

Note that constructors taking a builder object cannot be tested effectively because semantics of builder can be arbitrarily complex. Still, a factory class can be created in the test to facilitate equality testing. For example:

 public class FooTest {

   private static class FooFactoryForTest {
     public static Foo create(String a, String b, int c, boolean d) {
       return Foo.builder()
           .setA(a)
           .setB(b)
           .setC(c)
           .setD(d)
           .build();
     }
   }

   public void testEquals() {
     new ClassSanityTester()
       .forAllPublicStaticMethods(FooFactoryForTest.class)
       .thatReturn(Foo.class)
       .testEquals();
   }
 }
 

It will test that Foo objects created by the create(a, b, c, d) factory method with equal parameters are equal and vice versa, thus indirectly tests the builder equality.

  public void testEquals(Class<?> cls) {
    try {
      doTestEquals(cls);
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
 
  void doTestEquals(Class<?> cls)
    if (cls.isEnum()) {
      return;
    }
    List<? extends Invokable<?, ?>> factories = Lists.reverse(getFactories(TypeToken.of(cls)));
    if (factories.isEmpty()) {
      return;
    }
    int numberOfParameters = factories.get(0).getParameters().size();
    List<ParameterNotInstantiableExceptionparamErrors = Lists.newArrayList();
    List<ParameterHasNoDistinctValueExceptiondistinctValueErrors = Lists.newArrayList();
    List<InvocationTargetExceptioninstantiationExceptions = Lists.newArrayList();
    List<FactoryMethodReturnsNullExceptionnullErrors = Lists.newArrayList();
    // Try factories with the greatest number of parameters.
    for (Invokable<?, ?> factory : factories) {
      if (factory.getParameters().size() == numberOfParameters) {
        try {
          testEqualsUsing(factory);
          return;
        } catch (ParameterNotInstantiableException e) {
          paramErrors.add(e);
        } catch (ParameterHasNoDistinctValueException e) {
          distinctValueErrors.add(e);
        } catch (InvocationTargetException e) {
          instantiationExceptions.add(e);
        } catch (FactoryMethodReturnsNullException e) {
          nullErrors.add(e);
        }
      }
    }
    throwFirst(paramErrors);
    throwFirst(distinctValueErrors);
    throwFirst(instantiationExceptions);
    throwFirst(nullErrors);
  }

  
Instantiates cls by invoking one of its non-private constructors or non-private static factory methods with the parameters automatically provided using dummy values.

Returns:
The instantiated instance, or null if the class has no non-private constructor or factory method to be constructed.
  @Nullable <T> T instantiate(Class<T> cls)
    if (cls.isEnum()) {
      T[] constants = cls.getEnumConstants();
      if (constants.length > 0) {
        return constants[0];
      } else {
        return null;
      }
    }
    TypeToken<T> type = TypeToken.of(cls);
    List<ParameterNotInstantiableExceptionparamErrors = Lists.newArrayList();
    List<InvocationTargetExceptioninstantiationExceptions = Lists.newArrayList();
    List<FactoryMethodReturnsNullExceptionnullErrors = Lists.newArrayList();
    for (Invokable<?, ? extends T> factory : getFactories(type)) {
      T instance;
      try {
        instance = instantiate(factory);
      } catch (ParameterNotInstantiableException e) {
        paramErrors.add(e);
        continue;
      } catch (InvocationTargetException e) {
        instantiationExceptions.add(e);
        continue;
      }
      if (instance == null) {
        nullErrors.add(new FactoryMethodReturnsNullException(factory));
      } else {
        return instance;
      }
    }
    throwFirst(paramErrors);
    throwFirst(instantiationExceptions);
    throwFirst(nullErrors);
    return null;
  }

  
Returns an object responsible for performing sanity tests against the return values of all public static methods declared by cls, excluding superclasses.
    ImmutableList.Builder<Invokable<?, ?>> builder = ImmutableList.builder();
    for (Method method : cls.getDeclaredMethods()) {
      Invokable<?, ?> invokable = Invokable.from(method);
      invokable.setAccessible(true);
      if (invokable.isPublic() && invokable.isStatic() && !invokable.isSynthetic()) {
        builder.add(invokable);
      }
    }
    return new FactoryMethodReturnValueTester(clsbuilder.build(), "public static methods");
  }

  
Runs sanity tests against return values of static factory methods declared by a class.
  public final class FactoryMethodReturnValueTester {
    private final Set<StringpackagesToTest = Sets.newHashSet();
    private final Class<?> declaringClass;
    private final ImmutableList<Invokable<?, ?>> factories;
    private final String factoryMethodsDescription;
    private Class<?> returnTypeToTest = Object.class;
        Class<?> declaringClass,
        ImmutableList<Invokable<?, ?>> factories,
        String factoryMethodsDescription) {
      this. = declaringClass;
      this. = factories;
      this. = factoryMethodsDescription;
      .add(Reflection.getPackageName(declaringClass));
    }

    
Specifies that only the methods that are declared to return returnType or its subtype are tested.

Returns:
this tester object
    public FactoryMethodReturnValueTester thatReturn(Class<?> returnType) {
      this. = returnType;
      return this;
    }

    
Tests null checks against the instance methods of the return values, if any.

Test fails if default value cannot be determined for a constructor or factory method parameter, or if the constructor or factory method throws exception.

Returns:
this tester
      for (Invokable<?, ?> factory : getFactoriesToTest()) {
        Object instance = instantiate(factory);
        if (instance != null
            && .contains(Reflection.getPackageName(instance.getClass()))) {
          try {
            .testAllPublicInstanceMethods(instance);
          } catch (AssertionError e) {
            AssertionError error = new AssertionFailedError(
                "Null check failed on return value of " + factory);
            error.initCause(e);
            throw error;
          }
        }
      }
      return this;
    }

    
Tests Object.equals and Object.hashCode against the return values of the static methods, by asserting that when equal parameters are passed to the same static method, the return value should also be equal; and vice versa.

Test fails if default value cannot be determined for a constructor or factory method parameter, or if the constructor or factory method throws exception.

Returns:
this tester
      for (Invokable<?, ?> factory : getFactoriesToTest()) {
        try {
          testEqualsUsing(factory);
        } catch (FactoryMethodReturnsNullException e) {
          // If the factory returns null, we just skip it.
        }
      }
      return this;
    }

    
Runs serialization test on the return values of the static methods.

Test fails if default value cannot be determined for a constructor or factory method parameter, or if the constructor or factory method throws exception.

Returns:
this tester
      for (Invokable<?, ?> factory : getFactoriesToTest()) {
        Object instance = instantiate(factory);
        if (instance != null) {
          try {
            SerializableTester.reserialize(instance);
          } catch (RuntimeException e) {
            AssertionError error = new AssertionFailedError(
                "Serialization failed on return value of " + factory);
            error.initCause(e.getCause());
            throw error;
          }
        }
      }
      return this;
    }

    
Runs equals and serialization test on the return values.

Test fails if default value cannot be determined for a constructor or factory method parameter, or if the constructor or factory method throws exception.

Returns:
this tester
      for (Invokable<?, ?> factory : getFactoriesToTest()) {
        try {
          testEqualsUsing(factory);
        } catch (FactoryMethodReturnsNullException e) {
          // If the factory returns null, we just skip it.
        }
        Object instance = instantiate(factory);
        if (instance != null) {
          try {
            SerializableTester.reserializeAndAssert(instance);
          } catch (RuntimeException e) {
            AssertionError error = new AssertionFailedError(
                "Serialization failed on return value of " + factory);
            error.initCause(e.getCause());
            throw error;
          } catch (AssertionFailedError e) {
            AssertionError error = new AssertionFailedError(
                "Return value of " + factory + " reserialized to an unequal value");
            error.initCause(e);
            throw error;
          }
        }
      }
      return this;
    }
    private ImmutableList<Invokable<?, ?>> getFactoriesToTest() {
      ImmutableList.Builder<Invokable<?, ?>> builder = ImmutableList.builder();
      for (Invokable<?, ?> factory : ) {
        if (.isAssignableFrom(factory.getReturnType().getRawType())) {
          builder.add(factory);
        }
      }
      ImmutableList<Invokable<?, ?>> factoriesToTest = builder.build();
      Assert.assertFalse("No " +  + " that return "
              + .getName() + " or subtype are found in "
              +  + ".",
          factoriesToTest.isEmpty());
      return factoriesToTest;
    }
  }

  
Instantiates using factory. If factory is annotated with Nullable and returns null, null will be returned.

Throws:
ParameterNotInstantiableException if the static methods cannot be invoked because the default value of a parameter cannot be determined.
IllegalAccessException if the class isn't public or is nested inside a non-public class, preventing its methods from being accessible.
InvocationTargetException if a static method threw exception.
  @Nullable private <T> T instantiate(Invokable<?, ? extends T> factory)
    return invoke(factorygetDummyArguments(factory));
  }
  private void testEqualsUsing(final Invokable<?, ?> factory)
    List<Parameterparams = factory.getParameters();
    List<FreshValueGeneratorargGenerators = Lists.newArrayListWithCapacity(params.size());
    List<Objectargs = Lists.newArrayListWithCapacity(params.size());
    for (Parameter param : params) {
      FreshValueGenerator generator = newFreshValueGenerator();
      argGenerators.add(generator);
      args.add(generateDummyArg(paramgenerator));
    }
    Object instance = createInstance(factoryargs);
    List<ObjectequalArgs = generateEqualFactoryArguments(factoryparamsargs);
    // Each group is a List of items, each item has a list of factory args.
    final List<List<List<Object>>> argGroups = Lists.newArrayList();
    argGroups.add(ImmutableList.of(argsequalArgs));
    EqualsTester tester = new EqualsTester(new ItemReporter() {
      @Override String reportItem(Item<?> item) {
        List<ObjectfactoryArgs = argGroups.get(item.groupNumber).get(item.itemNumber);
        return factory.getName() + "(" + Joiner.on(", ").useForNull("null").join(factoryArgs) + ")";
      }
    });
    tester.addEqualityGroup(instancecreateInstance(factoryequalArgs));
    for (int i = 0; i < params.size(); i++) {
      List<ObjectnewArgs = Lists.newArrayList(args);
      Object newArg = argGenerators.get(i).generate(params.get(i).getType());
      if (newArg == null || Objects.equal(args.get(i), newArg)) {
        if (params.get(i).getType().getRawType().isEnum()) {
          continue// Nothing better we can do if it's single-value enum
        }
        throw new ParameterHasNoDistinctValueException(params.get(i));
      }
      newArgs.set(inewArg);
      tester.addEqualityGroup(createInstance(factorynewArgs));
      argGroups.add(ImmutableList.of(newArgs));
    }
    tester.testEquals();
  }

  
Returns dummy factory arguments that are equal to args but may be different instances, to be used to construct a second instance of the same equality group.
      Invokable<?, ?> factoryList<ParameterparamsList<Objectargs)
    List<ObjectequalArgs = Lists.newArrayList(args);
    for (int i = 0; i < args.size(); i++) {
      Parameter param = params.get(i);
      Object arg = args.get(i);
      // Use new fresh value generator because 'args' were populated with new fresh generator each.
      // Two newFreshValueGenerator() instances should normally generate equal value sequence.
      Object shouldBeEqualArg = generateDummyArg(paramnewFreshValueGenerator());
      if (arg != shouldBeEqualArg
          && Objects.equal(argshouldBeEqualArg)
          && hashCodeInsensitiveToArgReference(factoryargsishouldBeEqualArg)
          && hashCodeInsensitiveToArgReference(
              factoryargsigenerateDummyArg(paramnewFreshValueGenerator()))) {
        // If the implementation uses identityHashCode(), referential equality is
        // probably intended. So no point in using an equal-but-different factory argument.
        // We check twice to avoid confusion caused by accidental hash collision.
        equalArgs.set(ishouldBeEqualArg);
      }
    }
    return equalArgs;
  }
  private static boolean hashCodeInsensitiveToArgReference(
      Invokable<?, ?> factoryList<Objectargsint iObject alternateArg)
    List<ObjecttentativeArgs = Lists.newArrayList(args);
    tentativeArgs.set(ialternateArg);
    return createInstance(factorytentativeArgs).hashCode()
        == createInstance(factoryargs).hashCode();
  }
  // distinctValues is a type-safe class-values mapping, but we don't have a type-safe data
  // structure to hold the mappings.
  @SuppressWarnings({"unchecked""rawtypes"})
    FreshValueGenerator generator = new FreshValueGenerator() {
      @Override Object interfaceMethodCalled(Class<?> interfaceTypeMethod method) {
        return getDummyValue(TypeToken.of(interfaceType).method(method).getReturnType());
      }
    };
    for (Map.Entry<Class<?>, Collection<Object>> entry : .asMap().entrySet()) {
      generator.addSampleInstances((Classentry.getKey(), entry.getValue());
    }
    return generator;
  }
  private static @Nullable Object generateDummyArg(Parameter paramFreshValueGenerator generator)
    if (param.isAnnotationPresent(Nullable.class)) {
      return null;
    }
    Object arg = generator.generate(param.getType());
    if (arg == null) {
      throw new ParameterNotInstantiableException(param);
    }
    return arg;
  }
  private static <X extends Throwablevoid throwFirst(List<X> exceptionsthrows X {
    if (!exceptions.isEmpty()) {
      throw exceptions.get(0);
    }
  }

  
Factories with the least number of parameters are listed first.
  private static <T> ImmutableList<Invokable<?, ? extends T>> getFactories(TypeToken<T> type) {
    List<Invokable<?, ? extends T>> factories = Lists.newArrayList();
    for (Method method : type.getRawType().getDeclaredMethods()) {
      Invokable<?, ?> invokable = type.method(method);
      if (!invokable.isPrivate()
          && !invokable.isSynthetic()
          && invokable.isStatic()
          && type.isAssignableFrom(invokable.getReturnType())) {
        @SuppressWarnings("unchecked"// guarded by isAssignableFrom()
        Invokable<?, ? extends T> factory = (Invokable<?, ? extends T>) invokable;
        factories.add(factory);
      }
    }
    if (!Modifier.isAbstract(type.getRawType().getModifiers())) {
      for (Constructor<?> constructor : type.getRawType().getDeclaredConstructors()) {
        Invokable<T, T> invokable = type.constructor(constructor);
        if (!invokable.isPrivate() && !invokable.isSynthetic()) {
          factories.add(invokable);
        }
      }
    }
    for (Invokable<?, ?> factory : factories) {
      factory.setAccessible(true);
    }
    // Sorts methods/constructors with least number of parameters first since it's likely easier to
    // fill dummy parameter values for them. Ties are broken by name then by the string form of the
    // parameter list.
        .immutableSortedCopy(factories);
  }
  private List<ObjectgetDummyArguments(Invokable<?, ?> invokable)
    List<Objectargs = Lists.newArrayList();
    for (Parameter param : invokable.getParameters()) {
      if (param.isAnnotationPresent(Nullable.class)) {
        args.add(null);
        continue;
      }
      Object defaultValue = getDummyValue(param.getType());
      if (defaultValue == null) {
        throw new ParameterNotInstantiableException(param);
      }
      args.add(defaultValue);
    }
    return args;
  }
  private <T> T getDummyValue(TypeToken<T> type) {
    Class<? super T> rawType = type.getRawType();
    @SuppressWarnings("unchecked"// Assume all default values are generics safe.
    T defaultValue = (T) .getInstance(rawType);
    if (defaultValue != null) {
      return defaultValue;
    }
    @SuppressWarnings("unchecked"// ArbitraryInstances always returns generics-safe dummies.
    T value = (T) ArbitraryInstances.get(rawType);
    if (value != null) {
      return value;
    }
    if (rawType.isInterface()) {
      return new SerializableDummyProxy(this).newProxy(type);
    }
    return null;
  }
  private static <T> T createInstance(Invokable<?, ? extends T> factoryList<?> args)
    T instance = invoke(factoryargs);
    if (instance == null) {
      throw new FactoryMethodReturnsNullException(factory);
    }
    return instance;
  }
  @Nullable private static <T> T invoke(Invokable<?, ? extends T> factoryList<?> args)
    T returnValue = factory.invoke(nullargs.toArray());
    if (returnValue == null) {
      Assert.assertTrue(factory + " returns null but it's not annotated with @Nullable",
          factory.isAnnotationPresent(Nullable.class));
    }
    return returnValue;
  }

  
Thrown if the test tries to invoke a constructor or static factory method but failed because the dummy value of a constructor or method parameter is unknown.
    public ParameterNotInstantiableException(Parameter parameter) {
      super("Cannot determine value for parameter " + parameter
          + " of " + parameter.getDeclaringInvokable());
    }
  }

  
Thrown if the test fails to generate two distinct non-null values of a constructor or factory parameter in order to test Object.equals and Object.hashCode of the declaring class.
        super("Cannot generate distinct value for parameter " + parameter
            + " of " + parameter.getDeclaringInvokable());
    }
  }

  
Thrown if the test tries to invoke a static factory method to test instance methods but the factory returned null.
    public FactoryMethodReturnsNullException(Invokable<?, ?> factory) {
      super(factory + " returns null and cannot be used to test instance methods.");
    }
  }
  private static final class SerializableDummyProxy extends DummyProxy
      implements Serializable {
    private transient final ClassSanityTester tester;
      this. = tester;
    }
    @Override <R> R dummyReturnValue(TypeToken<R> returnType) {
      return .getDummyValue(returnType);
    }
    @Override public boolean equals(Object obj) {
      return obj instanceof SerializableDummyProxy;
    }
    @Override public int hashCode() {
      return 0;
    }
  }
New to GrepCode? Check out our FAQ X