### Question:
Serializer { public void writeStatement(Statement statement) throws IOException { try { statement.accept(this.serializerStatementVisitor); } catch (Serializer.RuntimeIoException e) { throw e.getIoException(); } } Serializer(final Writer writer, final Function<String, String> iriTransformer);  Serializer(final Writer writer);  Serializer(final Writer writer, PrefixDeclarationRegistry prefixDeclarationRegistry); void writeStatement(Statement statement); void writeFact(Fact fact); void writeRule(Rule rule); void writeDataSourceDeclaration(DataSourceDeclaration dataSourceDeclaration); void writeLiteral(Literal literal); void writePositiveLiteral(Predicate predicate, List<Term> arguments); void writeLiteralConjunction(final Conjunction<? extends Literal> literals); void writePredicate(Predicate predicate); void writeTerm(Term term); void writeAbstractConstant(AbstractConstant abstractConstant); void writeDatatypeConstant(DatatypeConstant datatypeConstant); void writeDatatypeConstantNoAbbreviations(DatatypeConstant datatypeConstant); void writeUniversalVariable(UniversalVariable universalVariable); void writeExistentialVariable(ExistentialVariable existentialVariable); void writeNamedNull(NamedNull namedNull); boolean writePrefixDeclarationRegistry(PrefixDeclarationRegistry prefixDeclarationRegistry); void writeLanguageStringConstant(LanguageStringConstant languageStringConstant); void writeCommand(Command command); static String getSerialization(SerializationWriter writeAction); static final String STATEMENT_END; static final Function<String, String> identityIriSerializer; }### Answer:
@Test public void serializeRule() throws IOException { serializer.writeStatement(rule); assertEquals("p1(?X) :- p2(?X, c), p1(c) .", writer.toString()); }
@Test public void serializeCsvDataSourceDeclaration() throws IOException { DataSourceDeclaration csvSourceDecl = new DataSourceDeclarationImpl(p1, new CsvFileDataSource("test.csv")); serializer.writeStatement(csvSourceDecl); assertEquals("@source p1[1]: load-csv(\"test.csv\") .", writer.toString()); }
@Test public void serializeRdfDataSourceDeclaration() throws IOException { DataSourceDeclaration rdfSourceDecl = new DataSourceDeclarationImpl(p3, new RdfFileDataSource("test.nt")); serializer.writeStatement(rdfSourceDecl); assertEquals("@source p3[3]: load-rdf(\"test.nt\") .", writer.toString()); }
@Test public void serializeSparqlDataSourceDeclaration() throws IOException { DataSourceDeclaration sparqlSourceDecl = new DataSourceDeclarationImpl(p1, new SparqlQueryResultDataSource(new URL("http: serializer.writeStatement(sparqlSourceDecl); assertEquals("@source p1[1]: sparql(<http: }
@Test(expected = IOException.class) public void serializeFact_fails() throws IOException { getThrowingSerializer().writeStatement(fact); }
@Test(expected = IOException.class) public void serializeRule_fails() throws IOException { getThrowingSerializer().writeStatement(rule); }
@Test(expected = IOException.class) public void serializeDataSourceDeclaration_fails() throws IOException { DataSourceDeclaration csvSourceDecl = new DataSourceDeclarationImpl(p1, new CsvFileDataSource("test.csv")); getThrowingSerializer().writeStatement(csvSourceDecl); }