]> source.dussan.org Git - jackcess.git/commitdiff
better test format handling
authorJames Ahlborn <jtahlborn@yahoo.com>
Thu, 27 May 2010 12:27:19 +0000 (12:27 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Thu, 27 May 2010 12:27:19 +0000 (12:27 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@470 f203690c-595d-4dc9-a70b-905162fa7fd2

test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java

index d2e326717befdb1354bd4c94faf4bf4563659ad4..44c5544f2729f430dfcafe1ecc5140d2cde63a71 100644 (file)
@@ -4,6 +4,7 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.channels.FileChannel;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
@@ -53,13 +54,32 @@ public class JetFormatTest extends TestCase {
     public String toString() { return _basename; }
   }
 
-  /** Defines currently supported db file formats. */
-  final static FileFormat[] SUPPORTED_FILEFORMATS = 
-    new FileFormat[] {
-    FileFormat.V2000,
-    FileFormat.V2003,
-    FileFormat.V2007,
-  };
+  /** Defines currently supported db file formats.  (can be modified at
+      runtime via the system property
+      "com.healthmarketscience.jackcess.testFormats") */
+  final static FileFormat[] SUPPORTED_FILEFORMATS;
+
+  static {
+    String testFormatStr = System.getProperty("com.healthmarketscience.jackcess.testFormats");
+    Set<FileFormat> testFormats = EnumSet.allOf(FileFormat.class);
+    if((testFormatStr != null) && (testFormatStr.length() > 0)) {
+      testFormats.clear();
+      for(String tmp : testFormatStr.split(",")) {
+        testFormats.add(FileFormat.valueOf(tmp.toUpperCase()));
+      }
+    }
+
+    List<FileFormat> supported = new ArrayList<FileFormat>();
+    for(FileFormat ff : Arrays.asList(FileFormat.V2000, FileFormat.V2003,
+                                      FileFormat.V2007)) {
+      if(!testFormats.contains(ff)) {
+        continue;
+      }
+      supported.add(ff);
+    }
+
+    SUPPORTED_FILEFORMATS = supported.toArray(new FileFormat[0]);
+  }
 
   /**
    * Defines known valid test database files, and their jet format version.
@@ -94,20 +114,8 @@ public class JetFormatTest extends TestCase {
 
     public static List<TestDB> getSupportedForBasename(Basename basename) {
 
-      String testFormatStr = System.getProperty("com.healthmarketscience.jackcess.testFormats");
-      Set<FileFormat> testFormats = EnumSet.allOf(FileFormat.class);
-      if((testFormatStr != null) && (testFormatStr.length() > 0)) {
-        testFormats = EnumSet.noneOf(FileFormat.class);
-        for(String tmp : testFormatStr.split(",")) {
-          testFormats.add(FileFormat.valueOf(tmp.toUpperCase()));
-        }
-      }
-
       List<TestDB> supportedTestDBs = new ArrayList<TestDB>();
       for (FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
-        if(!testFormats.contains(fileFormat)) {
-          continue;
-        }
         supportedTestDBs.add(new TestDB(
                                  getFileForBasename(basename, fileFormat),
                                  fileFormat));