cleanup work in tests

This commit is contained in:
eugenp 2014-07-12 11:55:08 +03:00
parent 02ecb42ccb
commit 092b3213ea
1 changed files with 31 additions and 9 deletions

View File

@ -26,17 +26,39 @@ public class JavaReaderToXUnitTest {
protected final Logger logger = LoggerFactory.getLogger(getClass()); protected final Logger logger = LoggerFactory.getLogger(getClass());
private static final int DEFAULT_SIZE = 1500000; private static final int DEFAULT_SIZE = 1500000;
// tests - sandbox
// tests - Reader to String // tests - Reader to String
// @Test @Test
// public void givenUsingPlainJava_whenConvertingReaderIntoString_thenCorrect() throws IOException { public void givenUsingPlainJava_whenConvertingReaderIntoString1_thenCorrect() throws IOException {
// final Reader initialReader = new StringReader("text"); final Reader reader = new StringReader("text");
// // int bufferSize = initialReader.toString().length(); int intValueOfChar;
// // char[] buffer = new char[bufferSize]; String targetString = "";
// initialReader.read(buffer); while ((intValueOfChar = reader.read()) != -1) {
// initialReader.close(); targetString += (char) intValueOfChar;
// final String targetString = new String(buffer); }
// } reader.close();
// test
System.out.println("targetString: " + targetString);
}
@Test
public void givenUsingPlainJava_whenConvertingReaderIntoString2_thenCorrect() throws IOException {
final Reader reader = new StringReader("text");
final char[] arr = new char[8 * 1024]; // 8K at a time
final StringBuffer buf = new StringBuffer();
int numChars;
while ((numChars = reader.read(arr, 0, arr.length)) > 0) {
buf.append(arr, 0, numChars);
}
reader.close();
// test
System.out.println("targetString: " + buf.toString());
}
@Test @Test
public void givenUsingGuava_whenConvertingReaderIntoString_thenCorrect() throws IOException { public void givenUsingGuava_whenConvertingReaderIntoString_thenCorrect() throws IOException {