You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2017/08/16 14:50:03 UTC
svn commit: r1805205 -
/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/CustomProviderTest.java
Author: struberg
Date: Wed Aug 16 14:50:03 2017
New Revision: 1805205
URL: http://svn.apache.org/viewvc?rev=1805205&view=rev
Log:
OWB-1210 add missing test
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/CustomProviderTest.java (with props)
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/CustomProviderTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/CustomProviderTest.java?rev=1805205&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/CustomProviderTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/CustomProviderTest.java Wed Aug 16 14:50:03 2017
@@ -0,0 +1,107 @@
+/*
+ * 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 javax.annotation.Priority;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Qualifier;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This test checks whether it is possible to add an own alternative implementation for
+ * a Provider<X> without interfering with Instance<X>
+ */
+public class CustomProviderTest extends AbstractUnitTest
+{
+
+ private @Inject String defaultString;
+
+ private @Inject Instance<String> defaultStringInstance;
+ private @Inject @MyQualifier Instance<String> qualifiedStringInstance;
+
+ private @Inject Provider<String> defaultStringProvider;
+ private @Inject @MyQualifier Provider<String> qualifiedStringProvider;
+
+
+ @Test
+ public void testProviderOverwrite()
+ {
+ startContainerInnerClasses();
+
+ Assert.assertNotNull(defaultString);
+ Assert.assertNotNull(defaultStringInstance);
+ Assert.assertNotNull(qualifiedStringInstance);
+ Assert.assertNotNull(defaultStringProvider);
+ Assert.assertNotNull(qualifiedStringProvider);
+
+ Assert.assertFalse(qualifiedStringInstance.isResolvable());
+ Assert.assertEquals("qualifiedString", qualifiedStringProvider.get());
+
+ Assert.assertEquals("defaultString", defaultString);
+ Assert.assertEquals("defaultString", defaultStringInstance.get());
+ Assert.assertEquals("defaultString", defaultStringProvider.get());
+
+ }
+
+ @Qualifier
+ @Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD})
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface MyQualifier
+ {
+
+ }
+
+ @Alternative
+ @Priority(1000)
+ public static class StringProviderProducer
+ {
+ @Produces
+ @Dependent
+ @MyQualifier
+ public Provider<String> myString()
+ {
+ return () -> "qualifiedString";
+ }
+ }
+
+ public static class DefaultStringProducer
+ {
+ @Produces
+ @Dependent
+ public String myString()
+ {
+ return "defaultString";
+ }
+ }
+
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/CustomProviderTest.java
------------------------------------------------------------------------------
svn:eol-style = native