OSDN Git Service

ユニットテスト下請け修正
authorOlyutorskii <olyutorskii@users.osdn.me>
Mon, 2 Dec 2013 17:31:20 +0000 (02:31 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Mon, 2 Dec 2013 17:31:20 +0000 (02:31 +0900)
src/test/java/testdata/CnvAssert.java
src/test/java/testdata/DebugOutputStream.java
src/test/java/testdata/TestDriver.java

index 1932e57..1458c9b 100644 (file)
@@ -17,7 +17,7 @@ import jp.sfjp.mikutoga.pmd2xml.Pmd2XmlConv;
 import static org.junit.Assert.*;
 
 /**
- *
+ * ファイル変換処理のユニットテスト下請け諸々。
  */
 public class CnvAssert {
 
@@ -30,7 +30,7 @@ public class CnvAssert {
      * @return テンポラリファイル
      * @throws IOException エラー
      */
-    public static File openTempFile() throws IOException{
+    private static File openTempFile() throws IOException{
         File file = File.createTempFile("pmd2xml", null);
         file.deleteOnExit();
         return file;
@@ -43,10 +43,9 @@ public class CnvAssert {
      * @param expPmdResource PMDリソース名
      * @throws Exception エラー
      */
-    public static void assertXml2Pmd(
-            Class<?> klass,
-            String xmlResource,
-            String expPmdResource )
+    public static void assertXml2Pmd(Class<?> klass,
+                                       String xmlResource,
+                                       String expPmdResource )
             throws Exception{
         InputStream xmlis =
                 klass.getResourceAsStream(xmlResource);
@@ -81,34 +80,28 @@ public class CnvAssert {
      * @param expXmlResource XMLリソース名
      * @throws Exception エラー
      */
-    public static void assertPmd2Xml(
-            Class<?> klass,
-            String pmdResource,
-            String expXmlResource )
+    public static void assertPmd2Xml(Class<?> klass,
+                                       String pmdResource,
+                                       String expXmlResource )
             throws Exception{
-        InputStream pmdis =
-                klass.getResourceAsStream(pmdResource);
-        assertNotNull(pmdis);
-        pmdis = new BufferedInputStream(pmdis);
-
-        File destFile = openTempFile();
-        OutputStream destOut;
-        destOut = new FileOutputStream(destFile);
-        destOut = new BufferedOutputStream(destOut);
-
-        Pmd2XmlConv converter = new Pmd2XmlConv();
-        converter.setInType(ModelFileType.PMD);
-        converter.setOutType(ModelFileType.XML_101009);
-        converter.setNewline("\n");
-        converter.setGenerator(null);
-
-        converter.convert(pmdis, destOut);
-
-        pmdis.close();
-        destOut.close();
-
-        assertSameFile(klass, expXmlResource, destFile);
+        assertPmd2Xml(klass, pmdResource, expXmlResource,
+                      ModelFileType.XML_101009 );
+        return;
+    }
 
+    /**
+     * PMDリソースをXMLに変換した結果がXMLリソースに等しいと表明する。
+     * @param klass リソース元クラス
+     * @param pmdResource PMDリソース名
+     * @param expXmlResource XMLリソース名
+     * @throws Exception エラー
+     */
+    public static void assertPmd2Xml13(Class<?> klass,
+                                         String pmdResource,
+                                         String expXmlResource )
+            throws Exception{
+        assertPmd2Xml(klass, pmdResource, expXmlResource,
+                      ModelFileType.XML_130128 );
         return;
     }
 
@@ -117,12 +110,13 @@ public class CnvAssert {
      * @param klass リソース元クラス
      * @param pmdResource PMDリソース名
      * @param expXmlResource XMLリソース名
+     * @param type XML種別
      * @throws Exception エラー
      */
-    public static void assertPmd2Xml13(
-            Class<?> klass,
-            String pmdResource,
-            String expXmlResource )
+    private static void assertPmd2Xml(Class<?> klass,
+                                       String pmdResource,
+                                       String expXmlResource,
+                                       ModelFileType type )
             throws Exception{
         InputStream pmdis =
                 klass.getResourceAsStream(pmdResource);
@@ -136,7 +130,7 @@ public class CnvAssert {
 
         Pmd2XmlConv converter = new Pmd2XmlConv();
         converter.setInType(ModelFileType.PMD);
-        converter.setOutType(ModelFileType.XML_130128);
+        converter.setOutType(type);
         converter.setNewline("\n");
         converter.setGenerator(null);
 
@@ -157,10 +151,8 @@ public class CnvAssert {
      * @param resFile ファイル
      * @throws IOException 入力エラー
      */
-    public static void assertSameFile(
-            Class<?> klass,
-            String resourceName,
-            File resFile )
+    public static void assertSameFile(Class<?> klass, String resourceName,
+                                        File resFile )
             throws IOException{
         InputStream expis =
                 klass.getResourceAsStream(resourceName);
@@ -197,12 +189,13 @@ public class CnvAssert {
             try{
                 assertEquals(expCh, resCh);
             }catch(AssertionError e){
-                System.err.println("offset=" + offset);
+                System.err.println("unmatch stream:offset=" + offset);
                 throw e;
             }
             offset++;
 
             if(expCh < 0) break;
+            if(resCh < 0) break;
         }
 
         return;
index 535f6d6..3b83b82 100644 (file)
@@ -12,7 +12,7 @@ import java.io.OutputStream;
 public class DebugOutputStream extends OutputStream{
 
     private final OutputStream os;
-    private long offset = 0L;
+    private long dumpedBytes = 0L;
 
 
     /**
@@ -30,6 +30,7 @@ public class DebugOutputStream extends OutputStream{
      * デバッガ用監視場所。
      */
     private void before(){
+        assert true;
         return;
     }
 
@@ -37,7 +38,8 @@ public class DebugOutputStream extends OutputStream{
      * デバッガ用監視場所。
      */
     private void after(){
-        this.offset++;
+        assert true;
+        this.dumpedBytes++;
         return;
     }
 
index 8b4a952..eb0fa09 100644 (file)
@@ -7,17 +7,16 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 /**
  * 使い捨てテスト用ドライバ。
  */
 public class TestDriver {
 
-    static{
-        assert Test.class != null;
-    }
-
     @BeforeClass
     public static void setUpClass() {
     }
@@ -36,12 +35,16 @@ public class TestDriver {
 
     /**
      * 使い捨てテスト本体。
-     * <p>ã\83\86ã\82¹ã\83\88ã\81\8cçµ\82ã\82\8fã\81£ã\81\9fã\82\89å¿\85ã\81\9aå\85\83ã\81«æ\88»ã\81\97ã\81¦
-     * アノテーション"Test"をコメントアウトするように
+     * <p>ã\83\86ã\82¹ã\83\88ã\82\92è¡\8cã\81\86æ\99\82ã\81¯
+     * アノテーション"Ignore"をコメントアウト
      * @throws Exception テスト失敗
      */
-    //@Test
+    @Test
+    @Ignore
     public void main() throws Exception{
+        assertTrue(true);
+//        fail();
+        return;
     }
 
 }