SourceService implements ISourceService { @Override public Source createSource(String url, String username, String password, Integer maxDownloads) { IllegalArgumentException exception = new IllegalArgumentException("Invalid URL"); if (url == null || url.isEmpty()) { throw exception; } try { URL checkUrl = new URL(url); if (!checkUrl.getProtocol().startsWith("http")) { throw exception; } } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL"); } return getSourceManager().create(url, username, password, maxDownloads); }  @Override int count(); @Override Source createSource(String url, String username, String password, Integer maxDownloads); @Override Source getSource(int sourceId); @Override Source getSource(SynchronizerSource synchronizerSource); @Override List<Source> getSource(List<SynchronizerSource> synchronizerSources); @Override boolean updateSource(Source source); @Override boolean deleteSource(Source source); @Override List<Source> list(); @Override List<Source> sortSources(List<Source> sources); @Override Source getBestSource(List<Source> sources);  }
@Test(dependsOnMethods = {"get"}) public void createSource() { String expectedUrl = "https: String expectedUsername = "login-username"; String expectedPassword = "login-password"; Source source = service.createSource(expectedUrl, expectedUsername, expectedPassword, null); Assert.assertNotNull(source); Assert.assertTrue(source.getId() > 3); Assert.assertEquals(source.getUrl(), expectedUrl); Assert.assertEquals(source.getUsername(), expectedUsername); Assert.assertEquals(source.getPassword(), expectedPassword); Assert.assertEquals(source.getBandwidth(), -1L); }
@Test(expectedExceptions = {IllegalArgumentException.class}) public void createSourceNullUrlArg() { String expectedUrl = null; service.createSource(expectedUrl, null, null, null); }
@Test(expectedExceptions = {IllegalArgumentException.class}) public void createSourceInvalidUrlArg() { String expectedUrl = "ftp: service.createSource(expectedUrl, null, null, null); }