1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package libcore.java.io; 18 19import java.io.BufferedWriter; 20import java.io.StringWriter; 21import junit.framework.TestCase; 22 23/** 24 * Some basic tests for BufferedWriter. 25 */ 26public class OldAndroidBufferedWriterTest extends TestCase { 27 28 public void testBufferedWriter() throws Exception { 29 String str = "AbCdEfGhIjKlMnOpQrStUvWxYz"; 30 StringWriter aa = new StringWriter(); 31 32 BufferedWriter a = new BufferedWriter(aa, 20); 33 try { 34 a.write(str.toCharArray(), 0, 26); 35 a.write('X'); 36 a.flush(); 37 assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", aa.toString()); 38 39 a.write("alphabravodelta", 5, 5); 40 a.flush(); 41 assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravo", aa.toString()); 42 a.newLine(); 43 a.write("I'm on a new line."); 44 a.flush(); 45 assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravo\nI\'m on a new line.", aa.toString()); 46 } finally { 47 a.close(); 48 } 49 } 50} 51