forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request square#453 from google/moe_sync_8/31
MOE sync 8/31
- Loading branch information
Showing
75 changed files
with
4,532 additions
and
887 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...it/functional-tests/src/main/java/test/ModuleIncludesCollectedFromModuleSuperclasses.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2016 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 test; | ||
|
||
import dagger.Component; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
/** | ||
* This tests that @Module.includes are traversed for supertypes of a module. | ||
*/ | ||
final class ModuleIncludesCollectedFromModuleSuperclasses { | ||
@Component(modules = TopLevelModule.class) | ||
interface C { | ||
Foo<String> foo(); | ||
int includedInTopLevelModule(); | ||
String includedFromModuleInheritance(); | ||
} | ||
|
||
@Module(includes = IncludedTopLevel.class) | ||
static class TopLevelModule extends FooModule<String> {} | ||
|
||
static class Foo<T> {} | ||
|
||
@Module(includes = IncludedFromModuleInheritance.class) | ||
abstract static class FooModule<T> extends FooCreator { | ||
@Provides Foo<T> fooOfT() { | ||
return createFoo(); | ||
} | ||
} | ||
|
||
static class FooCreator { | ||
<T> Foo<T> createFoo() { | ||
return new Foo<T>(); | ||
} | ||
} | ||
|
||
@Module | ||
static class IncludedTopLevel { | ||
@Provides int i() { | ||
return 123; | ||
} | ||
} | ||
|
||
@Module | ||
static class IncludedFromModuleInheritance { | ||
@Provides String inheritedProvision() { | ||
return "inherited"; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ctional-tests/src/main/java/test/subcomponent/SubcomponentFromModuleAndFactoryMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2016 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 test.subcomponent; | ||
|
||
import dagger.Component; | ||
import dagger.Module; | ||
import dagger.Subcomponent; | ||
|
||
/** | ||
* Tests for {@link Subcomponent}s which are defined with {@link Module#subcomponents()} and are | ||
* also requested as component factory methods. | ||
*/ | ||
public class SubcomponentFromModuleAndFactoryMethod { | ||
@Subcomponent | ||
interface Sub { | ||
@Subcomponent.Builder | ||
interface Builder { | ||
Sub sub(); | ||
} | ||
} | ||
|
||
@Module(subcomponents = Sub.class) | ||
class ModuleWithSubcomponent {} | ||
|
||
@Component(modules = ModuleWithSubcomponent.class) | ||
interface ExposesBuilder { | ||
Sub.Builder subcomponentBuilder(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...iler/src/it/functional-tests/src/main/java/test/subcomponent/UsesModuleSubcomponents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (C) 2016 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 test.subcomponent; | ||
|
||
import dagger.Component; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.Subcomponent; | ||
import dagger.multibindings.IntoSet; | ||
import java.util.Set; | ||
import javax.inject.Inject; | ||
|
||
/** Supporting types for {@link ModuleWithSubcomponentsTest}. */ | ||
@Component(modules = UsesModuleSubcomponents.ModuleWithSubcomponents.class) | ||
public interface UsesModuleSubcomponents { | ||
UsesChild usesChild(); | ||
|
||
Set<String> strings(); | ||
|
||
@Module(subcomponents = Child.class, includes = AlsoIncludesSubcomponents.class) | ||
class ModuleWithSubcomponents { | ||
@Provides | ||
@IntoSet | ||
static String provideStringInParent() { | ||
return "from parent"; | ||
} | ||
} | ||
|
||
@Module(subcomponents = Child.class) | ||
class AlsoIncludesSubcomponents {} | ||
|
||
@Subcomponent(modules = ChildModule.class) | ||
interface Child { | ||
Set<String> strings(); | ||
|
||
@Subcomponent.Builder | ||
interface Builder { | ||
Child build(); | ||
} | ||
} | ||
|
||
@Module | ||
class ChildModule { | ||
@Provides | ||
@IntoSet | ||
static String provideStringInChild() { | ||
return "from child"; | ||
} | ||
} | ||
|
||
class UsesChild { | ||
Set<String> strings; | ||
|
||
@Inject | ||
UsesChild(Child.Builder childBuilder) { | ||
this.strings = childBuilder.build().strings(); | ||
} | ||
} | ||
|
||
@Module(includes = ModuleWithSubcomponents.class) | ||
class OnlyIncludesModuleWithSubcomponents {} | ||
|
||
@Component(modules = OnlyIncludesModuleWithSubcomponents.class) | ||
interface ParentIncludesSubcomponentTransitively extends UsesModuleSubcomponents {} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
...functional-tests/src/main/java/test/subcomponent/pruning/ParentDoesntUseSubcomponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (C) 2016 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 test.subcomponent.pruning; | ||
|
||
import dagger.Component; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.Subcomponent; | ||
import dagger.multibindings.IntoSet; | ||
import java.util.Set; | ||
import javax.inject.Qualifier; | ||
|
||
/** | ||
* Supporting types for {@link SubcomponentOnlyRequestedBySiblingTest}. {@link ChildA} is a direct | ||
* child of the top level component, but is only requested within its sibling, not directly from its | ||
* parent. | ||
*/ | ||
@Component(modules = ParentDoesntUseSubcomponent.ParentModule.class) | ||
interface ParentDoesntUseSubcomponent { | ||
|
||
ChildB.Builder childBBuilder(); | ||
|
||
@Subcomponent(modules = ChildAModule.class) | ||
interface ChildA { | ||
@Subcomponent.Builder | ||
interface Builder { | ||
ChildA build(); | ||
} | ||
|
||
Set<Class<?>> componentHierarchy(); | ||
} | ||
|
||
@Subcomponent(modules = ChildBModule.class) | ||
interface ChildB { | ||
@Subcomponent.Builder | ||
interface Builder { | ||
ChildB build(); | ||
} | ||
|
||
Set<Class<?>> componentHierarchy(); | ||
|
||
@FromChildA | ||
Set<Class<?>> componentHierarchyFromChildA(); | ||
} | ||
|
||
@Module(subcomponents = {ChildA.class, ChildB.class}) | ||
class ParentModule { | ||
@Provides | ||
@IntoSet | ||
static Class<?> provideComponentType() { | ||
return ParentDoesntUseSubcomponent.class; | ||
} | ||
} | ||
|
||
@Module | ||
class ChildAModule { | ||
@Provides | ||
@IntoSet | ||
static Class<?> provideComponentType() { | ||
return ChildA.class; | ||
} | ||
} | ||
|
||
@Module | ||
class ChildBModule { | ||
@Provides | ||
@IntoSet | ||
static Class<?> provideComponentType() { | ||
return ChildB.class; | ||
} | ||
|
||
@Provides | ||
@FromChildA | ||
Set<Class<?>> fromChildA(ChildA.Builder childABuilder) { | ||
return childABuilder.build().componentHierarchy(); | ||
} | ||
} | ||
|
||
@Qualifier | ||
@interface FromChildA {} | ||
} |
30 changes: 30 additions & 0 deletions
30
...nal-tests/src/main/java/test/subcomponent/repeat/OtherSubcomponentWithRepeatedModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2015 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 test.subcomponent.repeat; | ||
|
||
import dagger.Subcomponent; | ||
|
||
@Subcomponent(modules = RepeatedModule.class) | ||
interface OtherSubcomponentWithRepeatedModule extends SubcomponentWithRepeatedModule { | ||
|
||
@Subcomponent.Builder | ||
interface Builder { | ||
Builder repeatedModule(RepeatedModule repeatedModule); | ||
|
||
OtherSubcomponentWithRepeatedModule build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../src/it/functional-tests/src/test/java/test/subcomponent/ModuleWithSubcomponentsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2016 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 test.subcomponent; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import dagger.Module; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
import test.subcomponent.UsesModuleSubcomponents.ParentIncludesSubcomponentTransitively; | ||
|
||
/** Tests for {@link Module#subcomponents()}. */ | ||
@RunWith(JUnit4.class) | ||
public class ModuleWithSubcomponentsTest { | ||
|
||
@Test | ||
public void subcomponentFromModules() { | ||
UsesModuleSubcomponents parent = DaggerUsesModuleSubcomponents.create(); | ||
assertThat(parent.strings()).containsExactly("from parent"); | ||
assertThat(parent.usesChild().strings).containsExactly("from parent", "from child"); | ||
} | ||
|
||
@Test | ||
public void subcomponentFromModules_transitively() { | ||
ParentIncludesSubcomponentTransitively parent = | ||
DaggerUsesModuleSubcomponents_ParentIncludesSubcomponentTransitively.create(); | ||
assertThat(parent.strings()).containsExactly("from parent"); | ||
assertThat(parent.usesChild().strings).containsExactly("from parent", "from child"); | ||
} | ||
} |
Oops, something went wrong.