diff options
Diffstat (limited to 'guava-tests/test/com/google/common/io/CharSourceTester.java')
-rw-r--r-- | guava-tests/test/com/google/common/io/CharSourceTester.java | 147 |
1 files changed, 0 insertions, 147 deletions
diff --git a/guava-tests/test/com/google/common/io/CharSourceTester.java b/guava-tests/test/com/google/common/io/CharSourceTester.java deleted file mode 100644 index b0d6eed..0000000 --- a/guava-tests/test/com/google/common/io/CharSourceTester.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2012 The Guava Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.common.io; - -import static com.google.common.io.SourceSinkFactory.CharSourceFactory; - -import com.google.common.collect.ImmutableList; - -import junit.framework.TestSuite; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.io.StringWriter; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; - -/** - * A generator of {@code TestSuite} instances for testing {@code CharSource} implementations. - * Generates tests of a all methods on a {@code CharSource} given various inputs the source is - * expected to contain. - * - * @author Colin Decker - */ -public class CharSourceTester extends SourceSinkTester<CharSource, String, CharSourceFactory> { - - private static final ImmutableList<Method> testMethods - = getTestMethods(CharSourceTester.class); - - static TestSuite tests(String name, CharSourceFactory factory) { - TestSuite suite = new TestSuite(name); - for (Map.Entry<String, String> entry : TEST_STRINGS.entrySet()) { - suite.addTest(suiteForString(factory, entry.getValue(), name, entry.getKey())); - } - return suite; - } - - static TestSuite suiteForString(CharSourceFactory factory, String string, - String name, String desc) { - TestSuite suite = new TestSuite(name + " [" + desc + "]"); - for (Method method : testMethods) { - suite.addTest(new CharSourceTester(factory, string, name, desc, method)); - } - return suite; - } - - private final ImmutableList<String> expectedLines; - - private CharSource source; - - public CharSourceTester(CharSourceFactory factory, String string, - String suiteName, String caseDesc, Method method) { - super(factory, string, suiteName, caseDesc, method); - this.expectedLines = getLines(expected); - } - - @Override - protected void setUp() throws Exception { - this.source = factory.createSource(data); - } - - public void testOpenStream() throws IOException { - Reader reader = source.openStream(); - - StringWriter writer = new StringWriter(); - char[] buf = new char[64]; - int read; - while ((read = reader.read(buf)) != -1) { - writer.write(buf, 0, read); - } - reader.close(); - writer.close(); - - assertExpectedString(writer.toString()); - } - - public void testOpenBufferedStream() throws IOException { - BufferedReader reader = source.openBufferedStream(); - - StringWriter writer = new StringWriter(); - char[] buf = new char[64]; - int read; - while ((read = reader.read(buf)) != -1) { - writer.write(buf, 0, read); - } - reader.close(); - writer.close(); - - assertExpectedString(writer.toString()); - } - - public void testCopyTo_appendable() throws IOException { - StringBuilder builder = new StringBuilder(); - - assertEquals(expected.length(), source.copyTo(builder)); - - assertExpectedString(builder.toString()); - } - - public void testCopyTo_charSink() throws IOException { - TestCharSink sink = new TestCharSink(); - - assertEquals(expected.length(), source.copyTo(sink)); - - assertExpectedString(sink.getString()); - } - - public void testRead_toString() throws IOException { - String string = source.read(); - assertExpectedString(string); - } - - public void testReadFirstLine() throws IOException { - if (expectedLines.isEmpty()) { - assertNull(source.readFirstLine()); - } else { - assertEquals(expectedLines.get(0), source.readFirstLine()); - } - } - - public void testReadLines_toList() throws IOException { - assertExpectedLines(source.readLines()); - } - - private void assertExpectedString(String string) { - assertEquals(expected, string); - } - - private void assertExpectedLines(List<String> list) { - assertEquals(expectedLines, list); - } -} |