forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When checking for local contributions, ignore whether the previously …
…resolved binding is for a synthetic binding or not. We should still check for @provides Set<T> and @provides @IntoSet T collisions across components (and the same for maps and @provides Optional<T> + @BindsOptionalOf T). Fixes #975 RELNOTES: - Fix a bug where binding collisions were not properly checked across subcomponent boundaries when a parent provided a concrete `Set`/`Map` and a child provided a multibinding contribution with the same key. - Also applies to providing a concrete optional binding and `@BindsOptionalOf` declarations. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=186678282
- Loading branch information
1 parent
43b6067
commit 98b9c3f
Showing
3 changed files
with
191 additions
and
22 deletions.
There are no files selected for viewing
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
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
96 changes: 96 additions & 0 deletions
96
javatests/dagger/internal/codegen/OptionalBindingTest.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,96 @@ | ||
/* | ||
* 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 dagger.internal.codegen; | ||
|
||
import static com.google.testing.compile.CompilationSubject.assertThat; | ||
import static dagger.internal.codegen.Compilers.daggerCompiler; | ||
|
||
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 OptionalBindingTest { | ||
@Test | ||
public void provideExplicitOptionalInParent_AndBindsOptionalOfInChild() { | ||
JavaFileObject parent = | ||
JavaFileObjects.forSourceLines( | ||
"test.Parent", | ||
"package test;", | ||
"", | ||
"import dagger.Component;", | ||
"import java.util.Optional;", | ||
"", | ||
"@Component(modules = ParentModule.class)", | ||
"interface Parent {", | ||
" Optional<String> optional();", | ||
" Child child();", | ||
"}"); | ||
JavaFileObject parentModule = | ||
JavaFileObjects.forSourceLines( | ||
"test.ParentModule", | ||
"package test;", | ||
"", | ||
"import dagger.Module;", | ||
"import dagger.Provides;", | ||
"import java.util.Optional;", | ||
"", | ||
"@Module", | ||
"class ParentModule {", | ||
" @Provides", | ||
" Optional<String> optional() {", | ||
" return Optional.of(new String());", | ||
" }", | ||
"}"); | ||
|
||
JavaFileObject child = | ||
JavaFileObjects.forSourceLines( | ||
"test.Child", | ||
"package test;", | ||
"", | ||
"import dagger.Subcomponent;", | ||
"import java.util.Optional;", | ||
"", | ||
"@Subcomponent(modules = ChildModule.class)", | ||
"interface Child {", | ||
" Optional<String> optional();", | ||
"}"); | ||
JavaFileObject childModule = | ||
JavaFileObjects.forSourceLines( | ||
"test.ChildModule", | ||
"package test;", | ||
"", | ||
"import dagger.BindsOptionalOf;", | ||
"import dagger.Module;", | ||
"", | ||
"@Module", | ||
"interface ChildModule {", | ||
" @BindsOptionalOf", | ||
" String optionalString();", | ||
"}"); | ||
|
||
Compilation compilation = daggerCompiler().compile(parent, parentModule, child, childModule); | ||
assertThat(compilation).failed(); | ||
assertThat(compilation) | ||
.hadErrorContaining("Optional<java.lang.String> is bound multiple times") | ||
.inFile(parent) | ||
.onLineContaining("interface Parent"); | ||
} | ||
} |