final static Format B = new Format("B");
public void testGetConverter() throws ConverterException {
ConverterRegistry registry = new ConverterRegistry();
Converter anyEncConverter = new GenericConverter(){
// A, B, null, null
{
getConverterContext().setSourceFormat(A);
getConverterContext().setTargetFormat(B);
getConverterContext().setSourceEncoding(null);
getConverterContext().setTargetEncoding(null);
}
public void convert(InputStream in, OutputStream out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
public void convert(Reader in, Writer out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
};
Converter anySourceEncConverter = new GenericConverter(){
// A, B, null, "UTF-8"
{
getConverterContext().setSourceFormat(A);
getConverterContext().setTargetFormat(B);
getConverterContext().setSourceEncoding(null);
getConverterContext().setTargetEncoding("UTF-8");
}
public void convert(InputStream in, OutputStream out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
public void convert(Reader in, Writer out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
};
Converter anyTargetEncConverter = new GenericConverter(){
// A, B, "UTF-8", null
{
getConverterContext().setSourceFormat(A);
getConverterContext().setTargetFormat(B);
getConverterContext().setSourceEncoding("UTF-8");
getConverterContext().setTargetEncoding(null);
}
public void convert(InputStream in, OutputStream out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
public void convert(Reader in, Writer out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
};
Converter specifiedEncConverter = new GenericConverter(){
// A, B, "UTF-8", "UTF-8"
{
getConverterContext().setSourceFormat(A);
getConverterContext().setTargetFormat(B);
getConverterContext().setSourceEncoding("UTF-8");
getConverterContext().setTargetEncoding("UTF-8");
}
public void convert(InputStream in, OutputStream out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
public void convert(Reader in, Writer out,
ConversionParameters params) throws ConverterException,
IOException
{
// TODO Auto-generated method stub
}
};
registry.addConverter(anySourceEncConverter);
registry.addConverter(anyTargetEncConverter);
registry.addConverter(specifiedEncConverter);
Converter returnedConverter;
returnedConverter = registry.getConverter(A.getName(), B.getName(),
"egal", "UTF-8");
assertTrue(anySourceEncConverter == returnedConverter);