Java Code Examples for com.google.common.testing.NullPointerTester#testAllPublicInstanceMethods()

The following examples show how to use com.google.common.testing.NullPointerTester#testAllPublicInstanceMethods() . 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: JimfsPathTest.java    From jimfs with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullPointerExceptions() throws NoSuchMethodException {
  NullPointerTester tester =
      new NullPointerTester().ignore(JimfsPath.class.getMethod("toRealPath", LinkOption[].class));
  // ignore toRealPath because the pathService creates fake paths that do not have a
  // JimfsFileSystem instance, causing it to fail since it needs to access the file system

  tester.testAllPublicInstanceMethods(pathService.parsePath("/"));
  tester.testAllPublicInstanceMethods(pathService.parsePath(""));
  tester.testAllPublicInstanceMethods(pathService.parsePath("/foo"));
  tester.testAllPublicInstanceMethods(pathService.parsePath("/foo/bar/baz"));
  tester.testAllPublicInstanceMethods(pathService.parsePath("foo"));
  tester.testAllPublicInstanceMethods(pathService.parsePath("foo/bar"));
  tester.testAllPublicInstanceMethods(pathService.parsePath("foo/bar/baz"));
  tester.testAllPublicInstanceMethods(pathService.parsePath("."));
  tester.testAllPublicInstanceMethods(pathService.parsePath(".."));
}
 
Example 2
Source File: PredicatesTest.java    From durian with Apache License 2.0 5 votes vote down vote up
@GwtIncompatible("NullPointerTester")
public void testContains_nulls() throws Exception {
	NullPointerTester tester = new NullPointerTester();
	Predicate<CharSequence> isWooPattern = Predicates.contains(Pattern.compile("Woo"));

	tester.testAllPublicInstanceMethods(isWooPattern);
}
 
Example 3
Source File: CcCompilationHelperTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructorThrowsNPE() throws Exception {
  ConfiguredTarget target =
      scratchConfiguredTarget("a", "b", "cc_library(name = 'b', srcs = [],)");
  RuleContext ruleContext = getRuleContext(target);
  CcToolchainProvider ccToolchain =
      CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext);
  FdoContext fdoContext = ccToolchain.getFdoContext();
  Artifact grepIncludes = getBinArtifact("grep_includes", target);
  NullPointerTester tester =
      new NullPointerTester()
          .setDefault(RuleContext.class, ruleContext)
          .setDefault(CcCommon.class, new CcCommon(ruleContext))
          .setDefault(CppSemantics.class, MockCppSemantics.INSTANCE)
          .setDefault(CcToolchainProvider.class, ccToolchain)
          .setDefault(BuildConfiguration.class, ruleContext.getConfiguration())
          .setDefault(FdoContext.class, fdoContext)
          .setDefault(Label.class, ruleContext.getLabel())
          .setDefault(Artifact.class, grepIncludes)
          .setDefault(CcCompilationOutputs.class, CcCompilationOutputs.builder().build());
  tester.testConstructors(CcCompilationHelper.class, Visibility.PACKAGE);
  tester.testAllPublicInstanceMethods(
      new CcCompilationHelper(
          ruleContext,
          ruleContext,
          target.getLabel(),
          /* grepIncludes= */ null,
          MockCppSemantics.INSTANCE,
          FeatureConfiguration.EMPTY,
          ccToolchain,
          fdoContext,
          /* executionInfo= */ ImmutableMap.of(),
          /* shouldProcessHeaders= */ true));
}
 
Example 4
Source File: ImmutableSortedKeyMapTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void nullPointers() {
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicStaticMethods(ImmutableSortedKeyMap.class);
  tester.testAllPublicInstanceMethods(
      new ImmutableSortedKeyMap.Builder<String, Object>());
  tester.testAllPublicInstanceMethods(ImmutableSortedKeyMap.<String, Integer>of());
  tester.testAllPublicInstanceMethods(ImmutableSortedKeyMap.of("one", 1));
  tester.testAllPublicInstanceMethods(
      ImmutableSortedKeyMap.of("one", 1, "two", 2));
}
 
Example 5
Source File: AaptCommandBuilderTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPassesNullPointerTester() throws Exception {
  NullPointerTester tester = new NullPointerTester().setDefault(Path.class, aapt);

  tester.testConstructor(AaptCommandBuilder.class.getConstructor(Path.class));
  tester.ignore(AaptCommandBuilder.class.getMethod("execute", String.class));
  tester.setDefault(Optional.class, Optional.empty());
  tester.testAllPublicInstanceMethods(new AaptCommandBuilder(aapt));
  tester.testAllPublicInstanceMethods(new AaptCommandBuilder(aapt).when(true));
  tester.testAllPublicInstanceMethods(new AaptCommandBuilder(aapt).when(false));
}
 
Example 6
Source File: JimfsFileChannelTest.java    From jimfs with Apache License 2.0 5 votes vote down vote up
@Test
public void testNullPointerExceptions() throws IOException {
  FileChannel channel = channel(regularFile(100), READ, WRITE);

  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicInstanceMethods(channel);
}
 
Example 7
Source File: BiCollectionTest.java    From mug with Apache License 2.0 5 votes vote down vote up
@Test public void testNulls() {
  NullPointerTester tester = new NullPointerTester();
  asList(BiCollection.class.getDeclaredMethods()).stream()
      .filter(m -> m.getName().equals("of"))
      .forEach(tester::ignore);
  tester.testAllPublicStaticMethods(BiCollection.class);
  tester.testAllPublicInstanceMethods(BiCollection.of());
}
 
Example 8
Source File: PredicatesTest.java    From durian with Apache License 2.0 5 votes vote down vote up
@GwtIncompatible("NullPointerTester")
public void testContainsPattern_nulls() throws Exception {
	NullPointerTester tester = new NullPointerTester();
	Predicate<CharSequence> isWooString = Predicates.containsPattern("Woo");

	tester.testAllPublicInstanceMethods(isWooString);
}
 
Example 9
Source File: MediaTypeTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test // com.google.common.testing.NullPointerTester
public void testNullPointer() {
    final NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicConstructors(MediaType.class);
    tester.testAllPublicStaticMethods(MediaType.class);
    tester.testAllPublicInstanceMethods(MediaType.parse("text/plain"));
}
 
Example 10
Source File: FormFieldTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNullness() {
  NullPointerTester tester =
      new NullPointerTester()
          .setDefault(Class.class, Object.class)
          .setDefault(Function.class, x -> x)
          .setDefault(Pattern.class, Pattern.compile("."))
          .setDefault(String.class, "hello.com");
  tester.testAllPublicStaticMethods(FormField.class);
  tester.testAllPublicInstanceMethods(FormField.named("lol"));
  tester.testAllPublicInstanceMethods(FormField.named("lol").build());
}
 
Example 11
Source File: FormFieldExceptionTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNullness() {
  NullPointerTester tester = new NullPointerTester()
      .setDefault(FormField.class, FormField.named("love").build());
  tester.testAllPublicConstructors(FormFieldException.class);
  tester.testAllPublicStaticMethods(FormFieldException.class);
  tester.testAllPublicInstanceMethods(new FormFieldException("lol"));
}
 
Example 12
Source File: RequestHandlerTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNullness() {
  NullPointerTester tester = new NullPointerTester();
  tester.setDefault(Class.class, Component.class);
  tester.setDefault(RequestAuthenticator.class, requestAuthenticator);
  tester.testAllPublicStaticMethods(RequestHandler.class);
  tester.testAllPublicInstanceMethods(handler);
}
 
Example 13
Source File: CleanerTest.java    From exonum-java-binding with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("UnstableApiUsage") // OK in an internal test
void testRejectsNull() {
  //TODO Consider rewriting this test to get rid of JUnit4 dependency through Guava Testing.
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicInstanceMethods(context);
}
 
Example 14
Source File: CuckooFilterTest.java    From guava-probably with Apache License 2.0 4 votes vote down vote up
@Test
public void nullPointers() {
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicInstanceMethods(CuckooFilter.create(Funnels.unencodedCharsFunnel(), 100));
  tester.testAllPublicStaticMethods(CuckooFilter.class);
}
 
Example 15
Source File: LocalLoadingCacheTest.java    From caffeine with Apache License 2.0 4 votes vote down vote up
public void testNullParameters() throws Exception {
  NullPointerTester tester = new NullPointerTester();
  CacheLoader<Object, Object> loader = identityLoader();
  tester.testAllPublicInstanceMethods(makeCache(createCacheBuilder(), loader));
}
 
Example 16
Source File: CacheBuilderTest.java    From caffeine with Apache License 2.0 4 votes vote down vote up
@GwtIncompatible("NullPointerTester")
public void testNullParameters() throws Exception {
  NullPointerTester tester = new NullPointerTester();
  Caffeine<Object, Object> builder = Caffeine.newBuilder();
  tester.testAllPublicInstanceMethods(builder);
}
 
Example 17
Source File: ExtraDataListTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Test public void testNulls() {
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicConstructors(ExtraDataList.class);
  tester.testAllPublicInstanceMethods(new ExtraDataList());
}
 
Example 18
Source File: ZipFileDataTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Test public void testNulls() {
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicConstructors(ZipFileData.class);
  tester.testAllPublicInstanceMethods(data);
}
 
Example 19
Source File: CidrAddressBlockTest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
public void testNulls() {
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicStaticMethods(CidrAddressBlock.class);
  tester.testAllPublicConstructors(CidrAddressBlock.class);
  tester.testAllPublicInstanceMethods(new CidrAddressBlock("::/0"));
}
 
Example 20
Source File: CuckooFilterTest.java    From guava-probably with Apache License 2.0 4 votes vote down vote up
@Test
public void nullPointers() {
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicInstanceMethods(CuckooFilter.create(Funnels.unencodedCharsFunnel(), 100));
  tester.testAllPublicStaticMethods(CuckooFilter.class);
}