@Test void shouldThrowForUnknownRawParameterizedType() { Type type = createParameterizedType(createParameterizedType(Object.class), Object.class); ObjectIdentifier identifier = new ObjectIdentifier(null, type); InjectorException ex = assertThrows(InjectorException.class, () -> identifier.getTypeAsClass()); assertThat(ex.getMessage(), containsString("does not have a Class as its raw type")); }
public Class<?> getTypeAsClass() { if (type instanceof Class<?>) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { Type rawType = ((ParameterizedType) type).getRawType(); if (rawType instanceof Class<?>) { return (Class<?>) rawType; } else { throw new InjectorException("Parameterized type '" + type + "' does not have a Class as its raw type"); } } throw new InjectorException("Unknown type '" + type + "' (" + type.getClass() + ") cannot be converted to Class"); }
ObjectIdentifier { public Class<?> getTypeAsClass() { if (type instanceof Class<?>) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { Type rawType = ((ParameterizedType) type).getRawType(); if (rawType instanceof Class<?>) { return (Class<?>) rawType; } else { throw new InjectorException("Parameterized type '" + type + "' does not have a Class as its raw type"); } } throw new InjectorException("Unknown type '" + type + "' (" + type.getClass() + ") cannot be converted to Class"); } }
ObjectIdentifier { public Class<?> getTypeAsClass() { if (type instanceof Class<?>) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { Type rawType = ((ParameterizedType) type).getRawType(); if (rawType instanceof Class<?>) { return (Class<?>) rawType; } else { throw new InjectorException("Parameterized type '" + type + "' does not have a Class as its raw type"); } } throw new InjectorException("Unknown type '" + type + "' (" + type.getClass() + ") cannot be converted to Class"); } ObjectIdentifier(ResolutionType resolutionType, Type type, Annotation... annotations); }
ObjectIdentifier { public Class<?> getTypeAsClass() { if (type instanceof Class<?>) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { Type rawType = ((ParameterizedType) type).getRawType(); if (rawType instanceof Class<?>) { return (Class<?>) rawType; } else { throw new InjectorException("Parameterized type '" + type + "' does not have a Class as its raw type"); } } throw new InjectorException("Unknown type '" + type + "' (" + type.getClass() + ") cannot be converted to Class"); } ObjectIdentifier(ResolutionType resolutionType, Type type, Annotation... annotations); ResolutionType getResolutionType(); Type getType(); Class<?> getTypeAsClass(); List<Annotation> getAnnotations(); @Override String toString(); }
ObjectIdentifier { public Class<?> getTypeAsClass() { if (type instanceof Class<?>) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { Type rawType = ((ParameterizedType) type).getRawType(); if (rawType instanceof Class<?>) { return (Class<?>) rawType; } else { throw new InjectorException("Parameterized type '" + type + "' does not have a Class as its raw type"); } } throw new InjectorException("Unknown type '" + type + "' (" + type.getClass() + ") cannot be converted to Class"); } ObjectIdentifier(ResolutionType resolutionType, Type type, Annotation... annotations); ResolutionType getResolutionType(); Type getType(); Class<?> getTypeAsClass(); List<Annotation> getAnnotations(); @Override String toString();  }