Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface Service {
- }
- @FactoryEntry(key = "one")
- public class ServiceImplOne implements Service {
- }
- @FactoryEntry(key = "two")
- public class ServiceImplTwo implements Service {
- }
- @FactoryEntry(key = "one", factoryName = "customFactory")
- public class CustomServiceImplOne implements Service {
- }
- @FactoryEntry(key = "two", factoryName = "customFactory")
- public class CustomServiceImplTwo implements Service {
- }
- public class GenericFactory<T> {
- private Map<String, T> map;
- public GenericFactory(Map<String, T> map) {
- this.map = map;
- }
- public T get(String key){
- return map.get(key);
- }
- }
- @RunWith(WeldJUnit4Runner.class)
- public class BeanSampleFactoryTest {
- @Inject
- @Factory
- private GenericFactory<Service> factory;
- @Inject
- @Factory(factoryName = "customFactory")
- private GenericFactory<Service> customFactory;
- @Test
- public void testCreate() throws Exception {
- assertNotNull(factory);
- assertNotNull(factory.get("one"));
- assertNotNull(factory.get("two"));
- assertNotNull(customFactory);
- assertNotNull(customFactory.get("one"));
- assertNotNull(customFactory.get("two"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement