Skip to content

Commit

Permalink
Relax the scope requirement for public fields
Browse files Browse the repository at this point in the history
This is a TCK counterpart to the specification change that allows all
pseudo-scoped beans to have public fields. It updates the text
in `tck-audit-cdi.xml` files, fixes naming in the relevant tests
and adds a test that a `@Singleton` bean can have a public field.
  • Loading branch information
Ladicek committed Nov 8, 2023
1 parent 8101d2e commit 986e0d0
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,10 @@ public void testDependentScopedBeanCanHaveNonStaticPublicField() throws Exceptio
Assert.assertEquals(getContextualReference(Tiger.class).name, "pete");
}

@Test
@SpecAssertion(section = MANAGED_BEANS, id = "fa")
public void testSingletonScopedBeanCanHaveNonStaticPublicField() throws Exception {
Assert.assertEquals(getContextualReference(SnowTiger.class).name, "martin");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jboss.cdi.tck.tests.implementation.simple.definition;

import jakarta.inject.Singleton;

@White
@Singleton
public class SnowTiger {

public String name = "martin";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jboss.cdi.tck.tests.implementation.simple.definition;

import jakarta.enterprise.inject.Stereotype;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Stereotype
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface White {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.implementation.simple.definition.dependentWithPublicField;
package org.jboss.cdi.tck.tests.implementation.simple.definition.normalScopedWithPublicField;

import jakarta.enterprise.context.RequestScoped;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.implementation.simple.definition.dependentWithPublicField;
package org.jboss.cdi.tck.tests.implementation.simple.definition.normalScopedWithPublicField;

import static org.jboss.cdi.tck.cdi.Sections.EXCEPTIONS;
import static org.jboss.cdi.tck.cdi.Sections.MANAGED_BEANS;
Expand All @@ -32,17 +32,17 @@
import org.testng.annotations.Test;

@SpecVersion(spec = "cdi", version = "2.0")
public class DependentWithPublicFieldTest extends AbstractTest {
public class NormalScopedWithPublicFieldTest extends AbstractTest {

@ShouldThrowException(DefinitionException.class)
@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder().withTestClassPackage(DependentWithPublicFieldTest.class).build();
return new WebArchiveBuilder().withTestClassPackage(NormalScopedWithPublicFieldTest.class).build();
}

@Test
@SpecAssertions({ @SpecAssertion(section = MANAGED_BEANS, id = "fc"), @SpecAssertion(section = EXCEPTIONS, id = "ba") })
public void testNonDependentScopedBeanCanNotHavePublicField() {
public void testNormalScopedBeanCanNotHavePublicField() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.implementation.simple.definition.nonDependentWithPublicStaticField;
package org.jboss.cdi.tck.tests.implementation.simple.definition.normalScopedWithPublicStaticField;

import jakarta.enterprise.context.RequestScoped;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.implementation.simple.definition.nonDependentWithPublicStaticField;
package org.jboss.cdi.tck.tests.implementation.simple.definition.normalScopedWithPublicStaticField;

import static org.jboss.cdi.tck.cdi.Sections.MANAGED_BEANS;
import static org.testng.Assert.assertEquals;
Expand All @@ -29,16 +29,16 @@
import org.testng.annotations.Test;

@SpecVersion(spec = "cdi", version = "2.0")
public class NonDependentWithPublicStaticFieldTest extends AbstractTest {
public class NormalScopedWithPublicStaticFieldTest extends AbstractTest {

@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder().withTestClassPackage(NonDependentWithPublicStaticFieldTest.class).build();
return new WebArchiveBuilder().withTestClassPackage(NormalScopedWithPublicStaticFieldTest.class).build();
}

@Test
@SpecAssertions({ @SpecAssertion(section = MANAGED_BEANS, id = "fb") })
public void testNonDependentScopedBeanCanHavePublicStaticField() {
public void testNormalScopedBeanCanHavePublicStaticField() {
assertEquals(Leopard.NAME, "john");
}

Expand Down
12 changes: 5 additions & 7 deletions impl/src/main/resources/tck-audit-cdi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -851,19 +851,17 @@
</assertion>

<group>
<text>If a managed bean has a non-static public field, it must have scope |@Dependent|. If a managed bean with a non-static public field declares
any scope other than |@Dependent|, the container automatically detects the problem and treats it as a definition error.
<text>If a managed bean has a non-static public field, its scope must be a pseudo-scope.
If a managed bean with a non-static public field declares a normal scope, the container automatically detects the problem and treats it as a definition error.
</text>
<assertion id="fa">
<text>Check a dependent scoped bean with a public field.</text>
<text>Check a pseudo-scoped bean with a public field.</text>
</assertion>
<assertion id="fb">
<text>Check a managed bean with a static public field which declares any scope other than |@Dependent|.</text>
<text>Check a managed bean with a static public field which declares a normal scope.</text>
</assertion>
<assertion id="fc">
<text>If a managed bean with a non-static public field declares any scope other than |@Dependent|, the container automatically detects the
problem and treats it as a definition error.
</text>
<text>Check a managed bean with a non-static public field which declares a normal scope.</text>
</assertion>
</group>

Expand Down
12 changes: 5 additions & 7 deletions web/src/main/resources/tck-audit-cdi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -837,19 +837,17 @@
</assertion>

<group>
<text>If a managed bean has a non-static public field, it must have scope |@Dependent|. If a managed bean with a non-static public field declares
any scope other than |@Dependent|, the container automatically detects the problem and treats it as a definition error.
<text>If a managed bean has a non-static public field, its scope must be a pseudo-scope.
If a managed bean with a non-static public field declares a normal scope, the container automatically detects the problem and treats it as a definition error.
</text>
<assertion id="fa">
<text>Check a dependent scoped bean with a public field.</text>
<text>Check a pseudo-scoped bean with a public field.</text>
</assertion>
<assertion id="fb">
<text>Check a managed bean with a static public field which declares any scope other than |@Dependent|.</text>
<text>Check a managed bean with a static public field which declares a normal scope.</text>
</assertion>
<assertion id="fc">
<text>If a managed bean with a non-static public field declares any scope other than |@Dependent|, the container automatically detects the
problem and treats it as a definition error.
</text>
<text>Check a managed bean with a non-static public field which declares a normal scope.</text>
</assertion>
</group>

Expand Down

0 comments on commit 986e0d0

Please sign in to comment.