Skip to content

Commit

Permalink
Refactor javatests/dagger/functional/builder/ tests.
Browse files Browse the repository at this point in the history
This CL does 3 main things:

  * Moves all dependencies for a test inside the test itself so that
    the test fully encapsulated and isolated from other tests in the package.
  * Creates separate test target for each test. This makes it easier to modify
    individual tests without affecting other tests in the same package.
  * Create actual tests for classes that we were previously just treating as
    "build" tests (`BuildMethodCovariantReturnInheritedTest`, `BuildMethodCovariantReturnTest`, and `PrivateConstructorsTest`).

RELNOTES=N/A
PiperOrigin-RevId: 466481296
  • Loading branch information
bcorso authored and Dagger Team committed Aug 9, 2022
1 parent 451640c commit 613e716
Show file tree
Hide file tree
Showing 26 changed files with 693 additions and 818 deletions.
101 changes: 101 additions & 0 deletions javatests/dagger/functional/builder/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright (C) 2022 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:
# Functional tests for Dagger builders

load("//:build_defs.bzl", "DOCLINT_HTML_AND_SYNTAX", "SOURCE_7_TARGET_7")
load("//:test_defs.bzl", "GenJavaTests")

package(default_visibility = ["//:src"])

GenJavaTests(
name = "BuilderBindsInstanceParameterTest",
srcs = ["BuilderBindsInstanceParameterTest.java"],
javacopts = DOCLINT_HTML_AND_SYNTAX,
lib_javacopts = SOURCE_7_TARGET_7,
test_only_deps = [
"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/guava:testlib",
"//third_party/java/truth",
"//third_party/java/junit",
"//:dagger_with_compiler",
],
deps = [],
)

GenJavaTests(
name = "BuilderTest",
srcs = ["BuilderTest.java"],
javacopts = DOCLINT_HTML_AND_SYNTAX,
lib_javacopts = SOURCE_7_TARGET_7,
test_only_deps = [
"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/guava:testlib",
"//third_party/java/truth",
"//third_party/java/junit",
"//:dagger_with_compiler",
],
deps = [],
)

GenJavaTests(
name = "PrivateConstructorsTest",
srcs = ["PrivateConstructorsTest.java"],
javacopts = DOCLINT_HTML_AND_SYNTAX,
lib_javacopts = SOURCE_7_TARGET_7,
test_only_deps = [
"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/guava:testlib",
"//third_party/java/truth",
"//third_party/java/junit",
"//:dagger_with_compiler",
],
deps = [],
)

GenJavaTests(
name = "BuildMethodCovariantReturnTest",
srcs = ["BuildMethodCovariantReturnTest.java"],
javacopts = DOCLINT_HTML_AND_SYNTAX,
lib_javacopts = SOURCE_7_TARGET_7,
test_only_deps = [
"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/guava:testlib",
"//third_party/java/truth",
"//third_party/java/junit",
"//:dagger_with_compiler",
],
deps = [],
)

GenJavaTests(
name = "BuildMethodCovariantReturnInheritedTest",
srcs = ["BuildMethodCovariantReturnInheritedTest.java"],
javacopts = DOCLINT_HTML_AND_SYNTAX,
lib_javacopts = SOURCE_7_TARGET_7,
test_only_deps = [
"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/guava:testlib",
"//third_party/java/truth",
"//third_party/java/junit",
"//:dagger_with_compiler",
],
deps = [],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

package dagger.functional.builder;

import dagger.Component;
import static com.google.common.truth.Truth.assertThat;

import dagger.Component;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

interface BuildMethodCovariantReturnInherited {
@RunWith(JUnit4.class)
public class BuildMethodCovariantReturnInheritedTest {
@Component
interface Simple {
interface BuilderSupertype {
Expand Down Expand Up @@ -55,4 +60,26 @@ interface GenericBuilderSupertype<T> {
@Component.Builder
interface Builder extends GenericBuilderSupertype<Object> {}
}

@Test
public void simpleComponentTest() {
Object component = DaggerBuildMethodCovariantReturnInheritedTest_Simple.builder().build();
assertThat(component).isInstanceOf(Simple.class);
}

@Test
public void genericBuilderTypeTest() {
ComponentSupertype component =
DaggerBuildMethodCovariantReturnInheritedTest_GenericBuilderType.builder().build();
assertThat(component).isInstanceOf(GenericBuilderType.class);
}

@Test
public void genericComponentSupertypeAndBuilderSupertypeTest() {
ParameterizedComponentSupertype<Object> component =
DaggerBuildMethodCovariantReturnInheritedTest_GenericComponentSupertypeAndBuilderSupertype
.builder()
.build();
assertThat(component).isInstanceOf(GenericComponentSupertypeAndBuilderSupertype.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@

package dagger.functional.builder;

import static com.google.common.truth.Truth.assertThat;

import dagger.Component;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@Component
interface BuildMethodCovariantReturn {
@RunWith(JUnit4.class)
public final class BuildMethodCovariantReturnTest {
@Component
interface C {
@Component.Builder
interface Builder {
Object build();
}
}

@Component.Builder
interface Builder {
Object build();
@Test
public void componentTest() {
Object component = DaggerBuildMethodCovariantReturnTest_C.builder().build();
assertThat(component).isInstanceOf(C.class);
}
}

0 comments on commit 613e716

Please sign in to comment.