diff options
author | Paul Duffin <paulduffin@google.com> | 2015-01-19 12:46:40 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-01-19 12:46:40 +0000 |
commit | aab56800fcb95e9b1a2d653588b14158080cc6b4 (patch) | |
tree | 7365392c3ea77742021cf187acfd465f9bb774ab /guava-tests/test/com/google/common/io/CharStreamsTest.java | |
parent | 6fa98dbaae182b511fbeb331e08f5fb827715ea8 (diff) | |
parent | 84fb43aa6a1e752487f2624055ff26b1b6b7c043 (diff) | |
download | android_external_guava-aab56800fcb95e9b1a2d653588b14158080cc6b4.tar.gz android_external_guava-aab56800fcb95e9b1a2d653588b14158080cc6b4.tar.bz2 android_external_guava-aab56800fcb95e9b1a2d653588b14158080cc6b4.zip |
am 84fb43aa: Merge "Revert "Upgraded Guava to unmodified v14.0.1""
* commit '84fb43aa6a1e752487f2624055ff26b1b6b7c043':
Revert "Upgraded Guava to unmodified v14.0.1"
Diffstat (limited to 'guava-tests/test/com/google/common/io/CharStreamsTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/io/CharStreamsTest.java | 144 |
1 files changed, 3 insertions, 141 deletions
diff --git a/guava-tests/test/com/google/common/io/CharStreamsTest.java b/guava-tests/test/com/google/common/io/CharStreamsTest.java index f0c84a2..c628afb 100644 --- a/guava-tests/test/com/google/common/io/CharStreamsTest.java +++ b/guava-tests/test/com/google/common/io/CharStreamsTest.java @@ -21,13 +21,10 @@ import static com.google.common.io.CharStreams.copy; import static com.google.common.io.CharStreams.newReaderSupplier; import com.google.common.base.Charsets; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.testing.TestLogHandler; -import junit.framework.TestSuite; - import java.io.ByteArrayInputStream; import java.io.EOFException; import java.io.FilterReader; @@ -46,15 +43,6 @@ import java.util.List; * @author Chris Nokleberg */ public class CharStreamsTest extends IoTestCase { - - public static TestSuite suite() { - TestSuite suite = new TestSuite(); - suite.addTest(CharSourceTester.tests("CharStreams.asCharSource[String]", - SourceSinkFactories.stringCharSourceFactory())); - suite.addTestSuite(CharStreamsTest.class); - return suite; - } - private static final String TEXT = "The quick brown fox jumped over the lazy dog."; @@ -92,18 +80,18 @@ public class CharStreamsTest extends IoTestCase { CharStreams.skipFully(reader, 6); assertEquals(-1, reader.read()); } - + private static class NonSkippingReader extends StringReader { NonSkippingReader(String s) { super(s); } - + @Override public long skip(long n) { return 0; } } - + public void testReadLines_fromReadable() throws IOException { byte[] bytes = "a\nb\nc".getBytes(Charsets.UTF_8.name()); List<String> lines = CharStreams.readLines( @@ -230,66 +218,6 @@ public class CharStreamsTest extends IoTestCase { assertTrue(brokenWrite.areClosed()); } - public void testCopySuppliersExceptions() { - if (!Closer.SuppressingSuppressor.isAvailable()) { - // test that exceptions are logged - - TestLogHandler logHandler = new TestLogHandler(); - Closeables.logger.addHandler(logHandler); - try { - for (InputSupplier<? extends Reader> in : BROKEN_INPUTS) { - runFailureTest(in, newStringWriterSupplier()); - assertTrue(logHandler.getStoredLogRecords().isEmpty()); - - runFailureTest(in, BROKEN_CLOSE_OUTPUT); - assertEquals((in == BROKEN_GET_INPUT) ? 0 : 1, getAndResetRecords(logHandler)); - } - - for (OutputSupplier<? extends Writer> out : BROKEN_OUTPUTS) { - runFailureTest(newReaderSupplier("ABC"), out); - assertTrue(logHandler.getStoredLogRecords().isEmpty()); - - runFailureTest(BROKEN_CLOSE_INPUT, out); - assertEquals(1, getAndResetRecords(logHandler)); - } - - for (InputSupplier<? extends Reader> in : BROKEN_INPUTS) { - for (OutputSupplier<? extends Writer> out : BROKEN_OUTPUTS) { - runFailureTest(in, out); - assertTrue(getAndResetRecords(logHandler) <= 1); - } - } - } finally { - Closeables.logger.removeHandler(logHandler); - } - } else { - // test that exceptions are suppressed - - for (InputSupplier<? extends Reader> in : BROKEN_INPUTS) { - int suppressed = runSuppressionFailureTest(in, newStringWriterSupplier()); - assertEquals(0, suppressed); - - suppressed = runSuppressionFailureTest(in, BROKEN_CLOSE_OUTPUT); - assertEquals((in == BROKEN_GET_INPUT) ? 0 : 1, suppressed); - } - - for (OutputSupplier<? extends Writer> out : BROKEN_OUTPUTS) { - int suppressed = runSuppressionFailureTest(newReaderSupplier("ABC"), out); - assertEquals(0, suppressed); - - suppressed = runSuppressionFailureTest(BROKEN_CLOSE_INPUT, out); - assertEquals(1, suppressed); - } - - for (InputSupplier<? extends Reader> in : BROKEN_INPUTS) { - for (OutputSupplier<? extends Writer> out : BROKEN_OUTPUTS) { - int suppressed = runSuppressionFailureTest(in, out); - assertTrue(suppressed <= 1); - } - } - } - } - private static int getAndResetRecords(TestLogHandler logHandler) { int records = logHandler.getStoredLogRecords().size(); logHandler.clear(); @@ -305,20 +233,6 @@ public class CharStreamsTest extends IoTestCase { } } - /** - * @return the number of exceptions that were suppressed on the expected thrown exception - */ - private static int runSuppressionFailureTest( - InputSupplier<? extends Reader> in, OutputSupplier<? extends Writer> out) { - try { - copy(in, out); - fail(); - } catch (IOException expected) { - return CloserTest.getSuppressed(expected).length; - } - throw new AssertionError(); // can't happen - } - private static OutputSupplier<Writer> newStringWriterSupplier() { return new OutputSupplier<Writer>() { @Override public Writer getOutput() { @@ -374,38 +288,6 @@ public class CharStreamsTest extends IoTestCase { assertEquals(expected, sw.toString()); } - public void testCopy() throws IOException { - StringBuilder builder = new StringBuilder(); - long copied = CharStreams.copy(new StringReader(ASCII), builder); - assertEquals(ASCII, builder.toString()); - assertEquals(ASCII.length(), copied); - - StringBuilder builder2 = new StringBuilder(); - copied = CharStreams.copy(new StringReader(I18N), builder2); - assertEquals(I18N, builder2.toString()); - assertEquals(I18N.length(), copied); - } - - /** - * Test for Guava issue 1061: http://code.google.com/p/guava-libraries/issues/detail?id=1061 - * - * <p>CharStreams.copy was failing to clear its CharBuffer after each read call, which effectively - * reduced the available size of the buffer each time a call to read didn't fill up the available - * space in the buffer completely. In general this is a performance problem since the buffer size - * is permanently reduced, but with certain Reader implementations it could also cause the buffer - * size to reach 0, causing an infinite loop. - */ - public void testCopyWithReaderThatDoesNotFillBuffer() throws IOException { - // need a long enough string for the buffer to hit 0 remaining before the copy completes - String string = Strings.repeat("0123456789", 100); - StringBuilder b = new StringBuilder(); - // the main assertion of this test is here... the copy will fail if the buffer size goes down - // each time it is not filled completely - long copied = CharStreams.copy(newNonBufferFillingReader(new StringReader(string)), b); - assertEquals(string, b.toString()); - assertEquals(string.length(), copied); - } - private static CheckCloseSupplier.Input<Reader> newCheckReader( InputSupplier<? extends Reader> delegate) { return new CheckCloseSupplier.Input<Reader>(delegate) { @@ -433,24 +315,4 @@ public class CharStreamsTest extends IoTestCase { } }; } - - /** - * Returns a reader wrapping the given reader that only reads half of the maximum number of - * characters that it could read in read(char[], int, int). - */ - private static Reader newNonBufferFillingReader(Reader reader) { - return new FilterReader(reader) { - @Override - public int read(char[] cbuf, int off, int len) throws IOException { - // if a buffer isn't being cleared correctly, this method will eventually start being called - // with a len of 0 forever - if (len <= 0) { - fail("read called with a len of " + len); - } - // read fewer than the max number of chars to read - // shouldn't be a problem unless the buffer is shrinking each call - return in.read(cbuf, off, Math.max(len - 1024, 0)); - } - }; - } } |