emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java
branchemul
changeset 694 0d277415ed02
parent 686 63982243369c
     1.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java	Wed Feb 06 15:22:57 2013 +0100
     1.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java	Thu Feb 07 12:58:12 2013 +0100
     1.3 @@ -17,15 +17,8 @@
     1.4   */
     1.5  package org.apidesign.bck2brwsr.compact.tck;
     1.6  
     1.7 -import java.io.ByteArrayOutputStream;
     1.8  import java.io.IOException;
     1.9  import java.io.InputStream;
    1.10 -import java.util.Arrays;
    1.11 -import java.util.LinkedHashMap;
    1.12 -import java.util.Map;
    1.13 -import java.util.Objects;
    1.14 -import java.util.zip.ZipEntry;
    1.15 -import java.util.zip.ZipInputStream;
    1.16  import org.apidesign.bck2brwsr.vmtest.Compare;
    1.17  import org.apidesign.bck2brwsr.vmtest.VMTest;
    1.18  import org.testng.annotations.Factory;
    1.19 @@ -38,7 +31,7 @@
    1.20      @Compare
    1.21      public String testDemoStaticCalculator() throws IOException {
    1.22          InputStream is = getClass().getResourceAsStream("demo.static.calculator-0.3-SNAPSHOT.jar");
    1.23 -        Archive zip = Archive.createZip(is);
    1.24 +        ZipArchive zip = ZipArchive.createZip(is);
    1.25          return zip.toString();
    1.26      }
    1.27      
    1.28 @@ -46,115 +39,4 @@
    1.29      public static Object[] create() {
    1.30          return VMTest.create(ZipCompatibilityTest.class);
    1.31      }
    1.32 -    
    1.33 -    private static final class Archive {
    1.34 -
    1.35 -        private final Map<String, byte[]> entries = new LinkedHashMap<>();
    1.36 -
    1.37 -        public static Archive createZip(InputStream is) throws IOException {
    1.38 -            Archive a = new Archive();
    1.39 -            readZip(is, a);
    1.40 -            return a;
    1.41 -        }
    1.42 -
    1.43 -        /**
    1.44 -         * Registers entry name and data
    1.45 -         */
    1.46 -        final void register(String entry, InputStream is) throws IOException {
    1.47 -            ByteArrayOutputStream os = new ByteArrayOutputStream();
    1.48 -            for (;;) {
    1.49 -                int ch = is.read();
    1.50 -                if (ch == -1) {
    1.51 -                    break;
    1.52 -                }
    1.53 -                os.write(ch);
    1.54 -            }
    1.55 -            os.close();
    1.56 -
    1.57 -            entries.put(entry, os.toByteArray());
    1.58 -        }
    1.59 -
    1.60 -        @Override
    1.61 -        public int hashCode() {
    1.62 -            return entries.hashCode();
    1.63 -        }
    1.64 -
    1.65 -        @Override
    1.66 -        public boolean equals(Object obj) {
    1.67 -            if (obj == null) {
    1.68 -                return false;
    1.69 -            }
    1.70 -            if (getClass() != obj.getClass()) {
    1.71 -                return false;
    1.72 -            }
    1.73 -            final Archive other = (Archive) obj;
    1.74 -            if (!Objects.deepEquals(this.entries, other.entries)) {
    1.75 -                return false;
    1.76 -            }
    1.77 -            return true;
    1.78 -        }
    1.79 -
    1.80 -        @Override
    1.81 -        public String toString() {
    1.82 -            StringBuilder sb = new StringBuilder();
    1.83 -            for (Map.Entry<String, byte[]> en : entries.entrySet()) {
    1.84 -                String string = en.getKey();
    1.85 -                byte[] bs = en.getValue();
    1.86 -
    1.87 -                sb.append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
    1.88 -            }
    1.89 -            return sb.toString();
    1.90 -        }
    1.91 -
    1.92 -        public void assertEquals(Archive zip, String msg) {
    1.93 -            boolean ok = true;
    1.94 -
    1.95 -            StringBuilder sb = new StringBuilder();
    1.96 -            sb.append(msg);
    1.97 -            for (Map.Entry<String, byte[]> en : entries.entrySet()) {
    1.98 -                String string = en.getKey();
    1.99 -                byte[] bs = en.getValue();
   1.100 -
   1.101 -                byte[] other = zip.entries.get(string);
   1.102 -
   1.103 -                sb.append("\n");
   1.104 -
   1.105 -                if (other == null) {
   1.106 -                    sb.append("EXTRA ").append(string).append(" = ").append(Arrays.toString(bs));
   1.107 -                    ok = false;
   1.108 -                    continue;
   1.109 -                }
   1.110 -                if (Arrays.equals(bs, other)) {
   1.111 -                    sb.append("OK    ").append(string);
   1.112 -                    continue;
   1.113 -                } else {
   1.114 -                    sb.append("DIFF  ").append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
   1.115 -                    sb.append("    TO").append(string).append(" = ").append(Arrays.toString(other)).append("\n");
   1.116 -                    ok = false;
   1.117 -                    continue;
   1.118 -                }
   1.119 -            }
   1.120 -            for (Map.Entry<String, byte[]> entry : zip.entries.entrySet()) {
   1.121 -                String string = entry.getKey();
   1.122 -                if (entries.get(string) == null) {
   1.123 -                    sb.append("MISS  ").append(string).append(" = ").append(Arrays.toString(entry.getValue()));
   1.124 -                    ok = false;
   1.125 -                }
   1.126 -            }
   1.127 -            if (!ok) {
   1.128 -                assert false : sb.toString();
   1.129 -            }
   1.130 -        }
   1.131 -        public static void readZip(InputStream is, Archive data) throws IOException {
   1.132 -            ZipInputStream zip = new ZipInputStream(is);
   1.133 -            for (;;) {
   1.134 -                ZipEntry en = zip.getNextEntry();
   1.135 -                if (en == null) {
   1.136 -                    return;
   1.137 -                }
   1.138 -                data.register(en.getName(), zip);
   1.139 -            }
   1.140 -        }
   1.141 -    }
   1.142 -    
   1.143  }