8163431: probeContentType/Basic.java fails after changes for JDK-8146215
authorbpb
Tue, 09 Aug 2016 07:43:48 -0700
changeset 40249 c164790b79f9
parent 40238 4d2a15091124
child 40250 e645cab45a32
8163431: probeContentType/Basic.java fails after changes for JDK-8146215 Summary: Allow multiple legal MIME type interpretations for certain extensions. Reviewed-by: chegar
jdk/test/java/nio/file/Files/probeContentType/Basic.java
--- a/jdk/test/java/nio/file/Files/probeContentType/Basic.java	Wed Jul 05 22:04:04 2017 +0200
+++ b/jdk/test/java/nio/file/Files/probeContentType/Basic.java	Tue Aug 09 07:43:48 2016 -0700
@@ -95,7 +95,7 @@
         return 0;
     }
 
-    static int checkContentTypes(String[] extensions, String[] expectedTypes)
+    static int checkContentTypes(String[] extensions, String[][] expectedTypes)
         throws IOException {
         if (extensions.length != expectedTypes.length) {
             System.err.println("Parameter array lengths differ");
@@ -113,9 +113,24 @@
                             + " cannot be determined");
                     failures++;
                 } else {
-                    if (!type.equals(expectedTypes[i])) {
-                        System.err.println("Content type: " + type
-                                + "; expected: " + expectedTypes[i]);
+                    boolean isTypeFound = false;
+                    for (String s : expectedTypes[i]) {
+                        if (type.equals(s)) {
+                            isTypeFound = true;
+                            break;
+                        }
+                    }
+                    if (!isTypeFound) {
+                        System.err.printf("Content type: %s; expected: ", type);
+                        int j = 0;
+                        for (String s : expectedTypes[i]) {
+                            if (j++ == 0) {
+                                System.err.printf("%s", s);
+                            } else {
+                                System.err.printf(", or %s", s);
+                            }
+                        }
+                        System.err.println();
                         failures++;
                     }
                 }
@@ -159,11 +174,24 @@
 
         // Verify that certain media extensions are mapped to the correct type.
         String[] extensions = new String[]{
-            "aac", "flac", "jpg", "mp3", "mp4", "pdf", "png", "webm"
+            "aac",
+            "flac",
+            "jpg",
+            "mp3",
+            "mp4",
+            "pdf",
+            "png",
+            "webm"
         };
-        String[] expectedTypes = new String[]{
-            "audio/aac", "audio/flac", "image/jpeg", "audio/mpeg",
-            "video/mp4", "application/pdf", "image/png", "video/webm"
+        String[][] expectedTypes = new String[][] {
+            {"audio/aac", "audio/x-aac"},
+            {"audio/flac", "audio/x-flac"},
+            {"image/jpeg"},
+            {"audio/mpeg"},
+            {"video/mp4"},
+            {"application/pdf"},
+            {"image/png"},
+            {"video/webm"}
         };
         failures += checkContentTypes(extensions, expectedTypes);