OSDN Git Service

パーサパッケージ名変更
[mikutoga/TogaGem.git] / src / test / java / sample / pmd / DummyMain.java
index 8fdfec4..905fd43 100644 (file)
@@ -13,12 +13,12 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import jp.sourceforge.mikutoga.parser.MmdFormatException;
-import jp.sourceforge.mikutoga.parser.MmdSource;
-import jp.sourceforge.mikutoga.parser.pmd.PmdParser;
+import jp.sfjp.mikutoga.bin.parser.MmdFormatException;
+import jp.sfjp.mikutoga.pmd.parser.PmdParser;
 
 /**
  * パーサ利用のサンプルプログラム。
+ * これはユニットテストではない。
  */
 public class DummyMain {
 
@@ -27,7 +27,28 @@ public class DummyMain {
     private static final DummyHandler handler = new DummyHandler();
 
     static{
-        PMDFILE = "D:\\Test\\test.pmd";
+        PMDFILE =
+                "D:\\Test\\test.pmd";
+    }
+
+    /**
+     * アプリを終了する。
+     * 制御は戻らない。
+     * @param code 終了コード。
+     */
+    private static void exit(int code){
+        System.exit(code);
+        assert false;
+        return;
+    }
+
+    /**
+     * 標準エラー出力にエラー情報を出し改行する。
+     * @param text エラー情報文字列
+     */
+    private static void errprintln(Object text){
+        System.err.println(text);
+        return;
     }
 
     /**
@@ -35,22 +56,21 @@ public class DummyMain {
      * @param fname ファイル名
      * @return 入力ソース
      */
-    private static MmdSource buildSource(String fname){
+    private static InputStream buildSource(String fname){
         File file = new File(fname);
 
         InputStream is;
         try{
             is = new FileInputStream(file);
         }catch(FileNotFoundException e){
-            System.err.println(e);
-            System.exit(1);
+            errprintln(e);
+            exit(1);
             return null;
         }
-        is = new BufferedInputStream(is, BUF_SZ);
 
-        MmdSource source = new MmdSource(is);
+        is = new BufferedInputStream(is, BUF_SZ);
 
-        return source;
+        return is;
     }
 
     /**
@@ -80,7 +100,7 @@ public class DummyMain {
         if(args.length == 1) fname = args[0];
         else                 fname = PMDFILE;
 
-        MmdSource source = buildSource(fname);
+        InputStream source = buildSource(fname);
 
         PmdParser parser = new PmdParser(source);
 
@@ -89,14 +109,14 @@ public class DummyMain {
         try{
             parser.parsePmd();
         }catch(IOException e){
-            System.err.println(e);
-            System.exit(1);
+            errprintln(e);
+            exit(1);
         }catch(MmdFormatException e){
-            System.err.println(e);
-            System.exit(1);
+            errprintln(e);
+            exit(1);
         }
 
-        System.exit(0);
+        exit(0);
 
         return;
     }