com.google.common.testing.ClassSanityTester Java Examples

The following examples show how to use com.google.common.testing.ClassSanityTester. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MoreStreamsTest.java    From mug with Apache License 2.0 5 votes vote down vote up
@Test public void testNulls() throws Exception {
  NullPointerTester tester = new NullPointerTester();
  asList(MoreStreams.class.getDeclaredMethods()).stream()
      .filter(m -> m.getName().equals("generate"))
      .forEach(tester::ignore);
  tester.testAllPublicStaticMethods(MoreStreams.class);
  new ClassSanityTester().forAllPublicStaticMethods(MoreStreams.class).testNulls();
}
 
Example #2
Source File: OptionalsTest.java    From mug with Apache License 2.0 5 votes vote down vote up
@Test public void testNulls() throws Exception {
  new NullPointerTester()
      .setDefault(Optional.class, Optional.empty())
      .setDefault(OptionalInt.class, OptionalInt.empty())
      .setDefault(OptionalLong.class, OptionalLong.empty())
      .setDefault(OptionalDouble.class, OptionalDouble.empty())
      .ignore(Optionals.class.getMethod("optional", boolean.class, Object.class))
      .testAllPublicStaticMethods(Optionals.class);
  new NullPointerTester()
      .setDefault(Optional.class, Optional.of("foo"))
      .setDefault(OptionalInt.class, OptionalInt.of(123))
      .setDefault(OptionalLong.class, OptionalLong.of(123))
      .setDefault(OptionalDouble.class, OptionalDouble.of(123))
      .ignore(Optionals.class.getMethod("optional", boolean.class, Object.class))
      .testAllPublicStaticMethods(Optionals.class);
  new ClassSanityTester()
      .setDefault(Optional.class, Optional.empty())
      .setDefault(OptionalInt.class, OptionalInt.empty())
      .setDefault(OptionalLong.class, OptionalLong.empty())
      .setDefault(OptionalDouble.class, OptionalDouble.empty())
      .forAllPublicStaticMethods(Optionals.class).testNulls();
  new ClassSanityTester()
      .setDefault(Optional.class, Optional.of("foo"))
      .setDefault(OptionalInt.class, OptionalInt.of(123))
      .setDefault(OptionalLong.class, OptionalLong.of(123))
      .setDefault(OptionalDouble.class, OptionalDouble.of(123))
      .forAllPublicStaticMethods(Optionals.class).testNulls();
}
 
Example #3
Source File: ParallelizerPreconditionsTest.java    From mug with Apache License 2.0 5 votes vote down vote up
@Test public void testNulls() {
  new ClassSanityTester().testNulls(Parallelizer.class);
  Parallelizer parallelizer = new Parallelizer(threadPool, 1);
  assertThrows(
      NullPointerException.class,
      () -> parallelizer.parallelize(nullTasks(), 1, TimeUnit.MILLISECONDS));
  assertThrows(NullPointerException.class, () -> parallelizer.parallelize(nullTasks()));
  assertThrows(
      NullPointerException.class, () -> parallelizer.parallelizeUninterruptibly(nullTasks()));
}
 
Example #4
Source File: HashCodeTest.java    From exonum-java-binding with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: SelectionTest.java    From mug with Apache License 2.0 4 votes vote down vote up
@Test
public void nullChecks() throws Exception {
  new ClassSanityTester().testNulls(Selection.class);
  new ClassSanityTester().forAllPublicStaticMethods(Selection.class).testNulls();
}
 
Example #6
Source File: FunnelTest.java    From mug with Apache License 2.0 4 votes vote down vote up
@Test public void testNulls() {
  new ClassSanityTester().testNulls(Funnel.class);
  new NullPointerTester().testAllPublicInstanceMethods(new Funnel<String>().through(batch::send));
}
 
Example #7
Source File: ExceptionPlanTest.java    From mug with Apache License 2.0 4 votes vote down vote up
@Test public void testNulls() {
  new ClassSanityTester().testNulls(ExceptionPlan.class);
}
 
Example #8
Source File: SubstringTest.java    From mug with Apache License 2.0 4 votes vote down vote up
private static ClassSanityTester newClassSanityTester() {
  return new ClassSanityTester()
      .setDefault(int.class, 0)
      .setDefault(Substring.Pattern.class, Substring.BEGINNING);
}
 
Example #9
Source File: MaybeTest.java    From mug with Apache License 2.0 4 votes vote down vote up
@Test public void testNulls_instanceMethods() throws Exception {
  new ClassSanityTester()
      .forAllPublicStaticMethods(Maybe.class)
      .testNulls();
}
 
Example #10
Source File: CycleDetectorTest.java    From mug with Apache License 2.0 4 votes vote down vote up
@Test
public void staticMethods_nullCheck() throws Exception {
  new NullPointerTester().testAllPublicStaticMethods(CycleDetector.class);
  new ClassSanityTester().forAllPublicStaticMethods(CycleDetector.class).testNulls();
}
 
Example #11
Source File: WalkerTest.java    From mug with Apache License 2.0 4 votes vote down vote up
@Test
public void staticMethods_nullCheck() throws Exception {
  new NullPointerTester().testAllPublicStaticMethods(Walker.class);
  new ClassSanityTester().forAllPublicStaticMethods(Walker.class).testNulls();
}
 
Example #12
Source File: TestSerializableSaltedHasher.java    From CuckooFilter4J with Apache License 2.0 4 votes vote down vote up
@Test
public void autoTestNulls() {
	new ClassSanityTester().testNulls(SerializableSaltedHasher.class);
}
 
Example #13
Source File: TestFilterTable.java    From CuckooFilter4J with Apache License 2.0 4 votes vote down vote up
@Test
public void autoTestNulls() {
	// chose 15 for int so it passes checks
	new ClassSanityTester().setDefault(int.class, 15).testNulls(FilterTable.class);
}
 
Example #14
Source File: TestIndexTagCalc.java    From CuckooFilter4J with Apache License 2.0 4 votes vote down vote up
@Test
public void autoTestNulls() {
	// chose 8 for int so it passes bucket and tag size checks
	new ClassSanityTester().setDefault(SerializableSaltedHasher.class, getUnsaltedHasher())
			.setDefault(long.class, 8L).setDefault(int.class, 8).testNulls(IndexTagCalc.class);
}
 
Example #15
Source File: TestCuckooFilter.java    From CuckooFilter4J with Apache License 2.0 4 votes vote down vote up
@Test
public void autoTestNulls() {
	// chose 15 for int so it passes checks
	new ClassSanityTester().setDefault(int.class, 15).setDefault(long.class, 15L).setDefault(double.class, 0.001)
			.testNulls(CuckooFilter.class);
}
 
Example #16
Source File: SuppliersTest.java    From durian with Apache License 2.0 4 votes vote down vote up
@GwtIncompatible("reflection")
public void testSuppliersNullChecks() throws Exception {
	new ClassSanityTester().forAllPublicStaticMethods(Suppliers.class)
			.testNulls();
}