RobotProjectConfigWriter { public String writeFragment(final Object modelPart) { try { final StringWriter writer = new StringWriter(512); writeConfiguration(modelPart, writer, ImmutableMap.of(Marshaller.JAXB_FORMATTED_OUTPUT, true, Marshaller.JAXB_FRAGMENT, true)); final ByteArrayInputStream stream = new ByteArrayInputStream( writer.toString().getBytes(StandardCharsets.UTF_8)); return CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8)); } catch (final IOException e) { throw new CannotWriteProjectConfigurationException( "Unable to write fragment of configuration for element of type '" + modelPart.getClass().getSimpleName() + "'", e); } }  InputStream writeConfiguration(final RobotProjectConfig configuration); String writeFragment(final Object modelPart);  }
@Test public void javaLibraryIsProperlyWrittenAsFragment() { final ReferencedLibrary library = ReferencedLibrary.create(LibraryType.JAVA, "java_lib", "path/to/lib"); final String fragment = new RobotProjectConfigWriter().writeFragment(library); assertThat(fragment).doesNotContain("<%xml") .contains("<referencedLibrary") .contains("type=\"JAVA\"") .contains("name=\"java_lib\"") .contains("path=\"path/to/lib\""); }
@Test public void virtualLibraryIsProperlyWrittenAsFragment() { final ReferencedLibrary library = ReferencedLibrary.create(LibraryType.VIRTUAL, "my_lib", "path/to/libspec.xml"); final String fragment = new RobotProjectConfigWriter().writeFragment(library); assertThat(fragment).doesNotContain("<%xml") .contains("<referencedLibrary") .contains("type=\"VIRTUAL\"") .contains("name=\"my_lib\"") .contains("path=\"path/to/libspec.xml\""); }
@Test public void pythonLibraryIsProperlyWrittenAsFragment() { final ReferencedLibrary library = ReferencedLibrary.create(LibraryType.PYTHON, "module.class", "path/to/lib/module.py"); final String fragment = new RobotProjectConfigWriter().writeFragment(library); assertThat(fragment).doesNotContain("<%xml") .contains("<referencedLibrary") .contains("type=\"PYTHON\"") .contains("name=\"module.class\"") .contains("path=\"path/to/lib/module.py\""); }
@Test public void libraryIsProperlyWrittenAsFragment_withNonAsciiCharacters() { final ReferencedLibrary library = ReferencedLibrary.create(LibraryType.PYTHON, "module.ąęółżźćń", "path/ą/ę/module.py"); final String fragment = new RobotProjectConfigWriter().writeFragment(library); assertThat(fragment).doesNotContain("<%xml") .contains("<referencedLibrary") .contains("type=\"PYTHON\"") .contains("name=\"module.ąęółżźćń\"") .contains("path=\"path/ą/ę/module.py\""); }
@Test public void excludedPathIsProperlyWrittenAsFragment() { final ExcludedPath path = ExcludedPath.create("some/excluded/path"); final String fragment = new RobotProjectConfigWriter().writeFragment(path); assertThat(fragment).doesNotContain("<%xml").contains("<excludedPath").contains("path=\"some/excluded/path\""); }
@Test public void excludedPathIsProperlyWrittenAsFragment_withNonAsciiCharacters() { final ExcludedPath path = ExcludedPath.create("ą/ę"); final String fragment = new RobotProjectConfigWriter().writeFragment(path); assertThat(fragment).doesNotContain("<%xml").contains("<excludedPath").contains("path=\"ą/ę\""); }