changeset 15321:ef0ba6e50464

8163431: probeContentType/Basic.java fails after changes for JDK-8146215 Summary: Allow multiple legal MIME type interpretations for certain extensions. Reviewed-by: chegar
author bpb
date Tue, 09 Aug 2016 07:43:48 -0700
parents 8c57f4c293bb
children 9287101b5f49
files test/java/nio/file/Files/probeContentType/Basic.java
diffstat 1 files changed, 36 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/nio/file/Files/probeContentType/Basic.java	Tue Aug 09 15:02:27 2016 +0200
+++ b/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);