OSDN Git Service

コンフィグ読み込みテストケース追加
authoryukihane <yukihane.feather@gmail.com>
Tue, 23 Aug 2011 04:57:38 +0000 (13:57 +0900)
committeryukihane <yukihane.feather@gmail.com>
Tue, 23 Aug 2011 04:57:38 +0000 (13:57 +0900)
frontend/src/yukihane/inqubus/Main.java [new file with mode: 0644]
frontend/src/yukihane/inqubus/config/Config.java [moved from frontend/src/yukihane/inqubus/conifg/Config.java with 92% similarity]
frontend/src/yukihane/inqubus/config/Properties.java [moved from frontend/src/yukihane/inqubus/conifg/Properties.java with 96% similarity]
frontend/src/yukihane/inqubus/gui/MainFrame.java
frontend/test/testdata/inqubus_ng.xml [new file with mode: 0644]
frontend/test/testdata/inqubus_ok.xml [new file with mode: 0644]
frontend/test/yukihane/inqubus/config/PropertiesTest.java

diff --git a/frontend/src/yukihane/inqubus/Main.java b/frontend/src/yukihane/inqubus/Main.java
new file mode 100644 (file)
index 0000000..4544bc7
--- /dev/null
@@ -0,0 +1,19 @@
+package yukihane.inqubus;
+
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+
+/**
+ * いんきゅばす起動クラス.
+ * @author yuki
+ */
+public class Main {
+
+    public static void main(String[] args) {
+        final FileSystem fileSystem = FileSystems.getDefault();
+        final Path path = fileSystem.getPath("inqubus.xml");
+        System.out.println(path.toAbsolutePath());
+
+    }
+}
@@ -1,7 +1,8 @@
-package yukihane.inqubus.conifg;
+package yukihane.inqubus.config;
 
 import java.io.File;
 import java.lang.reflect.Field;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.commons.configuration.ConfigurationException;
@@ -132,20 +133,16 @@ public enum Properties {
         this.p_proxy_use = Boolean.toString(use);
     }
 
-    private String getConfigurationName() {
-        return "inqubus.xml";
-    }
-
     private String getPrefix() {
         return "p_";
     }
 
     private Properties() {
         config = new XMLConfiguration();
-        config.setFileName(getConfigurationName());
     }
 
-    public void load() throws ConfigurationException {
+    public void load(String fileName) throws ConfigurationException {
+        config.setFileName(fileName);
         config.load();
     }
 
index d9ab6ca..eed7037 100644 (file)
@@ -22,7 +22,7 @@ import javax.swing.JTextField;
 import javax.swing.TransferHandler;
 import javax.swing.UIManager;
 import javax.swing.UIManager.LookAndFeelInfo;
-import yukihane.inqubus.conifg.Properties;
+import yukihane.inqubus.config.Properties;
 import yukihane.inqubus.model.Target;
 import yukihane.inqubus.model.TargetsTableModel;
 
diff --git a/frontend/test/testdata/inqubus_ng.xml b/frontend/test/testdata/inqubus_ng.xml
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/frontend/test/testdata/inqubus_ok.xml b/frontend/test/testdata/inqubus_ok.xml
new file mode 100644 (file)
index 0000000..e69de29
index 251328e..2b293e6 100644 (file)
@@ -1,14 +1,12 @@
 package yukihane.inqubus.config;
 
-import yukihane.inqubus.conifg.Properties;
+import static org.junit.Assert.*;
+
 import java.lang.reflect.Field;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
 import org.apache.commons.configuration.ConfigurationException;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.*;
 
 /**
  *
@@ -17,25 +15,36 @@ import static org.junit.Assert.*;
 public class PropertiesTest {
 
     @Test
-    public void test() throws ConfigurationException, IllegalArgumentException, IllegalAccessException {
+    public void testLoadFail() {
+        FileSystem fs = FileSystems.getDefault();
+        System.out.println(fs.getPath(".").toAbsolutePath());
         Properties p = Properties.INSTANCE;
-        p.load();
-        Field[] fields = p.getClass().getDeclaredFields();
-        for(Field f: fields){
-            f.setAccessible(true);
-            System.out.println(f.get(p));
+        try {
+            p.load("test/testdata/error.xml");
+            fail("ファイルが存在しないので読み込みに失敗するはず");
+        } catch (ConfigurationException ex) {
         }
-    }
-    @Test
-    public void test2() throws ConfigurationException, IllegalArgumentException, IllegalAccessException {
-        Properties p = Properties.INSTANCE;
-        p.load();
-        p.setDbLocation("d_loc");
-        p.save();
-        Field[] fields = p.getClass().getDeclaredFields();
-        for(Field f: fields){
-            f.setAccessible(true);
-            System.out.println(f.get(p));
+        try{
+            p.load("test/testdata/inqubus_test.xml");
+            fail("ファイルが空なので読み込みに失敗するはず");
+        } catch (ConfigurationException ex) {
         }
+//        Field[] fields = p.getClass().getDeclaredFields();
+//        for(Field f: fields){
+//            f.setAccessible(true);
+//            System.out.println(f.get(p));
+//        }
     }
+//    @Test
+//    public void test2() throws ConfigurationException, IllegalArgumentException, IllegalAccessException {
+//        Properties p = Properties.INSTANCE;
+//        p.load("test/testdata/inqubus_test.xml");
+//        p.setDbLocation("d_loc");
+//        p.save();
+//        Field[] fields = p.getClass().getDeclaredFields();
+//        for(Field f: fields){
+//            f.setAccessible(true);
+//            System.out.println(f.get(p));
+//        }
+//    }
 }