-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arc - support static producer methods.
- Loading branch information
Showing
2 changed files
with
60 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
51 changes: 51 additions & 0 deletions
51
...sts/src/test/java/io/quarkus/arc/test/producer/staticMethod/StaticMethodProducerTest.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,51 @@ | ||
package io.quarkus.arc.test.producer.staticMethod; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Singleton; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
/** | ||
* Tests static method producers | ||
*/ | ||
public class StaticMethodProducerTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(StaticMethodProducerTest.class, SomeProducer.class); | ||
|
||
@Test | ||
public void testStaticProducer() { | ||
InstanceHandle<String> stringInstance = Arc.container().instance(String.class); | ||
Assertions.assertTrue(stringInstance.isAvailable()); | ||
Assertions.assertEquals("foo", stringInstance.get()); | ||
InstanceHandle<Long> longInstance = Arc.container().instance(Long.class); | ||
Assertions.assertTrue(longInstance.isAvailable()); | ||
Assertions.assertEquals(2L, longInstance.get()); | ||
InstanceHandle<Double> instance = Arc.container().instance(Double.class); | ||
Assertions.assertTrue(instance.isAvailable()); | ||
Assertions.assertEquals(2.1, instance.get()); | ||
} | ||
|
||
@Singleton | ||
static class SomeProducer { | ||
|
||
@Produces | ||
private static Long produceLong() { | ||
return 2L; | ||
} | ||
|
||
@Produces | ||
static String produceString() { | ||
return "foo"; | ||
} | ||
|
||
@Produces | ||
public static Double produceDouble() { | ||
return 2.1; | ||
} | ||
} | ||
} |