Esempio n. 1
0
 /** @tests java.io.BufferedWriter#newLine() */
 public void test_newLine() throws Exception {
   String separator = System.getProperty("line.separator");
   bw.write("Hello");
   bw.newLine();
   bw.write("World");
   bw.flush();
   assertTrue(
       "Incorrect string written: " + sw.toString(),
       sw.toString().equals("Hello" + separator + "World"));
 }
Esempio n. 2
0
  /** @tests java.io.BufferedWriter#close() */
  public void test_close() throws IOException {
    try {
      bw.close();
      bw.write(testString);
      fail("Writing to a closed stream should throw IOException");
    } catch (IOException e) {
      // Expected
    }
    assertTrue("Write after close", !sw.toString().equals(testString));

    // Regression test for HARMONY-4178
    MockWriter mw = new MockWriter();
    BufferedWriter bw = new BufferedWriter(mw);
    bw.write('a');
    bw.close();

    // flush should not be called on underlying stream
    assertFalse("Flush was called in the underlying stream", mw.isFlushCalled());

    // on the other hand the BufferedWriter itself should flush the
    // buffer
    assertEquals("BufferdWriter do not flush itself before close", "a", mw.getWritten());
  }
Esempio n. 3
0
 /** @tests java.io.BufferedWriter#BufferedWriter(java.io.Writer) */
 public void test_ConstructorLjava_io_Writer() {
   sw = new Support_StringWriter();
   bw = new BufferedWriter(sw);
   sw.write("Hi");
   assertEquals("Constructor failed", "Hi", sw.toString());
 }
Esempio n. 4
0
 /** @tests java.io.BufferedWriter#write(java.lang.String, int, int) */
 public void test_writeLjava_lang_StringII() throws Exception {
   bw.write(testString);
   bw.flush();
   assertTrue("Incorrect string written", sw.toString().equals(testString));
 }
Esempio n. 5
0
 /** @tests java.io.BufferedWriter#write(int) */
 public void test_writeI() throws Exception {
   bw.write('T');
   assertTrue("Char written without flush", sw.toString().equals(""));
   bw.flush();
   assertEquals("Incorrect char written", "T", sw.toString());
 }
Esempio n. 6
0
 /** @tests java.io.BufferedWriter#write(char[], int, int) */
 public void test_write$CII() throws Exception {
   char[] testCharArray = testString.toCharArray();
   bw.write(testCharArray, 500, 1000);
   bw.flush();
   assertTrue("Incorrect string written", sw.toString().equals(testString.substring(500, 1500)));
 }
Esempio n. 7
0
 /** @tests java.io.BufferedWriter#flush() */
 public void test_flush() throws Exception {
   bw.write("This should not cause a flush");
   assertTrue("Bytes written without flush", sw.toString().equals(""));
   bw.flush();
   assertEquals("Bytes not flushed", "This should not cause a flush", sw.toString());
 }