-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates cycle indirection scenarios for tests
Creates `IndirectionCycle` with regular provided dependencies, `BindsIndirectionCycle` for bound dependencies indirection, and `MultibindProviderMapIndirectionCycle` for the scenario pinpointed in issue #175 and resolved by #198.
- Loading branch information
1 parent
0a47d59
commit fecdb36
Showing
5 changed files
with
145 additions
and
1 deletion.
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
39 changes: 39 additions & 0 deletions
39
integration-tests/src/main/java/com/example/BindsIndirectionCycle.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,39 @@ | ||
package com.example; | ||
|
||
import dagger.Binds; | ||
import dagger.Component; | ||
import dagger.Lazy; | ||
import dagger.Module; | ||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
|
||
@Component(modules = BindsIndirectionCycle.Module1.class) | ||
public interface BindsIndirectionCycle { | ||
B b(); | ||
|
||
class A { | ||
public final B b; | ||
|
||
@Inject | ||
A(B b) { | ||
this.b = b; | ||
} | ||
} | ||
|
||
class B { | ||
public final Provider<Object> providerObject; | ||
@Inject public Lazy<Object> lazyObject; | ||
@Inject public Provider<Lazy<Object>> lazyProviderObject; | ||
|
||
@Inject | ||
B(Provider<Object> providerObject) { | ||
this.providerObject = providerObject; | ||
} | ||
} | ||
|
||
@Module | ||
abstract class Module1 { | ||
@Binds | ||
abstract Object bindsA(A a); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
integration-tests/src/main/java/com/example/IndirectionCycle.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,42 @@ | ||
package com.example; | ||
|
||
import dagger.Component; | ||
import dagger.Lazy; | ||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
|
||
@Component | ||
public interface IndirectionCycle { | ||
A a(); | ||
|
||
C c(); | ||
|
||
class A { | ||
public final B b; | ||
|
||
@Inject | ||
A(B b) { | ||
this.b = b; | ||
} | ||
} | ||
|
||
class B { | ||
public final C c; | ||
|
||
@Inject | ||
B(C c) { | ||
this.c = c; | ||
} | ||
} | ||
|
||
class C { | ||
public final Provider<A> providerA; | ||
@Inject public Lazy<A> lazyA; | ||
@Inject public Provider<Lazy<A>> lazyProviderA; | ||
|
||
@Inject | ||
C(Provider<A> providerA) { | ||
this.providerA = providerA; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
integration-tests/src/main/java/com/example/MultibindingProviderMapIndirectionCycle.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,34 @@ | ||
package com.example; | ||
|
||
import dagger.Component; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.multibindings.IntoMap; | ||
import dagger.multibindings.StringKey; | ||
import java.util.Map; | ||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
|
||
@Component(modules = MultibindingProviderMapIndirectionCycle.Module1.class) | ||
public interface MultibindingProviderMapIndirectionCycle { | ||
Factory factory(); | ||
|
||
@Module | ||
abstract class Module1 { | ||
@Provides | ||
@IntoMap | ||
@StringKey("1") | ||
static Long one(Factory factory) { | ||
return 1L; | ||
} | ||
} | ||
|
||
class Factory { | ||
public final Map<String, Provider<Long>> providerMap; | ||
|
||
@Inject | ||
Factory(Map<String, Provider<Long>> providerMap) { | ||
this.providerMap = providerMap; | ||
} | ||
} | ||
} |
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