SyslogHosts implements Hosts { @Override public Host find(final String domain) throws IOException { return new SyslogHost(this.hosts.find(domain)); } SyslogHosts(final Hosts hsts); @Override void close(); @Override Host find(final String domain); @Override Set<Domain> domains(final User user);  }
@Test public void sendsMessagesToServer() throws Exception { final SyslogServerIF server = SyslogServer.getInstance("udp"); final int port = port(); server.getConfig().setPort(port); final BlockingQueue<String> messages = new LinkedBlockingQueue<String>(); server.getConfig().addEventHandler( new SyslogServerEventHandlerIF() { private static final long serialVersionUID = -7043255643054178133L; @Override public void event(final SyslogServerIF syslg, final SyslogServerEventIF event) { messages.add(event.getMessage()); } } ); final ExecutorService exec = Executors.newSingleThreadExecutor(); try { exec.execute(server); final Hosts hosts = Mockito.mock(Hosts.class); final String path = "/path/to/fetch"; final Host host = new HostMocker() .withContent(URI.create(path), "blah") .withSyslog(String.format("localhost:%d", port)) .mock(); Mockito.doReturn(host).when(hosts) .find(Mockito.anyString()); ResourceMocker.toByteArray( new SyslogHosts(hosts).find("dummy") .fetch(URI.create(path), Range.ENTIRE, Version.LATEST) ); MatcherAssert.assertThat( messages.poll(1, TimeUnit.MINUTES), Matchers.containsString(String.format("from %s", path)) ); } finally { server.shutdown(); exec.shutdown(); } }