| 11 | import java.util.zip.*; |
| 12 | |
| 13 | public class ZipOutputStreamTest |
| 14 | { |
| 15 | private static final String TEST1 = "test1.txt"; |
| 16 | private static final String TEST2 = "test2.txt"; |
| 17 | private static final String TEST3 = "test3.txt"; |
| 18 | private static final String TEST4 = "test4.txt"; |
| 19 | |
| 20 | private static final String TEST1_CONTENTS = "\"this is a test\""; |
| 21 | private static final String TEST2_CONTENTS = "this is a\nmulti-line test"; |
| 22 | private static final String TEST3_CONTENTS = "74 68 69 73 20 69 73 20 61 20 74 65 73 74"; |
| 23 | private static final String TEST4_CONTENTS = "01110100 01101000 01101001 01110011 00100000 01101001 01110011 00100000 01100001 00100000 01110100 01100101 01110011 01110100"; |
| 24 | |
| 25 | private static final String ONE_PARAM_ZIP_PREFIX = "zos1param"; |
| 26 | private static final String THREE_PARAM_ZIP_PREFIX = "zos3param"; |
| 27 | private static final String ZIP_SUFFIX = ".zip"; |
| 28 | |
| 29 | private static final Map<String, String> FILES_CONTENTS; |
| 30 | static |
| 31 | { |
| 32 | Map<String, String> m = new HashMap<String, String>(); |
| 33 | m.put(TEST1, TEST1_CONTENTS); |
| 34 | m.put(TEST2, TEST2_CONTENTS); |
| 35 | m.put(TEST3, TEST3_CONTENTS); |
| 36 | m.put(TEST4, TEST4_CONTENTS); |
| 37 | FILES_CONTENTS = Collections.unmodifiableMap(m); |
| 38 | } |
| 39 | |
| 40 | private static final boolean USE_ONE_PARAM_WRITE = true; |
| 41 | private static final boolean USE_THREE_PARAM_WRITE = false; |
| 42 | private static byte[] buffer = new byte[1024]; |
| 43 | |
| 44 | public static void main(String[] args) |
| 45 | { |
| 46 | List<File> zipFiles = new ArrayList<File>(2); |
| 47 | |
| 48 | // Test 1-param write function |
| 49 | File f1 = createZip(USE_ONE_PARAM_WRITE); |
| 50 | zipFiles.add(f1); |
| 51 | verifyContents(f1.getAbsolutePath()); |
| 52 | // Test 3-param write function |
| 53 | File f2 = createZip(USE_THREE_PARAM_WRITE); |
| 54 | zipFiles.add(f2); |
| 55 | verifyContents(f2.getAbsolutePath()); |
| 56 | // Remove the created zip files |
| 57 | cleanUp(zipFiles); |
| 58 | } |
| 59 | |
| 60 | private static File createZip(boolean useOneParam) |
| 61 | { |
| 62 | FileOutputStream outputStream = null; |
| 63 | ZipOutputStream zipContents = null; |
| 64 | |
| 65 | try |
| 66 | { |
| 67 | // Create a temporary zip file for this test |
| 68 | String prefix = useOneParam ? ONE_PARAM_ZIP_PREFIX : THREE_PARAM_ZIP_PREFIX; |
| 69 | File outputZip = File.createTempFile(prefix, ZIP_SUFFIX); |
| 70 |
nothing calls this directly
no test coverage detected