/** * Sets the default value for {@code type}, when dummy value for a parameter of the same type * needs to be created in order to invoke a method or constructor. The default value isn't used in * testing {@link Object#equals} because more than one sample instances are needed for testing * inequality. */ protected final <T> void setDefault(Class<T> type, T value) { tester.setDefault(type, value); }
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.class, Class.class); }
/** * Sets distinct values for {@code type}, so that when a class {@code Foo} is tested for {@link * Object#equals} and {@link Object#hashCode}, and its construction requires a parameter of {@code * type}, the distinct values of {@code type} can be passed as parameters to create {@code Foo} * instances that are unequal. * * <p>Calling {@code setDistinctValues(type, v1, v2)} also sets the default value for {@code type} * that's used for {@link #testNulls}. * * <p>Only necessary for types where {@link ClassSanityTester} doesn't already know how to create * distinct values. * * @return 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(value1, value2), "Duplicate value provided."); distinctValues.replaceValues(type, ImmutableList.of(value1, value2)); setDefault(type, value1); return this; }
public void testNulls() throws Exception { new ClassSanityTester() .setDefault(Method.class, FreshValueGeneratorTest.class.getDeclaredMethod("testNulls")) .testNulls(FreshValueGenerator.class); }
public void testNulls() { new ClassSanityTester() .setDefault(ItemReporter.class, new ItemReporter()) .testNulls(RelationshipTester.class); } }
public void testInstantiate_setDefault() throws Exception { NotInstantiable x = new NotInstantiable(); tester.setDefault(NotInstantiable.class, x); assertNotNull(tester.instantiate(ConstructorParameterNotInstantiable.class)); }
private static ClassSanityTester.FactoryMethodReturnValueTester sanityTester() { return new ClassSanityTester() .setDefault(byte[].class, new byte[] {1, 2, 3, 4}) .setDistinctValues(byte[].class, new byte[] {1, 2, 3, 4}, new byte[] {5, 6, 7, 8}) .setDistinctValues(String.class, "7f8005ff0e", "7f8005ff0f") .forAllPublicStaticMethods(HashCode.class); }
public void testExecutors_nullCheck() throws Exception { new ClassSanityTester() .setDefault(RateLimiter.class, RateLimiter.create(1.0)) .forAllPublicStaticMethods(MoreExecutors.class) .thatReturn(Executor.class) .testNulls(); }
/** * Sets the default value for {@code type}, when dummy value for a parameter of the same type * needs to be created in order to invoke a method or constructor. The default value isn't used in * testing {@link Object#equals} because more than one sample instances are needed for testing * inequality. */ protected final <T> void setDefault(Class<T> type, T value) { tester.setDefault(type, value); }
/** * Sets the default value for {@code type}, when dummy value for a parameter of the same type * needs to be created in order to invoke a method or constructor. The default value isn't used in * testing {@link Object#equals} because more than one sample instances are needed for testing * inequality. */ protected final <T> void setDefault(Class<T> type, T value) { tester.setDefault(type, value); }
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.class, Class.class); }
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.class, Class.class); }
public void testNulls() throws Exception { new ClassSanityTester() .setDefault(Method.class, FreshValueGeneratorTest.class.getDeclaredMethod("testNulls")) .testNulls(FreshValueGenerator.class); }
public void testNulls() throws Exception { new ClassSanityTester() .setDefault(Method.class, FreshValueGeneratorTest.class.getDeclaredMethod("testNulls")) .testNulls(FreshValueGenerator.class); }
public void testInstantiate_setDefault() throws Exception { NotInstantiable x = new NotInstantiable(); tester.setDefault(NotInstantiable.class, x); assertNotNull(tester.instantiate(ConstructorParameterNotInstantiable.class)); }
public void testNulls() { new ClassSanityTester() .setDefault(ItemReporter.class, new ItemReporter()) .testNulls(RelationshipTester.class); } }
public void testNulls() { new ClassSanityTester() .setDefault(ItemReporter.class, new ItemReporter()) .testNulls(RelationshipTester.class); } }
public void testInstantiate_setDefault() throws Exception { NotInstantiable x = new NotInstantiable(); tester.setDefault(NotInstantiable.class, x); assertNotNull(tester.instantiate(ConstructorParameterNotInstantiable.class)); }
private static ClassSanityTester.FactoryMethodReturnValueTester sanityTester() { return new ClassSanityTester() .setDefault(byte[].class, new byte[] {1, 2, 3, 4}) .setDistinctValues(byte[].class, new byte[] {1, 2, 3, 4}, new byte[] {5, 6, 7, 8}) .setDistinctValues(String.class, "7f8005ff0e", "7f8005ff0f") .forAllPublicStaticMethods(HashCode.class); }
public void testExecutors_nullCheck() throws Exception { new ClassSanityTester() .setDefault(RateLimiter.class, RateLimiter.create(1.0)) .forAllPublicStaticMethods(MoreExecutors.class) .thatReturn(Executor.class) .testNulls(); }