Exemplo n.º 1
0
 /** Test {@link TextInput#isEmpty()}. */
 public void testIsEmpty() {
   assertFalse(qedeqInput.isEmpty());
   final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
   for (int i = 0; i < first.length(); i++) {
     qedeqInput.read();
     assertFalse(qedeqInput.isEmpty());
   }
   qedeqInput.setPosition(qedeqInput.getMaximumPosition());
   assertTrue(qedeqInput.isEmpty());
 }
Exemplo n.º 2
0
  /** Test constructor {@link TextInput#TextInput(Reader)}. */
  public void testTextInputReader() throws Exception {
    final TextInput ti =
        new TextInput(
            new Reader() {
              int pos = 0;

              public void close() throws IOException {}

              public int read(char[] cbuf, int off, int len) throws IOException {
                if (pos >= XML_DATA.length()) {
                  return -1;
                }
                final String result = StringUtility.substring(XML_DATA, pos, len);
                for (int i = 0; i < result.length(); i++) {
                  cbuf[off + i] = result.charAt(i);
                }
                pos += result.length();
                return result.length();
              }
            });
    int i = 0;
    while (!ti.isEmpty()) {
      assertEquals(ti.read(), XML_DATA.charAt(i++));
    }
    try {
      new TextInput((Reader) null);
      fail("NullPointerException expected");
    } catch (NullPointerException e) {
      // expected
    }
  }
Exemplo n.º 3
0
 /** Test constructor {@link TextInput#TextInput(String)}. */
 public void testTextInputStringStringString() {
   int i = 0;
   while (!qedeqInput.isEmpty()) {
     assertEquals(qedeqInput.read(), XML_DATA.charAt(i++));
   }
   try {
     new TextInput((String) null);
     fail("NullPointerException expected");
   } catch (NullPointerException e) {
     // expected
   }
 }
Exemplo n.º 4
0
 /** Test constructor {@link TextInput#TextInput(StringBuffer)}. */
 public void testTextInputStringBufferStringString() {
   final StringBuffer buffer = new StringBuffer(XML_DATA);
   final TextInput ti = new TextInput(buffer);
   int i = 0;
   while (!ti.isEmpty()) {
     assertEquals(ti.read(), XML_DATA.charAt(i++));
   }
   try {
     new TextInput((StringBuffer) null);
     fail("NullPointerException expected");
   } catch (NullPointerException e) {
     // expected
   }
 }
Exemplo n.º 5
0
 /**
  * Test constructor {@link TextInput#TextInput(File)}.
  *
  * @throws Exception Test failed.
  */
 public void testTextInputFileString() throws Exception {
   final File file = new File(getOutdir(), this.getClass().getName() + ".testTexFileInput.impl");
   IoUtility.saveFile(file, XML_DATA, IoUtility.getDefaultEncoding());
   TextInput ti = new TextInput(file, IoUtility.getDefaultEncoding());
   while (!qedeqInput.isEmpty()) {
     assertEquals(qedeqInput.read(), ti.read());
   }
   try {
     new TextInput((File) null, "UTF-8");
     fail("Exception expected");
   } catch (RuntimeException e) {
     // OK
   }
   assertTrue(file.delete());
 }