You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by gp...@apache.org on 2014/02/03 11:02:32 UTC
svn commit: r1563815 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
test/java/org/apache/webbeans/test/instance/InstanceIteratorTest.java
Author: gpetracek
Date: Mon Feb 3 10:02:31 2014
New Revision: 1563815
URL: http://svn.apache.org/r1563815
Log:
OWB-929 InstanceImpl#iterator fixed
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceIteratorTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1563815&r1=1563814&r2=1563815&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java Mon Feb 3 10:02:31 2014
@@ -24,8 +24,10 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
@@ -259,7 +261,7 @@ public class InstanceImpl<T> implements
public Iterator<T> iterator()
{
Set<Bean<?>> beans = resolveBeans();
- Set<T> instances = new HashSet<T>();
+ List<T> instances = new ArrayList<T>();
parentCreationalContext.putInjectionPoint(injectionPoint);
try
{
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceIteratorTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceIteratorTest.java?rev=1563815&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceIteratorTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceIteratorTest.java Mon Feb 3 10:02:31 2014
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.test.instance;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Qualifier;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+public class InstanceIteratorTest extends AbstractUnitTest
+{
+ @Test
+ public void testInstanceIteratorWithBeanSelector() {
+ startContainer(
+ Qualifier1.class,
+ Qualifier2.class,
+ ShardContract.class,
+ Bean1.class,
+ Bean2.class,
+ BeanSelector.class,
+ InstanceHolder.class);
+
+ InstanceHolder instanceHolder = getInstance(InstanceHolder.class);
+ assertNotNull(instanceHolder);
+
+ Instance<ShardContract> instance = instanceHolder.getInstance();
+
+ int count = 0;
+
+ for (ShardContract ignored : instance)
+ {
+ count++;
+ }
+ assertEquals(3, count); //contextual instances: Bean1, Bean2, 2nd instance of Bean1 exposed by the producer
+ }
+
+ public static class InstanceHolder
+ {
+ @Inject
+ @Any
+ private Instance<ShardContract> instance;
+
+
+ public Instance<ShardContract> getInstance()
+ {
+ return instance;
+ }
+ }
+
+ @Target({TYPE, METHOD, PARAMETER})
+ @Retention(RUNTIME)
+ @Qualifier
+ public @interface Qualifier1
+ {
+ }
+
+ @Target({TYPE, METHOD, PARAMETER})
+ @Retention(RUNTIME)
+ @Qualifier
+ public @interface Qualifier2
+ {
+ }
+
+ public interface ShardContract
+ {
+ }
+
+ @ApplicationScoped
+ @Qualifier1
+ public static class Bean1 implements ShardContract
+ {
+ }
+
+ @ApplicationScoped
+ @Qualifier2
+ public static class Bean2 implements ShardContract
+ {
+ }
+
+ public static class BeanSelector
+ {
+ @Produces
+ protected ShardContract selectBean(@Qualifier1 ShardContract bean)
+ {
+ return bean; //usually there are different beans -> one gets selected, however, it isn't needed for the test
+ }
+ }
+}