Skip to content

Commit

Permalink
Add Gradle tests that use transitive types and annotation on base com…
Browse files Browse the repository at this point in the history
…ponents, base component factories, and component dependencies in the transitive-annotation-app.

RELNOTES=N/A
PiperOrigin-RevId: 428791214
  • Loading branch information
bcorso authored and Dagger Team committed Feb 15, 2022
1 parent 3ae46b8 commit 0b9398e
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 25 deletions.
@@ -0,0 +1,133 @@
/*
* 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.
*/

package library1;

import library2.MyTransitiveAnnotation;
import library2.MyTransitiveType;

/**
* A class used to test that Dagger won't fail on unresolvable transitive types used in non-dagger
* related elements and annotations.
*/
// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public abstract class MyBaseComponent {
@MyQualifier
// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public abstract MyComponentModule.UnscopedQualifiedBindsType unscopedQualifiedBindsTypeBase();

// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public abstract MyComponentModule.UnscopedUnqualifiedBindsType unscopedUnqualifiedBindsTypeBase();

// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public abstract void injectFooBase(
// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE) @MyOtherAnnotation(MyTransitiveType.class) Foo binding);

// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public abstract static class Factory {
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public abstract MyBaseComponent create(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyComponentModule myComponentModule,
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyComponentDependency myComponentDependency);

// Non-dagger factory code

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyTransitiveType nonDaggerField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static MyTransitiveType nonDaggerStaticField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyTransitiveType nonDaggerMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static MyTransitiveType nonDaggerStaticMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}
}

// Non-dagger code

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyTransitiveType nonDaggerField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static MyTransitiveType nonDaggerStaticField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyTransitiveType nonDaggerMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static MyTransitiveType nonDaggerStaticMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}
}
@@ -0,0 +1,88 @@
/*
* 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.
*/

package library1;

import library2.MyTransitiveAnnotation;
import library2.MyTransitiveType;

/**
* A class used to test that Dagger won't fail on unresolvable transitive types used in non-dagger
* related elements and annotations.
*/
// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public final class MyComponentDependency {
private final MyComponentDependencyBinding qualifiedMyComponentDependencyBinding =
new MyComponentDependencyBinding();
private final MyComponentDependencyBinding unqualifiedMyComponentDependencyBinding =
new MyComponentDependencyBinding();

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyComponentDependency() {}

@MyQualifier
// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyComponentDependencyBinding qualifiedMyComponentDependencyBinding() {
return qualifiedMyComponentDependencyBinding;
}

// @MyTransitiveAnnotation: Not yet supported
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyComponentDependencyBinding unqualifiedMyComponentDependencyBinding() {
return unqualifiedMyComponentDependencyBinding;
}

// Non-dagger code

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyTransitiveType nonDaggerField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static MyTransitiveType nonDaggerStaticField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public MyTransitiveType nonDaggerMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static MyTransitiveType nonDaggerStaticMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}
}
@@ -0,0 +1,20 @@
/*
* 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.
*/

package library1;

/** Used as a binding in {@link MyComponentDependency}. */
public final class MyComponentDependencyBinding {}
Expand Up @@ -57,6 +57,9 @@ public abstract void injectFoo(
@MyOtherAnnotation(MyTransitiveType.class)
@Subcomponent.Factory
public abstract static class Factory {
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public abstract MySubcomponentWithFactory create(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
Expand All @@ -79,30 +82,34 @@ public abstract MySubcomponentWithFactory create(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public String nonDaggerField = "";
public MyTransitiveType nonDaggerField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static String nonDaggerStaticField = "";
public static MyTransitiveType nonDaggerStaticField = null;

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public void nonDaggerMethod(
public MyTransitiveType nonDaggerMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
String str) {}
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}

@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
public static void nonDaggerStaticMethod(
public static MyTransitiveType nonDaggerStaticMethod(
@MyTransitiveAnnotation
@MyAnnotation(MyTransitiveType.VALUE)
@MyOtherAnnotation(MyTransitiveType.class)
String str) {}
MyTransitiveType nonDaggerParameter) {
return nonDaggerParameter;
}
}

// Non-dagger code
Expand Down
Expand Up @@ -20,44 +20,54 @@
import javax.inject.Singleton;
import library1.AssistedFoo;
import library1.Foo;
import library1.MyBaseComponent;
import library1.MyComponentDependency;
import library1.MyComponentDependencyBinding;
import library1.MyComponentModule;
import library1.MyQualifier;
import library1.MySubcomponentWithBuilder;
import library1.MySubcomponentWithFactory;

@Singleton
@Component(modules = MyComponentModule.class)
interface MyComponent {
Foo foo();
@Component(dependencies = MyComponentDependency.class, modules = MyComponentModule.class)
abstract class MyComponent extends MyBaseComponent {
abstract Foo foo();

AssistedFoo.Factory assistedFooFactory();
abstract AssistedFoo.Factory assistedFooFactory();

@MyQualifier
MyComponentModule.ScopedQualifiedBindsType scopedQualifiedBindsType();
abstract MyComponentModule.ScopedQualifiedBindsType scopedQualifiedBindsType();

MyComponentModule.ScopedUnqualifiedBindsType scopedUnqualifiedBindsType();
abstract MyComponentModule.ScopedUnqualifiedBindsType scopedUnqualifiedBindsType();

@MyQualifier
MyComponentModule.UnscopedQualifiedBindsType unscopedQualifiedBindsType();
abstract MyComponentModule.UnscopedQualifiedBindsType unscopedQualifiedBindsType();

MyComponentModule.UnscopedUnqualifiedBindsType unscopedUnqualifiedBindsType();
abstract MyComponentModule.UnscopedUnqualifiedBindsType unscopedUnqualifiedBindsType();

@MyQualifier
MyComponentModule.ScopedQualifiedProvidesType scopedQualifiedProvidesType();
abstract MyComponentModule.ScopedQualifiedProvidesType scopedQualifiedProvidesType();

MyComponentModule.ScopedUnqualifiedProvidesType scopedUnqualifiedProvidesType();
abstract MyComponentModule.ScopedUnqualifiedProvidesType scopedUnqualifiedProvidesType();

@MyQualifier
MyComponentModule.UnscopedQualifiedProvidesType unscopedQualifiedProvidesType();
abstract MyComponentModule.UnscopedQualifiedProvidesType unscopedQualifiedProvidesType();

MyComponentModule.UnscopedUnqualifiedProvidesType unscopedUnqualifiedProvidesType();
abstract MyComponentModule.UnscopedUnqualifiedProvidesType unscopedUnqualifiedProvidesType();

MySubcomponentWithFactory.Factory mySubcomponentWithFactory();
abstract MySubcomponentWithFactory.Factory mySubcomponentWithFactory();

MySubcomponentWithBuilder.Builder mySubcomponentWithBuilder();
abstract MySubcomponentWithBuilder.Builder mySubcomponentWithBuilder();

@MyQualifier
abstract MyComponentDependencyBinding qualifiedMyComponentDependencyBinding();

abstract MyComponentDependencyBinding unqualifiedMyComponentDependencyBinding();

@Component.Factory
interface Factory {
MyComponent create(MyComponentModule myComponentModule);
abstract static class Factory extends MyBaseComponent.Factory {
public abstract MyComponent create(
MyComponentModule myComponentModule,
MyComponentDependency myComponentDependency);
}
}
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;

import library1.Dep;
import library1.MyComponentDependency;
import library1.MyComponentModule;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -31,7 +32,8 @@ public final class MyComponentTest {

@Before
public void setup() {
component = DaggerMyComponent.factory().create(new MyComponentModule(new Dep()));
component = DaggerMyComponent.factory()
.create(new MyComponentModule(new Dep()), new MyComponentDependency());
}

@Test
Expand Down Expand Up @@ -91,4 +93,10 @@ public void testUnscopedUnqualifiedProvidesTypeIsNotScoped() {
assertThat(component.unscopedUnqualifiedProvidesType())
.isNotEqualTo(component.unscopedUnqualifiedProvidesType());
}

@Test
public void testMyComponentDependencyBinding() {
assertThat(component.qualifiedMyComponentDependencyBinding())
.isNotEqualTo(component.unqualifiedMyComponentDependencyBinding());
}
}

0 comments on commit 0b9398e

Please sign in to comment.