PlcDriverManager { public PlcConnection getConnection(String url) throws PlcConnectionException { PlcDriver driver = getDriver(url); PlcConnection connection = driver.getConnection(url); connection.connect(); return connection; } PlcDriverManager();  PlcDriverManager(ClassLoader classLoader); PlcConnection getConnection(String url); PlcConnection getConnection(String url, PlcAuthentication authentication); @Experimental PlcDriver getDriver(String url);  }
@Test public void getExistingDriverTest() throws PlcException { MockPlcConnection mockConnection = (MockPlcConnection) new PlcDriverManager().getConnection("api-mock: assertThat(mockConnection.getAuthentication(), nullValue()); assertThat(mockConnection.isConnected(), is(true)); }
@Test public void getExistingDriverWithAuthenticationTest() throws PlcException { PlcUsernamePasswordAuthentication authentication = new PlcUsernamePasswordAuthentication("user", "pass"); MockPlcConnection mockConnection = (MockPlcConnection) new PlcDriverManager().getConnection("api-mock: assertThat(mockConnection.getAuthentication(), notNullValue()); assertThat(mockConnection.getAuthentication(), instanceOf(PlcUsernamePasswordAuthentication.class)); assertThat(mockConnection.isConnected(), is(true)); }
@Test public void getNotExistingDriverTest() { assertThrows(PlcConnectionException.class, () -> new PlcDriverManager().getConnection("non-existing-protocol: }
@Test public void getInvalidUriTest() throws PlcConnectionException { assertThrows(PlcConnectionException.class, () -> new PlcDriverManager().getConnection("The quick brown fox jumps over the lazy dog")); }
@Test public void getDuplicateDriver() throws MalformedURLException { ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader(); URL[] urls = new URL[1]; urls[0] = new File("src/test/resources/test").toURI().toURL(); ClassLoader fakeClassLoader = new URLClassLoader(urls, originalClassloader); assertThrows(IllegalStateException.class, () -> new PlcDriverManager(fakeClassLoader).getConnection("api-mock: }