[zipdiff-cvs] zipdiff/src/test/zipdiff DifferenceCalculatorTest.java,1.4,1.5
Status: Alpha
Brought to you by:
sullis
From: Sean S. <su...@us...> - 2004-06-19 20:22:10
|
Update of /cvsroot/zipdiff/zipdiff/src/test/zipdiff In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27295/src/test/zipdiff Modified Files: DifferenceCalculatorTest.java Log Message: Index: DifferenceCalculatorTest.java =================================================================== RCS file: /cvsroot/zipdiff/zipdiff/src/test/zipdiff/DifferenceCalculatorTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DifferenceCalculatorTest.java 19 Jun 2004 20:14:34 -0000 1.4 --- DifferenceCalculatorTest.java 19 Jun 2004 20:21:59 -0000 1.5 *************** *** 5,15 **** --- 5,21 ---- package zipdiff; + import java.io.BufferedOutputStream; + import java.io.File; import java.io.FileNotFoundException; + import java.io.FileOutputStream; import java.io.IOException; import java.util.Map; + import java.util.jar.JarEntry; + import java.util.jar.JarOutputStream; import zipdiff.DifferenceCalculator; import zipdiff.Differences; + import junit.framework.TestCase; /** *************** *** 18,22 **** * @author jastewart */ ! public class DifferenceCalculatorTest extends AbstractTestCase { --- 24,178 ---- * @author jastewart */ ! public class DifferenceCalculatorTest extends TestCase { ! private static String ENTRYA = "A"; ! private static String ENTRYB = "B"; ! private static String ENTRYC = "C"; ! public static final String SYSTEM_TMP_DIR_PROPERTY = "java.io.tmpdir"; ! public static final String TEST_DIR_POSTFIX = File.separator + "UnitTestsDifferenceCalculatorTest"; ! private static String testDirPathName; ! // naming convention The Capital letter denotes the entry so A will be the same as A ! // OneEntry denotes that the jar has one entry ! private static String testJarOneEmpty; ! private static String testJarTwoEmpty; ! private static String testJarOneEntryA1Filename; ! private static String testJarOneEntryA2Filename; ! private static String testJarOneEntryB1Filename; ! private static String testJarTwoEntryAB1Filename; ! private static String testJarTwoEntryAC2Filename; ! private static String testJarOneEntryAContentsChangedFilename; ! { ! testDirPathName = ! System.getProperty(System.getProperty(SYSTEM_TMP_DIR_PROPERTY)); ! if(testDirPathName == null) { ! testDirPathName = File.separator + "temp" + TEST_DIR_POSTFIX; ! } ! testJarOneEmpty = testDirPathName + File.separator + "testJarOneEmpty.jar"; ! testJarTwoEmpty = testDirPathName + File.separator + "testJarTwoEmpty.jar"; ! testJarOneEntryA1Filename = testDirPathName + File.separator + "testJarOneEntryA1Filename.jar"; ! testJarOneEntryA2Filename = testDirPathName + File.separator + "testJarOneEntryA2Filename.jar"; ! testJarOneEntryB1Filename = testDirPathName + File.separator + "testJarOneEntryB1Filename.jar"; ! testJarTwoEntryAB1Filename = testDirPathName + File.separator + "testJarTwoEntryAB1Filename.jar"; ! testJarTwoEntryAB1Filename = testDirPathName + File.separator + "testJarTwoEntryAB1Filename.jar"; ! testJarTwoEntryAC2Filename = testDirPathName + File.separator + "testJarTwoEntryAC2Filename.jar"; ! testJarOneEntryAContentsChangedFilename = testDirPathName + File.separator + "testJarOneEntryAContentsChangedFilename.jar"; ! } ! ! /** ! * Constructor for DifferenceCalculatorTest. ! * @param arg0 ! */ ! public DifferenceCalculatorTest(String arg0) { ! super(arg0); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryA1() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryA1Filename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYA); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='a'; ! } ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryA2() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryA2Filename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYA); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='a'; ! } ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryAContentsChanged() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryAContentsChangedFilename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYA); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='a'; ! } ! // set a different content so that it will come up as changed ! data1[data1.length-1] = 'b'; ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } ! ! /** ! * Create a jar with only one entry in it. That entry being A ! * @throws FileNotFoundException ! * @throws IOException ! */ ! public void createJarOneEntryB1() throws FileNotFoundException, IOException { ! // create a jar file with no duplicates ! File testDir = new File(testDirPathName); ! testDir.mkdirs(); ! JarOutputStream testJarOS = ! new JarOutputStream( ! new BufferedOutputStream( ! new FileOutputStream(testJarOneEntryB1Filename))); ! ! // ad an entry ! JarEntry entry1 = new JarEntry(ENTRYB); ! testJarOS.putNextEntry(entry1); ! byte data1[] = new byte[2048]; ! for (int i=0; i < data1.length; i++) { ! data1[i]='b'; ! } ! testJarOS.write(data1); ! ! testJarOS.flush(); ! testJarOS.close(); ! } *************** *** 36,40 **** Map changedEntries = differences.getChanged(); assertTrue(changedEntries.size() == 0); - } --- 192,195 ---- *************** *** 94,97 **** } - } --- 249,251 ---- |