aboutsummaryrefslogtreecommitdiff
path: root/javatests/dagger/internal/codegen/bindinggraphvalidation
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/dagger/internal/codegen/bindinggraphvalidation')
-rw-r--r--javatests/dagger/internal/codegen/bindinggraphvalidation/BUILD37
-rw-r--r--javatests/dagger/internal/codegen/bindinggraphvalidation/NullableBindingValidationTest.java410
2 files changed, 0 insertions, 447 deletions
diff --git a/javatests/dagger/internal/codegen/bindinggraphvalidation/BUILD b/javatests/dagger/internal/codegen/bindinggraphvalidation/BUILD
deleted file mode 100644
index 551e09139..000000000
--- a/javatests/dagger/internal/codegen/bindinggraphvalidation/BUILD
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2020 The Dagger 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.
-
-# Description:
-# Tests for dagger.internal.codegen.bindinggraphvalidation
-
-load("//:build_defs.bzl", "DOCLINT_HTML_AND_SYNTAX")
-load("//:test_defs.bzl", "GenJavaTests")
-
-package(default_visibility = ["//:src"])
-
-GenJavaTests(
- name = "bindinggraphvalidation_tests",
- srcs = glob(["*.java"]),
- functional = False,
- javacopts = DOCLINT_HTML_AND_SYNTAX,
- deps = [
- "//java/dagger/internal/codegen/bindinggraphvalidation",
- "//javatests/dagger/internal/codegen:compilers",
- "@google_bazel_common//third_party/java/compile_testing",
- "@google_bazel_common//third_party/java/javapoet",
- "@google_bazel_common//third_party/java/junit",
- "@google_bazel_common//third_party/java/truth",
- "@maven//:com_google_auto_auto_common",
- ],
-)
diff --git a/javatests/dagger/internal/codegen/bindinggraphvalidation/NullableBindingValidationTest.java b/javatests/dagger/internal/codegen/bindinggraphvalidation/NullableBindingValidationTest.java
deleted file mode 100644
index 50a65acd7..000000000
--- a/javatests/dagger/internal/codegen/bindinggraphvalidation/NullableBindingValidationTest.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright (C) 2018 The Dagger 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 dagger.internal.codegen.bindinggraphvalidation;
-
-import static com.google.testing.compile.CompilationSubject.assertThat;
-import static dagger.internal.codegen.Compilers.compilerWithOptions;
-import static dagger.internal.codegen.Compilers.daggerCompiler;
-import static dagger.internal.codegen.bindinggraphvalidation.NullableBindingValidator.nullableToNonNullable;
-
-import com.google.testing.compile.Compilation;
-import com.google.testing.compile.JavaFileObjects;
-import javax.tools.JavaFileObject;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class NullableBindingValidationTest {
- private static final JavaFileObject NULLABLE =
- JavaFileObjects.forSourceLines(
- "test.Nullable", // force one-string-per-line format
- "package test;",
- "",
- "public @interface Nullable {}");
-
- @Test public void nullCheckForConstructorParameters() {
- JavaFileObject a = JavaFileObjects.forSourceLines("test.A",
- "package test;",
- "",
- "import javax.inject.Inject;",
- "",
- "final class A {",
- " @Inject A(String string) {}",
- "}");
- JavaFileObject module = JavaFileObjects.forSourceLines("test.TestModule",
- "package test;",
- "",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "final class TestModule {",
- " @Nullable @Provides String provideString() { return null; }",
- "}");
- JavaFileObject component = JavaFileObjects.forSourceLines("test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " A a();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, a, module, component);
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- nullableToNonNullable(
- "String",
- "@Nullable @Provides String TestModule.provideString()"));
-
- // but if we disable the validation, then it compiles fine.
- Compilation compilation2 =
- compilerWithOptions("-Adagger.nullableValidation=WARNING")
- .compile(NULLABLE, a, module, component);
- assertThat(compilation2).succeeded();
- }
-
- @Test public void nullCheckForMembersInjectParam() {
- JavaFileObject a = JavaFileObjects.forSourceLines("test.A",
- "package test;",
- "",
- "import javax.inject.Inject;",
- "",
- "final class A {",
- " @Inject A() {}",
- " @Inject void register(String string) {}",
- "}");
- JavaFileObject module = JavaFileObjects.forSourceLines("test.TestModule",
- "package test;",
- "",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "final class TestModule {",
- " @Nullable @Provides String provideString() { return null; }",
- "}");
- JavaFileObject component = JavaFileObjects.forSourceLines("test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " A a();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, a, module, component);
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- nullableToNonNullable(
- "String",
- "@Nullable @Provides String TestModule.provideString()"));
-
- // but if we disable the validation, then it compiles fine.
- Compilation compilation2 =
- compilerWithOptions("-Adagger.nullableValidation=WARNING")
- .compile(NULLABLE, a, module, component);
- assertThat(compilation2).succeeded();
- }
-
- @Test public void nullCheckForVariable() {
- JavaFileObject a = JavaFileObjects.forSourceLines("test.A",
- "package test;",
- "",
- "import javax.inject.Inject;",
- "",
- "final class A {",
- " @Inject String string;",
- " @Inject A() {}",
- "}");
- JavaFileObject module = JavaFileObjects.forSourceLines("test.TestModule",
- "package test;",
- "",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "final class TestModule {",
- " @Nullable @Provides String provideString() { return null; }",
- "}");
- JavaFileObject component = JavaFileObjects.forSourceLines("test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " A a();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, a, module, component);
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- nullableToNonNullable(
- "String",
- "@Nullable @Provides String TestModule.provideString()"));
-
- // but if we disable the validation, then it compiles fine.
- Compilation compilation2 =
- compilerWithOptions("-Adagger.nullableValidation=WARNING")
- .compile(NULLABLE, a, module, component);
- assertThat(compilation2).succeeded();
- }
-
- @Test public void nullCheckForComponentReturn() {
- JavaFileObject module = JavaFileObjects.forSourceLines("test.TestModule",
- "package test;",
- "",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "final class TestModule {",
- " @Nullable @Provides String provideString() { return null; }",
- "}");
- JavaFileObject component = JavaFileObjects.forSourceLines("test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " String string();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, module, component);
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- nullableToNonNullable(
- "String",
- "@Nullable @Provides String TestModule.provideString()"));
-
- // but if we disable the validation, then it compiles fine.
- Compilation compilation2 =
- compilerWithOptions("-Adagger.nullableValidation=WARNING")
- .compile(NULLABLE, module, component);
- assertThat(compilation2).succeeded();
- }
-
- @Test
- public void nullCheckForOptionalInstance() {
- JavaFileObject a =
- JavaFileObjects.forSourceLines(
- "test.A",
- "package test;",
- "",
- "import com.google.common.base.Optional;",
- "import javax.inject.Inject;",
- "",
- "final class A {",
- " @Inject A(Optional<String> optional) {}",
- "}");
- JavaFileObject module =
- JavaFileObjects.forSourceLines(
- "test.TestModule",
- "package test;",
- "",
- "import dagger.BindsOptionalOf;",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "abstract class TestModule {",
- " @Nullable @Provides static String provideString() { return null; }",
- " @BindsOptionalOf abstract String optionalString();",
- "}");
- JavaFileObject component =
- JavaFileObjects.forSourceLines(
- "test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " A a();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, a, module, component);
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- nullableToNonNullable(
- "String",
- "@Nullable @Provides String TestModule.provideString()"));
- }
-
- @Test
- public void nullCheckForOptionalProvider() {
- JavaFileObject a =
- JavaFileObjects.forSourceLines(
- "test.A",
- "package test;",
- "",
- "import com.google.common.base.Optional;",
- "import javax.inject.Inject;",
- "import javax.inject.Provider;",
- "",
- "final class A {",
- " @Inject A(Optional<Provider<String>> optional) {}",
- "}");
- JavaFileObject module =
- JavaFileObjects.forSourceLines(
- "test.TestModule",
- "package test;",
- "",
- "import dagger.BindsOptionalOf;",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "abstract class TestModule {",
- " @Nullable @Provides static String provideString() { return null; }",
- " @BindsOptionalOf abstract String optionalString();",
- "}");
- JavaFileObject component =
- JavaFileObjects.forSourceLines(
- "test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " A a();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, a, module, component);
- assertThat(compilation).succeeded();
- }
-
- @Test
- public void nullCheckForOptionalLazy() {
- JavaFileObject a =
- JavaFileObjects.forSourceLines(
- "test.A",
- "package test;",
- "",
- "import com.google.common.base.Optional;",
- "import dagger.Lazy;",
- "import javax.inject.Inject;",
- "",
- "final class A {",
- " @Inject A(Optional<Lazy<String>> optional) {}",
- "}");
- JavaFileObject module =
- JavaFileObjects.forSourceLines(
- "test.TestModule",
- "package test;",
- "",
- "import dagger.BindsOptionalOf;",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "abstract class TestModule {",
- " @Nullable @Provides static String provideString() { return null; }",
- " @BindsOptionalOf abstract String optionalString();",
- "}");
- JavaFileObject component =
- JavaFileObjects.forSourceLines(
- "test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " A a();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, a, module, component);
- assertThat(compilation).succeeded();
- }
-
- @Test
- public void nullCheckForOptionalProviderOfLazy() {
- JavaFileObject a =
- JavaFileObjects.forSourceLines(
- "test.A",
- "package test;",
- "",
- "import com.google.common.base.Optional;",
- "import dagger.Lazy;",
- "import javax.inject.Inject;",
- "import javax.inject.Provider;",
- "",
- "final class A {",
- " @Inject A(Optional<Provider<Lazy<String>>> optional) {}",
- "}");
- JavaFileObject module =
- JavaFileObjects.forSourceLines(
- "test.TestModule",
- "package test;",
- "",
- "import dagger.BindsOptionalOf;",
- "import dagger.Provides;",
- "import javax.inject.Inject;",
- "",
- "@dagger.Module",
- "abstract class TestModule {",
- " @Nullable @Provides static String provideString() { return null; }",
- " @BindsOptionalOf abstract String optionalString();",
- "}");
- JavaFileObject component =
- JavaFileObjects.forSourceLines(
- "test.TestComponent",
- "package test;",
- "",
- "import dagger.Component;",
- "",
- "@Component(modules = TestModule.class)",
- "interface TestComponent {",
- " A a();",
- "}");
- Compilation compilation = daggerCompiler().compile(NULLABLE, a, module, component);
- assertThat(compilation).succeeded();
- }
-
- @Test
- public void moduleValidation() {
- JavaFileObject module =
- JavaFileObjects.forSourceLines(
- "test.TestModule",
- "package test;",
- "",
- "import dagger.Binds;",
- "import dagger.Module;",
- "import dagger.Provides;",
- "",
- "@Module",
- "abstract class TestModule {",
- " @Provides @Nullable static String nullableString() { return null; }",
- " @Binds abstract Object object(String string);",
- "}");
-
- Compilation compilation =
- compilerWithOptions("-Adagger.fullBindingGraphValidation=ERROR")
- .compile(module, NULLABLE);
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- nullableToNonNullable(
- "String",
- "@Provides @Nullable String TestModule.nullableString()"));
- }
-}