### Question:
Serializer { public boolean writePrefixDeclarationRegistry(PrefixDeclarationRegistry prefixDeclarationRegistry) throws IOException { boolean result = false; final String baseIri = prefixDeclarationRegistry.getBaseIri(); if (!PrefixDeclarationRegistry.EMPTY_BASE.contentEquals(baseIri)) { writer.write("@base <"); writer.write(baseIri); writer.write(">"); writer.write(STATEMENT_END); writer.write("\n"); result = true; } Iterator<Entry<String, String>> prefixIterator = prefixDeclarationRegistry.iterator(); while (prefixIterator.hasNext()) { Entry<String, String> entry = prefixIterator.next(); writer.write("@prefix "); writer.write(entry.getKey()); writer.write(" <"); writer.write(entry.getValue()); writer.write(">"); writer.write(STATEMENT_END); writer.write("\n"); result = true; } return result; } 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 serializePrefixDeclarations() throws IOException { final MergingPrefixDeclarationRegistry prefixes = new MergingPrefixDeclarationRegistry(); prefixes.setBaseIri("http: prefixes.setPrefixIri("eg:", "http: Serializer prefSerializer = new Serializer(writer, prefixes); boolean result = prefSerializer.writePrefixDeclarationRegistry(prefixes); assertEquals("@base <http: assertTrue(result); }
@Test public void serializeEmptyPrefixDeclarations() throws IOException { final MergingPrefixDeclarationRegistry prefixes = new MergingPrefixDeclarationRegistry(); Serializer prefSerializer = new Serializer(writer, prefixes); boolean result = prefSerializer.writePrefixDeclarationRegistry(prefixes); assertEquals("", writer.toString()); assertFalse(result); }
@Test(expected = IOException.class) public void serializePrefixDeclarations_fails() throws IOException { final MergingPrefixDeclarationRegistry prefixes = new MergingPrefixDeclarationRegistry(); prefixes.setBaseIri("http: prefixes.setPrefixIri("eg:", "http: getThrowingSerializer().writePrefixDeclarationRegistry(prefixes); }