@Test public void getMatcherShouldThrowOnBadType() throws Exception { GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(THROWING_FILE_SYSTEM)); GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(genericLoader); expectedException.expect(MessagingException.class); guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() .matcherName("org.apache.james.transport.mailets.Null") .mailetContext(FakeMailContext.defaultContext()) .build()); }
@Override public Matcher getMatcher(MatcherConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMatcherName()); Matcher result = genericLoader.<Matcher>withNamingSheme(MATCHER_NAMING_SCHEME) .instantiate(className); result.init(config); return result; } catch (Exception e) { throw new MessagingException("Can not load matcher " + config.getMatcherName(), e); } }
GuiceMatcherLoader implements MatcherLoader { @Override public Matcher getMatcher(MatcherConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMatcherName()); Matcher result = genericLoader.<Matcher>withNamingSheme(MATCHER_NAMING_SCHEME) .instantiate(className); result.init(config); return result; } catch (Exception e) { throw new MessagingException("Can not load matcher " + config.getMatcherName(), e); } } }
GuiceMatcherLoader implements MatcherLoader { @Override public Matcher getMatcher(MatcherConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMatcherName()); Matcher result = genericLoader.<Matcher>withNamingSheme(MATCHER_NAMING_SCHEME) .instantiate(className); result.init(config); return result; } catch (Exception e) { throw new MessagingException("Can not load matcher " + config.getMatcherName(), e); } } @Inject  GuiceMatcherLoader(GuiceGenericLoader genericLoader); }
GuiceMatcherLoader implements MatcherLoader { @Override public Matcher getMatcher(MatcherConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMatcherName()); Matcher result = genericLoader.<Matcher>withNamingSheme(MATCHER_NAMING_SCHEME) .instantiate(className); result.init(config); return result; } catch (Exception e) { throw new MessagingException("Can not load matcher " + config.getMatcherName(), e); } } @Inject  GuiceMatcherLoader(GuiceGenericLoader genericLoader); @Override Matcher getMatcher(MatcherConfig config); }
GuiceMatcherLoader implements MatcherLoader { @Override public Matcher getMatcher(MatcherConfig config) throws MessagingException { try { ClassName className = new ClassName(config.getMatcherName()); Matcher result = genericLoader.<Matcher>withNamingSheme(MATCHER_NAMING_SCHEME) .instantiate(className); result.init(config); return result; } catch (Exception e) { throw new MessagingException("Can not load matcher " + config.getMatcherName(), e); } } @Inject  GuiceMatcherLoader(GuiceGenericLoader genericLoader); @Override Matcher getMatcher(MatcherConfig config);  }