*/
public class getReaderForText implements Testlet
{
public void test(TestHarness harness)
{
SimpleDoc doc = new SimpleDoc(
new String("Text to print"), DocFlavor.STRING.TEXT_PLAIN, null);
try
{
Reader reader1 = doc.getReaderForText();
Reader reader2 = doc.getReaderForText();
harness.check(reader1 == reader2);
harness.check(reader1 instanceof StringReader);
}
catch (IOException e)
{
harness.check(false);
}
SimpleDoc doc1 = new SimpleDoc(
new char[]{'A','b'}, DocFlavor.CHAR_ARRAY.TEXT_PLAIN, null);
try
{
Reader reader2 = doc1.getReaderForText();
Reader reader3 = doc1.getReaderForText();
harness.check(reader2 == reader3);
harness.check(reader2 instanceof CharArrayReader);
}
catch (IOException e)
{
harness.check(false);
}
SimpleDoc doc2 = new SimpleDoc(
new CharArrayReader(new char[]{'A','b'}), DocFlavor.READER.TEXT_PLAIN, null);
try
{
Reader reader4 = doc2.getReaderForText();
Reader reader5 = doc2.getReaderForText();
harness.check(reader4 == reader5);
harness.check(reader4 == doc2.getPrintData());
}
catch (IOException e)
{
harness.check(false);
}
SimpleDoc doc3 = new SimpleDoc(
new byte[]{'A','b'}, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
try
{
Reader reader6 = doc3.getReaderForText();
harness.check(reader6 == null);
}
catch (IOException e)
{
harness.check(false);