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 package org.apache.harmony.tests.java.util.jar; 18 19 import java.io.File; 20 import java.io.FileOutputStream; 21 import java.io.IOException; 22 import java.util.jar.Attributes; 23 import java.util.jar.JarOutputStream; 24 import java.util.jar.Manifest; 25 import java.util.zip.ZipEntry; 26 27 public class JarOutputStreamTest extends junit.framework.TestCase { 28 29 /** 30 * java.util.jar.JarOutputStream#putNextEntry(java.util.zip.ZipEntry) 31 */ 32 public void test_putNextEntryLjava_util_zip_ZipEntry() throws Exception { 33 34 } 35 36 public void test_JarOutputStreamLjava_io_OutputStreamLjava_util_jar_Manifest() 37 throws IOException { 38 File fooJar = File.createTempFile("hyts_", ".jar"); 39 fooJar.deleteOnExit(); 40 File barZip = File.createTempFile("hyts_", ".zip"); 41 barZip.deleteOnExit(); 42 43 FileOutputStream fos = new FileOutputStream(fooJar); 44 45 Manifest man = new Manifest(); 46 Attributes att = man.getMainAttributes(); 47 att.put(Attributes.Name.MANIFEST_VERSION, "1.0"); 48 att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo"); 49 att.put(Attributes.Name.CLASS_PATH, barZip.getName()); 50 51 fos.close(); 52 try { 53 new JarOutputStream(fos, man); 54 fail("IOException expected"); 55 } catch (IOException ee) { 56 // expected 57 } 58 59 try { 60 new JarOutputStream(fos, null); 61 fail("NullPointerException expected"); 62 } catch (NullPointerException ee) { 63 // expected 64 } 65 } 66 67 public void test_JarOutputStreamLjava_io_OutputStream() throws IOException { 68 File fooJar = File.createTempFile("hyts_", ".jar"); 69 70 FileOutputStream fos = new FileOutputStream(fooJar); 71 ZipEntry ze = new ZipEntry("Test"); 72 73 try { 74 JarOutputStream joutFoo = new JarOutputStream(fos); 75 joutFoo.putNextEntry(ze); 76 joutFoo.write(33); 77 } catch (IOException ee) { 78 fail("IOException is not expected"); 79 } 80 81 fos.close(); 82 fooJar.delete(); 83 try { 84 JarOutputStream joutFoo = new JarOutputStream(fos); 85 joutFoo.putNextEntry(ze); 86 fail("IOException expected"); 87 } catch (IOException ee) { 88 // expected 89 } 90 } 91 } 92