FileUtil { public String getDefaultSortOrderXml() throws IOException { CheckedSupplier<InputStream, IOException> createStreamFunc = () -> { if (customSortOrderFile != null) { UrlWrapper urlWrapper = new UrlWrapper(customSortOrderFile); if (urlWrapper.isUrl()) { return urlWrapper.openStream(); } else { return openCustomSortOrderFile(); } } else if (predefinedSortOrder != null) { return getPredefinedSortOrder(predefinedSortOrder); } return getPredefinedSortOrder(DEFAULT_SORT_ORDER_FILENAME); }; try (InputStream inputStream = createStreamFunc.get()) { return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } }  void setup(PluginParameters parameters); void backupFile(); String getPomFileContent(); void saveViolationFile(String violationXml); void savePomFile(String sortedXml); String getDefaultSortOrderXml();  }
@Test void defaultSortOrderFromFileShouldWork() throws Exception { FileUtil fileUtil = createFileUtil("Attribute_expected.xml"); String defaultSortOrderXml = fileUtil.getDefaultSortOrderXml(); assertThat(defaultSortOrderXml, startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<projec")); }
@Test void defaultSortOrderFromUrlShouldWork() throws IOException { FileUtil fileUtil = createFileUtil("https: try { String defaultSortOrderXml = fileUtil.getDefaultSortOrderXml(); assertThat(defaultSortOrderXml, containsString("Sverige")); } catch (UnknownHostException e) { } }
@Test void defaultSortOrderFromNonExistingPageShouldThrowException() throws IOException { FileUtil fileUtil = createFileUtil("https: try { fileUtil.getDefaultSortOrderXml(); fail(); } catch (UnknownHostException e) { } catch (FileNotFoundException e) { assertThat(e.getMessage(), is("https: } }