Permalink
Browse files

Part of CDITCK-414 - extend AssignabilityOfRawAndParameterizedTypesTest

Test BeanManager.getBeans() for retrieving generic beans with type variables with multiple bounds
  • Loading branch information...
1 parent 2248d0d commit 2e9a5fc20701467f28622039336933f2f6e7afa2 @bafco bafco committed with tremes Jun 5, 2014
Showing with 367 additions and 6 deletions.
  1. +107 −6 ...k/tests/lookup/typesafe/resolution/parameterized/AssignabilityOfRawAndParameterizedTypesTest.java
  2. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/Bar.java
  3. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/BarBazImpl.java
  4. +20 −0 ...ain/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/BarBazSuperFooImpl.java
  5. +20 −0 .../main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/BarSubBazFooImpl.java
  6. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/Baz.java
  7. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/Box.java
  8. +20 −0 .../main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/BoxBarBazFooImpl.java
  9. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/Foo.java
  10. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/SubBar.java
  11. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/SubBaz.java
  12. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/SuperBar.java
  13. +20 −0 ...n/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/SuperBarFooCloneable.java
  14. +20 −0 impl/src/main/java/org/jboss/cdi/tck/tests/lookup/typesafe/resolution/parameterized/SuperFoo.java
@@ -39,10 +39,19 @@
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;
+/**
+ *
+ * @author Martin Kouba
+ * @author Matus Abaffy
+ */
@SuppressWarnings("serial")
@SpecVersion(spec = "cdi", version = "1.1 Final Release")
public class AssignabilityOfRawAndParameterizedTypesTest extends AbstractTest {
+ private static final Class<?>[] RESULT_TYPES = new Class<?>[] { ResultImpl.class, Result.class, Object.class };
+ private static final Class<?>[] DAO_TYPES = new Class<?>[] { Dao.class, Object.class };
+ private static final Class<?>[] BOX_TYPES = new Class<?>[] { BoxBarBazFooImpl.class, Box.class, Object.class };
+
@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder().withTestClassPackage(AssignabilityOfRawAndParameterizedTypesTest.class).build();
@@ -88,7 +97,7 @@ public void testAssignabilityOfParameterizedTypeWithTypeVariablesToParameterized
Set<Bean<Result<? extends Throwable, ? super Exception>>> beans = getBeans(new TypeLiteral<Result<? extends Throwable, ? super Exception>>() {
});
assert beans.size() == 1;
- assert rawTypeSetMatches(beans.iterator().next().getTypes(), ResultImpl.class, Result.class, Object.class);
+ assert rawTypeSetMatches(beans.iterator().next().getTypes(), RESULT_TYPES);
}
@Test
@@ -98,15 +107,50 @@ public void testAssignabilityOfParameterizedTypeWithTypeVariablesToParameterized
Set<Bean<Result<? extends RuntimeException, ? super RuntimeException>>> beans = getBeans(new TypeLiteral<Result<? extends RuntimeException, ? super RuntimeException>>() {
});
assert beans.size() == 1;
- assert rawTypeSetMatches(beans.iterator().next().getTypes(), ResultImpl.class, Result.class, Object.class);
+ assert rawTypeSetMatches(beans.iterator().next().getTypes(), RESULT_TYPES);
}
@Test
@SpecAssertion(section = ASSIGNABLE_PARAMETERS, id = "dc")
- public void testAssignabilityOfParameterizedTypeWithTypeVariablesToParameterizedTypeWithWildcardsBroken() {
+ public <T1 extends SubBar & SubBaz & Foo,
+ T2 extends BarBazImpl & Foo,
+ T3 extends SubBar & SubBaz & SuperFoo,
+ T4 extends SubBar & SubBaz,
+ T5 extends BarBazSuperFooImpl,
+ T6 extends BarBazSuperFooImpl & SuperBarFooCloneable> void testAssignabilityOfParameterizedTypeWithTypeVariablesToParameterizedTypeWithWildcardWithLowerBound() {
Set<Bean<Result<? extends Exception, ? super Throwable>>> beans = getBeans(new TypeLiteral<Result<? extends Exception, ? super Throwable>>() {
});
assertEquals(beans.size(), 0);
+
+ Set<Bean<Box<? super T1>>> beans1 = getBeans(new TypeLiteral<Box<? super T1>>() {
+ });
+ assertEquals(beans1.size(), 1);
+ assertTrue(rawTypeSetMatches(beans1.iterator().next().getTypes(), BOX_TYPES));
+
+ Set<Bean<Box<? super T2>>> beans2 = getBeans(new TypeLiteral<Box<? super T2>>() {
+ });
+ assertEquals(beans2.size(), 1);
+ assertTrue(rawTypeSetMatches(beans2.iterator().next().getTypes(), BOX_TYPES));
+
+ // SuperFoo does not extend Foo
+ Set<Bean<Box<? super T3>>> noBeans3 = getBeans(new TypeLiteral<Box<? super T3>>() {
+ });
+ assertEquals(noBeans3.size(), 0);
+
+ // does not extend Foo
+ Set<Bean<Box<? super T4>>> noBeans4 = getBeans(new TypeLiteral<Box<? super T4>>() {
+ });
+ assertEquals(noBeans4.size(), 0);
+
+ // SuperFoo does not extend Foo
+ Set<Bean<Box<? super T5>>> noBeans5 = getBeans(new TypeLiteral<Box<? super T5>>() {
+ });
+ assertEquals(noBeans5.size(), 0);
+
+ Set<Bean<Box<? super T6>>> beans6 = getBeans(new TypeLiteral<Box<? super T6>>() {
+ });
+ assertEquals(beans6.size(), 1);
+ assertTrue(rawTypeSetMatches(beans6.iterator().next().getTypes(), BOX_TYPES));
}
@Test
@@ -115,20 +159,39 @@ public void testAssignabilityOfParameterizedTypeWithTypeVariablesToParameterized
Set<Bean<Result<RuntimeException, IllegalStateException>>> beans = getBeans(new TypeLiteral<Result<RuntimeException, IllegalStateException>>() {
});
assert beans.size() == 1;
- assert rawTypeSetMatches(beans.iterator().next().getTypes(), ResultImpl.class, Result.class, Object.class);
+ assert rawTypeSetMatches(beans.iterator().next().getTypes(), RESULT_TYPES);
Set<Bean<Result<RuntimeException, Throwable>>> noBeans = getBeans(new TypeLiteral<Result<RuntimeException, Throwable>>() {
});
assertEquals(noBeans.size(), 0);
}
@Test
+ @SpecAssertion(section = ASSIGNABLE_PARAMETERS, id = "e")
+ public void testAssignabilityOfParameterizedTypeWithTypeVariablesWithMultipleBoundsToParameterizedTypeWithActualTypes() {
+ Set<Bean<Box<BarSubBazFooImpl>>> beans = getBeans(new TypeLiteral<Box<BarSubBazFooImpl>>() {
+ });
+ assertEquals(beans.size(), 1);
+ assertTrue(rawTypeSetMatches(beans.iterator().next().getTypes(), BOX_TYPES));
+
+ // SuperFoo is not inside BoxBarBazFooImpl's bounds
+ Set<Bean<Box<BarBazSuperFooImpl>>> noBeans1 = getBeans(new TypeLiteral<Box<BarBazSuperFooImpl>>() {
+ });
+ assertEquals(noBeans1.size(), 0);
+
+ // BarBazImpl does not extend Baz, which is required by BoxBarBazFooImpl's bounds
+ Set<Bean<Box<BarBazImpl>>> noBeans2 = getBeans(new TypeLiteral<Box<BarBazImpl>>() {
+ });
+ assertEquals(noBeans2.size(), 0);
+ }
+
+ @Test
@SpecAssertion(section = ASSIGNABLE_PARAMETERS, id = "f")
public <T1 extends RuntimeException, T2 extends T1, T3> void testAssignabilityOfParameterizedTypeWithTypeVariablesToParameterizedTypeWithTypeVariable() {
Set<Bean<Result<T1, T2>>> beans = getBeans(new TypeLiteral<Result<T1, T2>>() {
});
assert beans.size() == 1;
- assert rawTypeSetMatches(beans.iterator().next().getTypes(), ResultImpl.class, Result.class, Object.class);
+ assert rawTypeSetMatches(beans.iterator().next().getTypes(), RESULT_TYPES);
Set<Bean<Result<T1, T3>>> noBeans = getBeans(new TypeLiteral<Result<T1, T3>>() {
});
@@ -137,7 +200,45 @@ public void testAssignabilityOfParameterizedTypeWithTypeVariablesToParameterized
Set<Bean<Dao<T1, T3>>> daoBeans = getBeans(new TypeLiteral<Dao<T1, T3>>() {
});
assertEquals(daoBeans.size(), 1);
- assertTrue(rawTypeSetMatches(daoBeans.iterator().next().getTypes(), Dao.class, Object.class));
+ assertTrue(rawTypeSetMatches(daoBeans.iterator().next().getTypes(), DAO_TYPES));
}
+ @Test
+ @SpecAssertion(section = ASSIGNABLE_PARAMETERS, id = "f")
+ public <T1 extends SubBar & SubBaz & Foo,
+ T2 extends BarBazImpl & Foo,
+ T3 extends SubBar & SubBaz & SuperFoo,
+ T4 extends SubBar & SubBaz,
+ T5 extends BarBazSuperFooImpl,
+ T6 extends BarBazSuperFooImpl & SuperBarFooCloneable> void testAssignabilityOfParameterizedTypeWithTypeVariableWithMultipleBoundsToParameterizedTypeWithTypeVariable() {
+ Set<Bean<Box<T1>>> beans1 = getBeans(new TypeLiteral<Box<T1>>() {
+ });
+ assertEquals(beans1.size(), 1);
+ assertTrue(rawTypeSetMatches(beans1.iterator().next().getTypes(), BOX_TYPES));
+
+ Set<Bean<Box<T2>>> beans2 = getBeans(new TypeLiteral<Box<T2>>() {
+ });
+ assertEquals(beans2.size(), 1);
+ assertTrue(rawTypeSetMatches(beans2.iterator().next().getTypes(), BOX_TYPES));
+
+ // SuperFoo does not extend Foo
+ Set<Bean<Box<T3>>> noBeans3 = getBeans(new TypeLiteral<Box<T3>>() {
+ });
+ assertEquals(noBeans3.size(), 0);
+
+ // does not extend Foo
+ Set<Bean<Box<T4>>> noBeans4 = getBeans(new TypeLiteral<Box<T4>>() {
+ });
+ assertEquals(noBeans4.size(), 0);
+
+ // SuperFoo does not extend Foo
+ Set<Bean<Box<T5>>> noBeans5 = getBeans(new TypeLiteral<Box<T5>>() {
+ });
+ assertEquals(noBeans5.size(), 0);
+
+ Set<Bean<Box<T6>>> beans6 = getBeans(new TypeLiteral<Box<T6>>() {
+ });
+ assertEquals(beans6.size(), 1);
+ assertTrue(rawTypeSetMatches(beans6.iterator().next().getTypes(), BOX_TYPES));
+ }
}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+interface Bar extends SuperBar {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+class BarBazImpl implements Bar, Baz {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+class BarBazSuperFooImpl implements Bar, Baz, SuperFoo {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+class BarSubBazFooImpl extends BarBazImpl implements SubBaz, Foo {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+interface Baz {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+interface Box<T> {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+class BoxBarBazFooImpl<T extends Bar & Baz & Foo> implements Box<T> {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+interface Foo extends SuperFoo {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+interface SubBar extends Bar {
+}
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2014, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized;
+
+interface SubBaz extends Baz {
+}
Oops, something went wrong.

0 comments on commit 2e9a5fc

Please sign in to comment.