2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package libcore.java.io;
19 import java.io.BufferedInputStream;
20 import java.io.DataInputStream;
21 import java.io.FilterInputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.LineNumberInputStream;
25 import java.io.PushbackInputStream;
26 import java.security.DigestInputStream;
27 import java.security.MessageDigest;
28 import java.security.NoSuchAlgorithmException;
29 import java.util.zip.CRC32;
30 import java.util.zip.CheckedInputStream;
31 import java.util.zip.Inflater;
32 import java.util.zip.InflaterInputStream;
33 import javax.crypto.CipherInputStream;
34 import javax.crypto.NullCipher;
35 import junit.framework.TestCase;
37 public final class FilterInputStreamNullSourceTest extends TestCase {
39 public void testBufferedInputStream() throws IOException {
40 assertReadsFailWithIoException(new BufferedInputStream(null));
41 assertReadsFailWithIoException(new BufferedInputStream(null, 1024));
44 public void testCheckedInputStream() throws IOException {
45 assertReadsFailWithNullPointerException(new CheckedInputStream(null, new CRC32()));
48 public void testCipherInputStream() throws IOException {
49 InputStream in = new CipherInputStream(null, new NullCipher());
53 } catch (NullPointerException expected) {
56 assertEquals(0, in.available());
61 } catch (NullPointerException expected) {
65 public void testDataInputStream() throws IOException {
66 assertReadsFailWithNullPointerException(new DataInputStream(null));
69 public void testDigestInputStream() throws IOException, NoSuchAlgorithmException {
70 MessageDigest md5 = MessageDigest.getInstance("MD5");
71 assertReadsFailWithNullPointerException(new DigestInputStream(null, md5));
74 public void testFilterInputStream() throws IOException {
75 assertReadsFailWithNullPointerException(new FilterInputStream(null) {});
78 public void testInflaterInputStream() throws IOException {
80 new InflaterInputStream(null);
82 } catch (NullPointerException expected) {
85 new InflaterInputStream(null, new Inflater());
87 } catch (NullPointerException expected) {
90 new InflaterInputStream(null, new Inflater(), 1024);
92 } catch (NullPointerException expected) {
96 public void testLineNumberInputStream() throws IOException {
97 assertReadsFailWithNullPointerException(new LineNumberInputStream(null));
100 public void testPushbackInputStream() throws IOException {
101 assertReadsFailWithIoException(new PushbackInputStream(null));
102 assertReadsFailWithIoException(new PushbackInputStream(null, 1024));
105 private void assertReadsFailWithIoException(InputStream in) throws IOException {
109 } catch (IOException expected) {
115 } catch (IOException expected) {
121 private void assertReadsFailWithNullPointerException(InputStream in) throws IOException {
125 } catch (NullPointerException expected) {
131 } catch (NullPointerException expected) {
137 } catch (NullPointerException expected) {