.findAny() .isPresent(); final boolean violatesLowerBound = getConcreteBounds(((MetaWildcardType) to).getLowerBounds()) .filter(bound -> !bound.isAssignableTo(fromMC)) .findAny()
.findAny() .isPresent(); final boolean violatesLowerBound = getConcreteBounds(((MetaWildcardType) to).getLowerBounds()) .filter(bound -> !bound.isAssignableTo(fromMC)) .findAny()
@Test public void testMethodReturnTypeWithUpperBoundedWildcardParameter() { final MetaClass c = getMetaClass(ClassWithGenericMethods.class); final MetaMethod method = c.getMethod("methodReturningUpperBoundedWildcardCollection", new Class[] {}); // TODO (ERRAI-459) decide whether it's correct to have the type param present or not // then adjust this assertion to strict equality rather than startsWith() assertTrue(method.getReturnType().getFullyQualifiedNameWithTypeParms().startsWith("java.util.Collection")); final MetaType genericReturnType = method.getGenericReturnType(); assertNotNull(genericReturnType); assertTrue("Got unexpected return type type " + genericReturnType.getClass(), genericReturnType instanceof MetaParameterizedType); final MetaParameterizedType mpReturnType = (MetaParameterizedType) genericReturnType; assertEquals(1, mpReturnType.getTypeParameters().length); // Sole type parameter should be <? extends String> assertTrue(mpReturnType.getTypeParameters()[0] instanceof MetaWildcardType); final MetaWildcardType typeParam = (MetaWildcardType) mpReturnType.getTypeParameters()[0]; assertArrayEquals(new MetaType[] {}, typeParam.getLowerBounds()); assertArrayEquals(new MetaType[] { getMetaClass(String.class) }, typeParam.getUpperBounds()); }
@Test public void testMethodReturnTypeWithWildcardParameter() { final MetaClass c = getMetaClass(ClassWithGenericMethods.class); final MetaMethod method = c.getMethod("methodReturningUnboundedWildcardCollection", new Class[] {}); // TODO (ERRAI-459) decide whether it's correct to have the type param present or not // then adjust this assertion to strict equality rather than startsWith() assertTrue(method.getReturnType().getFullyQualifiedNameWithTypeParms().startsWith("java.util.Collection")); final MetaType genericReturnType = method.getGenericReturnType(); assertNotNull(genericReturnType); assertTrue("Got unexpected return type type " + genericReturnType.getClass(), genericReturnType instanceof MetaParameterizedType); final MetaParameterizedType mpReturnType = (MetaParameterizedType) genericReturnType; assertEquals(1, mpReturnType.getTypeParameters().length); // Sole type parameter should be <?> assertTrue(mpReturnType.getTypeParameters()[0] instanceof MetaWildcardType); final MetaWildcardType typeParam = (MetaWildcardType) mpReturnType.getTypeParameters()[0]; assertArrayEquals(new MetaType[] {}, typeParam.getLowerBounds()); assertArrayEquals(new MetaType[] { getMetaClass(Object.class) }, typeParam.getUpperBounds()); }
@Test public void testFieldWithStringBoundedWildcardTypeParam() throws Exception { final MetaClass metaClass = getMetaClass(ClassWithGenericCollections.class); final MetaField field = metaClass.getDeclaredField("hasWildcardExtendsStringParam"); assertNotNull(field); assertEquals("Collection", field.getType().getName()); assertEquals("java.util.Collection", field.getType().getFullyQualifiedName()); assertEquals("<? extends java.lang.String>", field.getType().getParameterizedType().toString()); assertEquals("java.util.Collection<? extends java.lang.String>", field.getType().getFullyQualifiedNameWithTypeParms()); assertEquals("java.util.Collection", field.getType().getErased().getFullyQualifiedNameWithTypeParms()); assertEquals(1, field.getType().getParameterizedType().getTypeParameters().length); final MetaWildcardType typeParam = (MetaWildcardType) field.getType().getParameterizedType().getTypeParameters()[0]; assertEquals("Should have no lower bound", Arrays.asList(), Arrays.asList(typeParam.getLowerBounds())); assertEquals("Upper bound should be java.lang.String", Arrays.asList(getMetaClass(String.class)), Arrays.asList(typeParam.getUpperBounds())); }
@Test public void testMethodReturnTypeWithLowerBoundedWildcardParameter() { final MetaClass c = getMetaClass(ClassWithGenericMethods.class); final MetaMethod method = c.getMethod("methodReturningLowerBoundedWildcardCollection", new Class[] {}); // TODO (ERRAI-459) decide whether it's correct to have the type param present or not // then adjust this assertion to strict equality rather than startsWith() assertTrue(method.getReturnType().getFullyQualifiedNameWithTypeParms().startsWith("java.util.Collection")); final MetaType genericReturnType = method.getGenericReturnType(); assertNotNull(genericReturnType); assertTrue("Got unexpected return type type " + genericReturnType.getClass(), genericReturnType instanceof MetaParameterizedType); final MetaParameterizedType mpReturnType = (MetaParameterizedType) genericReturnType; assertEquals(1, mpReturnType.getTypeParameters().length); // Sole type parameter should be <? extends String> assertTrue(mpReturnType.getTypeParameters()[0] instanceof MetaWildcardType); final MetaWildcardType typeParam = (MetaWildcardType) mpReturnType.getTypeParameters()[0]; assertArrayEquals(new MetaType[] { getMetaClass(String.class) }, typeParam.getLowerBounds()); assertArrayEquals(new MetaType[] { getMetaClass(Object.class)}, typeParam.getUpperBounds()); }