forked from quarkusio/quarkus
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Funqy - fix constructor injection for normal scoped beans
fixes: quarkusio#27671
- Loading branch information
1 parent
da3036e
commit e9926a2
Showing
3 changed files
with
138 additions
and
0 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
127 changes: 127 additions & 0 deletions
127
...-common/deployment/src/test/java/io/quarkus/funqy/deployment/DependencyInjectionTest.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,127 @@ | ||
package io.quarkus.funqy.deployment; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.funqy.Funq; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DependencyInjectionTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot( | ||
(jar) -> jar.addClasses(GreetingFunction.class, GreetingService.class, FarewellFunction.class, | ||
HiFunction.class, ByeFunction.class)); | ||
|
||
@Inject | ||
GreetingFunction greetingFunction; | ||
|
||
@Inject | ||
FarewellFunction farewellFunction; | ||
|
||
@Inject | ||
ByeFunction byeFunction; | ||
|
||
@Inject | ||
HiFunction hiFunction; | ||
|
||
@Test | ||
public void testFieldInjection() { | ||
// bean with a pseudo-scope | ||
Assertions.assertEquals("Hello World!", greetingFunction.greeting()); | ||
// normal scoped bean | ||
Assertions.assertEquals("Bye!", byeFunction.bye()); | ||
} | ||
|
||
@Test | ||
public void testConstructorInjection() { | ||
// bean with a pseudo-scope | ||
Assertions.assertEquals("Goodbye!", farewellFunction.farewell()); | ||
// normal scoped bean | ||
Assertions.assertEquals("Hi!", hiFunction.hi()); | ||
} | ||
|
||
public static class GreetingFunction { | ||
|
||
@Inject | ||
GreetingService greetingService; | ||
|
||
@Funq | ||
String greeting() { | ||
return greetingService.sayHello(); | ||
} | ||
|
||
} | ||
|
||
public static class FarewellFunction { | ||
|
||
private final GreetingService greetingService; | ||
|
||
public FarewellFunction(GreetingService greetingService) { | ||
this.greetingService = greetingService; | ||
} | ||
|
||
@Funq | ||
String farewell() { | ||
return greetingService.sayGoodbye(); | ||
} | ||
|
||
} | ||
|
||
@ApplicationScoped | ||
public static class ByeFunction { | ||
|
||
@Inject | ||
GreetingService greetingService; | ||
|
||
@Funq | ||
String bye() { | ||
return greetingService.sayBye(); | ||
} | ||
|
||
} | ||
|
||
@ApplicationScoped | ||
public static class HiFunction { | ||
|
||
private final GreetingService greetingService; | ||
|
||
public HiFunction(GreetingService greetingService) { | ||
this.greetingService = greetingService; | ||
} | ||
|
||
@Funq | ||
String hi() { | ||
return greetingService.sayHi(); | ||
} | ||
|
||
} | ||
|
||
@Singleton | ||
public static class GreetingService { | ||
|
||
public String sayHello() { | ||
return "Hello World!"; | ||
} | ||
|
||
public String sayGoodbye() { | ||
return "Goodbye!"; | ||
} | ||
|
||
public String sayHi() { | ||
return "Hi!"; | ||
} | ||
|
||
public String sayBye() { | ||
return "Bye!"; | ||
} | ||
|
||
} | ||
|
||
} |