@Test public void illegalArgumentWhenMissingModule() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("NoModuleProvider should have a static inner class named Module"); Providers.instantiateModule(new NoModuleProvider()); }
public static Object instantiateModule(Provider in) throws IllegalArgumentException { String moduleClassName; if (in.getClass().isAnonymousClass()) { moduleClassName = in.getClass().getSuperclass().getName() + "$Module"; } else { moduleClassName = in.getClass().getName() + "$Module"; } Class<?> moduleClass; try { moduleClass = Class.forName(moduleClassName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(in.getClass().getName() + " should have a static inner class named Module", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } try { Constructor<?> ctor = moduleClass.getDeclaredConstructor(); ctor.setAccessible(true); return ctor.newInstance(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("ensure " + moduleClassName + " has a no-args constructor", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } }
Providers { public static Object instantiateModule(Provider in) throws IllegalArgumentException { String moduleClassName; if (in.getClass().isAnonymousClass()) { moduleClassName = in.getClass().getSuperclass().getName() + "$Module"; } else { moduleClassName = in.getClass().getName() + "$Module"; } Class<?> moduleClass; try { moduleClass = Class.forName(moduleClassName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(in.getClass().getName() + " should have a static inner class named Module", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } try { Constructor<?> ctor = moduleClass.getDeclaredConstructor(); ctor.setAccessible(true); return ctor.newInstance(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("ensure " + moduleClassName + " has a no-args constructor", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } } }
Providers { public static Object instantiateModule(Provider in) throws IllegalArgumentException { String moduleClassName; if (in.getClass().isAnonymousClass()) { moduleClassName = in.getClass().getSuperclass().getName() + "$Module"; } else { moduleClassName = in.getClass().getName() + "$Module"; } Class<?> moduleClass; try { moduleClass = Class.forName(moduleClassName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(in.getClass().getName() + " should have a static inner class named Module", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } try { Constructor<?> ctor = moduleClass.getDeclaredConstructor(); ctor.setAccessible(true); return ctor.newInstance(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("ensure " + moduleClassName + " has a no-args constructor", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } }  }
Providers { public static Object instantiateModule(Provider in) throws IllegalArgumentException { String moduleClassName; if (in.getClass().isAnonymousClass()) { moduleClassName = in.getClass().getSuperclass().getName() + "$Module"; } else { moduleClassName = in.getClass().getName() + "$Module"; } Class<?> moduleClass; try { moduleClass = Class.forName(moduleClassName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(in.getClass().getName() + " should have a static inner class named Module", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } try { Constructor<?> ctor = moduleClass.getDeclaredConstructor(); ctor.setAccessible(true); return ctor.newInstance(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("ensure " + moduleClassName + " has a no-args constructor", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } }  static Iterable<Provider> list(); static Provider getByName(String providerName); static Provider withUrl(Provider provider, String url); static Object instantiateModule(Provider in); static Object provide(denominator.Provider provider); }
Providers { public static Object instantiateModule(Provider in) throws IllegalArgumentException { String moduleClassName; if (in.getClass().isAnonymousClass()) { moduleClassName = in.getClass().getSuperclass().getName() + "$Module"; } else { moduleClassName = in.getClass().getName() + "$Module"; } Class<?> moduleClass; try { moduleClass = Class.forName(moduleClassName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(in.getClass().getName() + " should have a static inner class named Module", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } try { Constructor<?> ctor = moduleClass.getDeclaredConstructor(); ctor.setAccessible(true); return ctor.newInstance(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("ensure " + moduleClassName + " has a no-args constructor", e); } catch (Exception e) { throw new IllegalArgumentException("exception attempting to instantiate " + moduleClassName + " for provider " + in.name(), e); } }  static Iterable<Provider> list(); static Provider getByName(String providerName); static Provider withUrl(Provider provider, String url); static Object instantiateModule(Provider in); static Object provide(denominator.Provider provider);  }