1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package org.apache.harmony.crypto.tests.javax.crypto;
19
20import java.io.BufferedInputStream;
21import java.io.ByteArrayInputStream;
22import java.io.InputStream;
23
24import junit.framework.TestCase;
25
26import javax.crypto.Cipher;
27import javax.crypto.CipherInputStream;
28import javax.crypto.NullCipher;
29
30public class CipherInputStreamTest extends TestCase {
31
32    /**
33     * @tests javax.crypto.CipherInputStream#read(byte[] b, int off, int len)
34     */
35    public void testReadBII() throws Exception {
36        // Regression for HARMONY-1080
37        CipherInputStream stream = new CipherInputStream(null, new NullCipher());
38        try {
39            stream.read(new byte[1], 1, 0);
40            fail("NullPointerException expected");
41        } catch (NullPointerException e) {
42            // expected
43        }
44    }
45
46    /**
47     * @tests javax.crypto.CipherInputStream#close()
48     */
49    public void testClose() throws Exception {
50        // Regression for HARMONY-1087
51        try {
52            new CipherInputStream(new ByteArrayInputStream(new byte[] { 1 }),
53                    Cipher.getInstance("DES/CBC/PKCS5Padding")).close();
54            fail("IllegalStateException expected!");
55        } catch (IllegalStateException e) {
56            // expected
57        }
58        try {
59            new CipherInputStream(new BufferedInputStream((InputStream) null),
60                    Cipher.getInstance("DES/CBC/PKCS5Padding")).close();
61            fail("IllegalStateException expected!");
62        } catch (IllegalStateException e) {
63            // expected
64        }
65    }
66
67}
68