### Question:
DriverRepository implements DriverFactory { @Override public <T> DrainDriver<T> createDrain(ProcessScript<T> script) throws IOException { if (script == null) { throw new IllegalArgumentException("script must not be null"); } String name = script.getDrainScript().getResourceName(); ResourceMirror resource = resources.get(name); if (resource == null) { WGLOG.error("E04001", script.getName(), name); throw new IOException(MessageFormat.format( "Resource \"{0}\" is not defined (drain of \"{1}\")", name, script.getName())); } return resource.createDrain(script); } DriverRepository(Iterable<? extends ResourceMirror> resources); @Override SourceDriver<T> createSource(ProcessScript<T> script); @Override DrainDriver<T> createDrain(ProcessScript<T> script);  }### Answer:
@Test public void testCreateDrain() throws Exception { DriverRepository repo = new DriverRepository(Arrays.asList(new MockResourceMirror("test2"))); ProcessScript<String> script = new ProcessScript<>( "testing", "simple", String.class, driver("test1"), driver("test2")); DrainDriver<String> source = repo.createDrain(script); assertThat(source, is(instanceOf(MockDrainDriver.class))); MockDrainDriver<String> mock = (MockDrainDriver<String>) source; assertThat(mock.name, is("test2")); }
@Test(expected = IOException.class) public void createDrain_missing() throws Exception { DriverRepository repo = new DriverRepository(Arrays.asList(new MockResourceMirror("test"))); ProcessScript<String> script = new ProcessScript<>( "testing", "simple", String.class, driver("test"), driver("MISSING")); repo.createDrain(script); }