com.google.common.testing.NullPointerTester Java Examples
The following examples show how to use
com.google.common.testing.NullPointerTester.
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 |
@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: LauncherFileWriteActionTest.java From bazel with Apache License 2.0 | 6 votes |
@Test public void testNulls() throws Exception { assertOutput(LaunchInfo.builder().build(), new byte[0]); assertOutput( LaunchInfo.builder().addKeyValuePair("", null).addKeyValuePair("", "").build(), new byte[0]); assertOutput( LaunchInfo.builder() .addJoinedValues("", "", null) .addJoinedValues("", "delimiter", null) .addJoinedValues("", "", ImmutableList.of()) .addJoinedValues("", "delimiter", ImmutableList.of()) .build(), new byte[0]); LaunchInfo.Builder obj = LaunchInfo.builder(); Class<LaunchInfo.Builder> clazz = LaunchInfo.Builder.class; NullPointerTester npt = new NullPointerTester().setDefault(String.class, "foo"); npt.testMethod(obj, clazz.getMethod("addKeyValuePair", String.class, String.class)); npt.testMethod( obj, clazz.getMethod("addJoinedValues", String.class, String.class, Iterable.class)); }
Example #3
Source File: OptionalsTest.java From mug with Apache License 2.0 | 5 votes |
@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 #4
Source File: ProcfsReaderTest.java From micrometer-jvm-extras with Apache License 2.0 | 5 votes |
@Test public void testNullContract() throws Exception { final ProcfsReader uut = new ProcfsReader(BASE, "smaps-001.txt"); final NullPointerTester npt = new NullPointerTester(); npt.testConstructors(uut.getClass(), Visibility.PACKAGE); npt.testStaticMethods(uut.getClass(), Visibility.PACKAGE); npt.testInstanceMethods(uut, Visibility.PACKAGE); }
Example #5
Source File: MoreStreamsTest.java From mug with Apache License 2.0 | 5 votes |
@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 #6
Source File: AaptCommandBuilderTest.java From bazel with Apache License 2.0 | 5 votes |
@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 #7
Source File: ProcfsEntryTest.java From micrometer-jvm-extras with Apache License 2.0 | 5 votes |
@Test public void testNullContract() { final NullPointerTester npt = new NullPointerTester(); npt.testConstructors(uut.getClass(), Visibility.PACKAGE); npt.testStaticMethods(uut.getClass(), Visibility.PACKAGE); npt.testInstanceMethods(uut, Visibility.PACKAGE); }
Example #8
Source File: FunctionsTest.java From mug with Apache License 2.0 | 5 votes |
@Test public void testCheckedBiConsumer_nulls() throws Throwable { CheckedBiConsumer<Object, Object, ?> consumer = (a, b) -> { requireNonNull(a); requireNonNull(b); }; new NullPointerTester().testAllPublicInstanceMethods(consumer); }
Example #9
Source File: ImmutableSortedKeyMapTest.java From bazel with Apache License 2.0 | 5 votes |
@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 #10
Source File: FunctionsTest.java From mug with Apache License 2.0 | 5 votes |
@Test public void testCheckedFunction_nulls() throws Throwable { CheckedFunction<Object, ?, ?> function = x -> { requireNonNull(x); return 1; }; new NullPointerTester().testAllPublicInstanceMethods(function); }
Example #11
Source File: ProcfsSmapsTest.java From micrometer-jvm-extras with Apache License 2.0 | 5 votes |
@Test public void testNullContract() { final ProcfsSmaps uut = new ProcfsSmaps(mock(ProcfsReader.class)); final NullPointerTester npt = new NullPointerTester(); npt.testConstructors(uut.getClass(), Visibility.PACKAGE); npt.testStaticMethods(uut.getClass(), Visibility.PACKAGE); npt.testInstanceMethods(uut, Visibility.PACKAGE); }
Example #12
Source File: CcCompilationHelperTest.java From bazel with Apache License 2.0 | 5 votes |
@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 #13
Source File: JimfsFileChannelTest.java From jimfs with Apache License 2.0 | 5 votes |
@Test public void testNullPointerExceptions() throws IOException { FileChannel channel = channel(regularFile(100), READ, WRITE); NullPointerTester tester = new NullPointerTester(); tester.testAllPublicInstanceMethods(channel); }
Example #14
Source File: FormFieldExceptionTest.java From nomulus with Apache License 2.0 | 5 votes |
@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 #15
Source File: CleanerTest.java From exonum-java-binding with Apache License 2.0 | 5 votes |
@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 #16
Source File: FunctionsTest.java From mug with Apache License 2.0 | 5 votes |
@Test public void testCheckedBiFunction_nulls() throws Throwable { CheckedBiFunction<Object, Object, ?, ?> function = (a, b) -> { requireNonNull(a); requireNonNull(b); return 1; }; new NullPointerTester().testAllPublicInstanceMethods(function); }
Example #17
Source File: BiCollectionTest.java From mug with Apache License 2.0 | 5 votes |
@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 #18
Source File: ProcfsStatusTest.java From micrometer-jvm-extras with Apache License 2.0 | 5 votes |
@Test public void testNullContract() { final ProcfsStatus uut = new ProcfsStatus(mock(ProcfsReader.class)); final NullPointerTester npt = new NullPointerTester(); npt.testConstructors(uut.getClass(), Visibility.PACKAGE); npt.testStaticMethods(uut.getClass(), Visibility.PACKAGE); npt.testInstanceMethods(uut, Visibility.PACKAGE); }
Example #19
Source File: ProcessMemoryMetricsTest.java From micrometer-jvm-extras with Apache License 2.0 | 5 votes |
@Test public void testNullContract() { final ProcessMemoryMetrics uut = new ProcessMemoryMetrics(status); final NullPointerTester npt = new NullPointerTester(); npt.testConstructors(uut.getClass(), Visibility.PACKAGE); npt.testStaticMethods(uut.getClass(), Visibility.PACKAGE); npt.testInstanceMethods(uut, Visibility.PACKAGE); }
Example #20
Source File: RetryerTest.java From mug with Apache License 2.0 | 5 votes |
@Test public void testNulls() throws Exception { Stream<?> statelessStream = (Stream<?>) Proxy.newProxyInstance( RetryerTest.class.getClassLoader(), new Class<?>[] {Stream.class}, (p, method, args) -> method.invoke(Stream.of(), args)); new NullPointerTester() .setDefault(Stream.class, statelessStream) .ignore(Retryer.class.getMethod("uponReturn", Object.class, Stream.class)) .ignore(Retryer.class.getMethod("uponReturn", Object.class, List.class)) .testAllPublicInstanceMethods(new Retryer()); }
Example #21
Source File: RequestHandlerTest.java From nomulus with Apache License 2.0 | 5 votes |
@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 #22
Source File: PredicatesTest.java From durian with Apache License 2.0 | 5 votes |
@GwtIncompatible("NullPointerTester") public void testContains_nulls() throws Exception { NullPointerTester tester = new NullPointerTester(); Predicate<CharSequence> isWooPattern = Predicates.contains(Pattern.compile("Woo")); tester.testAllPublicInstanceMethods(isWooPattern); }
Example #23
Source File: UtilsTest.java From mug with Apache License 2.0 | 5 votes |
@Test public void testNulls() { for (Method method : Utils.class.getDeclaredMethods()) { if (method.isSynthetic()) continue; if (method.getName().equals("cast")) continue; new NullPointerTester().testMethod(null, method); } }
Example #24
Source File: SubstringTest.java From mug with Apache License 2.0 | 5 votes |
@Test public void testNulls() throws Exception { new NullPointerTester().testAllPublicInstanceMethods(Substring.BEGINNING.in("foobar").get()); new NullPointerTester().testAllPublicInstanceMethods(Substring.END.in("foobar").get()); newClassSanityTester() .testNulls(Substring.class); newClassSanityTester() .forAllPublicStaticMethods(Substring.class).testNulls(); }
Example #25
Source File: MaybeTest.java From mug with Apache License 2.0 | 5 votes |
@Test public void testNulls_staticMethods() { for (Method method : Maybe.class.getMethods()) { if (method.isSynthetic()) continue; if (method.getName().equals("of")) continue; if (Modifier.isStatic(method.getModifiers())) { new NullPointerTester().testMethod(null, method); } } }
Example #26
Source File: PredicatesTest.java From durian with Apache License 2.0 | 5 votes |
@GwtIncompatible("NullPointerTester") public void testContainsPattern_nulls() throws Exception { NullPointerTester tester = new NullPointerTester(); Predicate<CharSequence> isWooString = Predicates.containsPattern("Woo"); tester.testAllPublicInstanceMethods(isWooString); }
Example #27
Source File: MediaTypeTest.java From armeria with Apache License 2.0 | 5 votes |
@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 #28
Source File: AuthenticatedRegistrarAccessorTest.java From nomulus with Apache License 2.0 | 5 votes |
@Test public void testNullness() { new NullPointerTester() .setDefault(HttpServletRequest.class, req) .setDefault(HttpServletResponse.class, rsp) .testAllPublicStaticMethods(AuthenticatedRegistrarAccessor.class); }
Example #29
Source File: ProcessThreadMetricsTest.java From micrometer-jvm-extras with Apache License 2.0 | 5 votes |
@Test public void testNullContract() { final ProcessThreadMetrics uut = new ProcessThreadMetrics(status); final NullPointerTester npt = new NullPointerTester(); npt.testConstructors(uut.getClass(), Visibility.PACKAGE); npt.testStaticMethods(uut.getClass(), Visibility.PACKAGE); npt.testInstanceMethods(uut, Visibility.PACKAGE); }
Example #30
Source File: FormFieldTest.java From nomulus with Apache License 2.0 | 5 votes |
@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()); }