public <T extends Loser<AssertionError>> void testMethod_exceptionTypes() throws NoSuchMethodException { Method failMethod = Loser.class.getMethod("lose"); Invokable<T, ?> invokable = new TypeToken<T>(getClass()) {}.method(failMethod); assertThat(invokable.getExceptionTypes()).contains(TypeToken.of(AssertionError.class)); }
public <T extends CannotConstruct<AssertionError>> void testConstructor_exceptionTypes() throws NoSuchMethodException { @SuppressWarnings("rawtypes") // Reflection API skew Constructor<CannotConstruct> constructor = CannotConstruct.class.getConstructor(); Invokable<T, ?> invokable = new TypeToken<T>(getClass()) {}.constructor(constructor); assertThat(invokable.getExceptionTypes()).contains(TypeToken.of(AssertionError.class)); }
public void testInstanceMethod_exceptionTypes() throws Exception { Invokable<?, ?> delegate = Prepender.method("prepend", Iterable.class); assertEquals( ImmutableList.of( TypeToken.of(IllegalArgumentException.class), TypeToken.of(NullPointerException.class)), delegate.getExceptionTypes()); }
public void testConstructor_exceptionTypes() throws Exception { assertEquals( ImmutableList.of(TypeToken.of(NullPointerException.class)), Prepender.constructor(String.class, int.class).getExceptionTypes()); }
public void testStaticMethod_exceptionTypes() throws Exception { Invokable<?, ?> delegate = Prepender.method("prepend", String.class, Iterable.class); assertEquals(ImmutableList.of(), delegate.getExceptionTypes()); }
public static void putInvokables(Class<?> sync, Class<?> async, Cache<Invokable<?, ?>, Invokable<?, ?>> cache) { for (Invokable<?, ?> invoked : methods(sync)) { Invokable<?, ?> delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()) || isCloseable(delegatedMethod), "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod); cache.put(invoked, delegatedMethod); } }
public static void putInvokables(Class<?> sync, Class<?> async, Cache<Invokable<?, ?>, Invokable<?, ?>> cache) { for (Invokable<?, ?> invoked : methods(sync)) { Invokable<?, ?> delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()) || isCloseable(delegatedMethod), "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod); cache.put(invoked, delegatedMethod); } }
public static void putInvokables(Class<?> sync, Class<?> async, Cache<Invokable<?, ?>, Invokable<?, ?>> cache) { for (Invokable<?, ?> invoked : methods(sync)) { Invokable<?, ?> delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()) || isCloseable(delegatedMethod), "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod); cache.put(invoked, delegatedMethod); } }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
public GetterDescription(String propertyName, TypeToken<?> owningType, Method method) { super(propertyName, method, Visibility.PUBLIC, owningType.method(method).getReturnType(), owningType); this.invokable = owningType.method(method); this.exceptions = invokable.getExceptionTypes(); }
public <T extends Loser<AssertionError>> void testMethod_exceptionTypes() throws NoSuchMethodException { Method failMethod = Loser.class.getMethod("lose"); Invokable<T, ?> invokable = new TypeToken<T>(getClass()) {}.method(failMethod); assertThat(invokable.getExceptionTypes()).contains(TypeToken.of(AssertionError.class)); }
public <T extends CannotConstruct<AssertionError>> void testConstructor_exceptionTypes() throws NoSuchMethodException { @SuppressWarnings("rawtypes") // Reflection API skew Constructor<CannotConstruct> constructor = CannotConstruct.class.getConstructor(); Invokable<T, ?> invokable = new TypeToken<T>(getClass()) {}.constructor(constructor); assertThat(invokable.getExceptionTypes()).contains(TypeToken.of(AssertionError.class)); }
public void testInstanceMethod_exceptionTypes() throws Exception { Invokable<?, ?> delegate = Prepender.method("prepend", Iterable.class); assertEquals( ImmutableList.of( TypeToken.of(IllegalArgumentException.class), TypeToken.of(NullPointerException.class)), delegate.getExceptionTypes()); }
public void testConstructor_exceptionTypes() throws Exception { assertEquals(ImmutableList.of(TypeToken.of(NullPointerException.class)), Prepender.constructor(String.class, int.class).getExceptionTypes()); }
public void testStaticMethod_exceptionTypes() throws Exception { Invokable<?, ?> delegate = Prepender.method("prepend", String.class, Iterable.class); assertEquals(ImmutableList.of(), delegate.getExceptionTypes()); }