Author: niallp Date: Wed Apr 14 17:19:15 2010 New Revision: 934024 URL: http://svn.apache.org/viewvc?rev=934024&view=rev Log: IO-242 Add proxy reader/writer tests
Added: commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java (with props) commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java (with props) Added: commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java?rev=934024&view=auto ============================================================================== --- commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java (added) +++ commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java Wed Apr 14 17:19:15 2010 @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.commons.io.input; + +import java.io.IOException; +import java.io.Reader; +import java.nio.CharBuffer; + +import junit.framework.TestCase; + +/** + * Test {...@link ProxyReader}. + * + * @version $Revision$ + */ +public class ProxyReaderTest extends TestCase { + + public ProxyReaderTest(String name) { + super(name); + } + + /** Test writing Null Char Array */ + public void testNullCharArray() { + + ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0)); + + try { + proxy.read((char[])null); + } catch(NullPointerException e) { + // Should it being throwing NPE? See IO-242 + } catch(Exception e) { + fail("Writing null String threw " + e); + } + + try { + proxy.read((char[])null, 0, 0); + } catch(Exception e) { + fail("Writing null String threw " + e); + } + } + + /** Test writing Null CharBuffer */ + public void testNullCharBuffer() { + + ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0)); + + try { + proxy.read((CharBuffer)null); + } catch(NullPointerException e) { + // Should it being throwing NPE? See IO-242 + } catch(Exception e) { + fail("Writing null String threw " + e); + } + } + + /** ProxyReader implementation */ + private static class ProxyReaderImpl extends ProxyReader { + ProxyReaderImpl(Reader proxy) { + super(proxy); + } + } + + /** Custom NullReader implementation */ + private static class CustomNullReader extends NullReader { + CustomNullReader(int len) { + super(len); + } + public int read(char[] chars) throws IOException { + return chars == null ? 0 : super.read(chars); + } + public int read(CharBuffer target) throws IOException { + return target == null ? 0 : super.read(target); + } + } +} Propchange: commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java?rev=934024&view=auto ============================================================================== --- commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java (added) +++ commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java Wed Apr 14 17:19:15 2010 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.commons.io.output; + +import junit.framework.TestCase; + +/** + * Test {...@link ProxyWriter}. + * + * @version $Revision$ + */ +public class ProxyWriterTest extends TestCase { + + public ProxyWriterTest(String name) { + super(name); + } + + /** Test writing Null String */ + public void testNullString() { + + ProxyWriter proxy = new ProxyWriter(new NullWriter()); + + try { + proxy.write((String)null); + } catch(NullPointerException e) { + // Should it being throwing NPE? See IO-242 + } catch(Exception e) { + fail("Writing null String threw " + e); + } + + try { + proxy.write((String)null, 0, 0); + } catch(NullPointerException e) { + // Should it being throwing NPE? See IO-242 + } catch(Exception e) { + fail("Writing null String threw " + e); + } + } + + /** Test writing Null Char array */ + public void testNullCharArray() { + + ProxyWriter proxy = new ProxyWriter(new NullWriter()); + + try { + proxy.write((char[])null); + } catch(NullPointerException e) { + // Should it being throwing NPE? See IO-242 + } catch(Exception e) { + fail("Writing null char[] threw " + e); + } + + try { + proxy.write((char[])null, 0, 0); + } catch(NullPointerException e) { + // Should it being throwing NPE? See IO-242 + } catch(Exception e) { + fail("Writing null char[] threw " + e); + } + } + +} Propchange: commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL