Index: lutinutil/src/test/org/codelutin/util/ZipUtilTest.java diff -u /dev/null lutinutil/src/test/org/codelutin/util/ZipUtilTest.java:1.1 --- /dev/null Thu Aug 24 13:37:25 2006 +++ lutinutil/src/test/org/codelutin/util/ZipUtilTest.java Thu Aug 24 13:37:20 2006 @@ -0,0 +1,101 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * ZipUtilTest.java + * + * Created: 24 août 2006 10:47:21 + * + * @author poussin + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2006/08/24 13:37:20 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.util; + +import java.io.File; +import java.io.FileFilter; + +import org.apache.commons.logging.LogFactory; + +import junit.framework.TestCase; + + +/** + * @author poussin + * + */ + +public class ZipUtilTest extends TestCase { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private org.apache.commons.logging.Log log = LogFactory.getLog(ZipUtilTest.class); + + public static void main(String[] args) { + } + + /* + * Test method for 'org.codelutin.util.ZipUtil.compress(File, File, FileFilter)' + */ + public void testCompress() throws Exception { + File dir = new File(System.getProperty("user.dir")); + File zipFile = File.createTempFile("testCompressZip", ".zip"); + log.info("Compress " + dir + "in zip file = " + zipFile); + + ZipUtil.compress(zipFile, dir, null); + + assertTrue(zipFile.exists()); + assertTrue(0 != zipFile.length()); + } + + public void testCompressFilter() throws Exception { + File dir = new File(System.getProperty("user.dir")); + File zipFile = File.createTempFile("testCompressZip", ".zip"); + log.info("Compress " + dir + "in zip file = " + zipFile); + + FileFilter filter = new FileFilter() { + public boolean accept(File pathname) { + boolean result = !pathname.getPath().contains("/target"); + return result; + } + + }; + + ZipUtil.compress(zipFile, dir, filter); + + assertTrue(zipFile.exists()); + assertTrue(0 != zipFile.length()); + } + + public void testCompressFile() throws Exception { + File dir = new File(System.getProperty("java.home"), "bin" + File.separator + "java"); + File zipFile = File.createTempFile("testCompressZip", ".zip"); + log.info("Compress " + dir + "in zip file = " + zipFile); + + ZipUtil.compress(zipFile, dir, null); + + assertTrue(zipFile.exists()); + assertTrue(0 != zipFile.length()); + } + +} + +