-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#175 - Interfaces with generic type parameters that extend other inte…
…rfaces, don't PROVIDE those extended interfaces
- Loading branch information
Showing
5 changed files
with
59 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.example.generic; | ||
|
||
public interface BuildTask { | ||
|
||
void build(); | ||
} |
6 changes: 6 additions & 0 deletions
6
inject-test/src/test/java/org/example/generic/BuildTaskWith.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,6 @@ | ||
package org.example.generic; | ||
|
||
public interface BuildTaskWith<T> extends BuildTask { | ||
|
||
void prepareWith(T param); | ||
} |
20 changes: 20 additions & 0 deletions
20
inject-test/src/test/java/org/example/generic/PathBuildTask.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,20 @@ | ||
package org.example.generic; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import java.nio.file.Path; | ||
|
||
@Singleton | ||
public class PathBuildTask implements BuildTaskWith<Path> { | ||
|
||
@Override | ||
public void prepareWith(Path param) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void build() { | ||
// do nothing | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
inject-test/src/test/java/org/example/generic/PathBuildTaskTest.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,25 @@ | ||
package org.example.generic; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class PathBuildTaskTest { | ||
|
||
@Test | ||
void genericInterfaceWithExtends_expect_providesExtendedInterface() { | ||
|
||
try (BeanScope beanScope = BeanScope.newBuilder().build()) { | ||
|
||
PathBuildTask pathBuildTask = beanScope.get(PathBuildTask.class); | ||
BuildTask buildTask = beanScope.get(BuildTask.class); | ||
|
||
// PathBuildTask is registered as providing PathBuildTask.class, BuildTask.class and generic TYPE_BuildTaskWithPath | ||
assertThat(pathBuildTask).isSameAs(buildTask); | ||
|
||
Object viaType = beanScope.get(PathBuildTask$DI.TYPE_BuildTaskWithPath, null); | ||
assertThat(viaType).isSameAs(buildTask); | ||
} | ||
} | ||
} |