From 3d2503b61965f520d495e0ee6185747bff0aaecd Mon Sep 17 00:00:00 2001 From: Olyutorskii Date: Tue, 3 Dec 2013 02:31:20 +0900 Subject: [PATCH] =?utf8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86?= =?utf8?q?=E3=82=B9=E3=83=88=E4=B8=8B=E8=AB=8B=E3=81=91=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/test/java/testdata/CnvAssert.java | 77 ++++++++++++--------------- src/test/java/testdata/DebugOutputStream.java | 6 ++- src/test/java/testdata/TestDriver.java | 17 +++--- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/test/java/testdata/CnvAssert.java b/src/test/java/testdata/CnvAssert.java index 1932e57..1458c9b 100644 --- a/src/test/java/testdata/CnvAssert.java +++ b/src/test/java/testdata/CnvAssert.java @@ -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; diff --git a/src/test/java/testdata/DebugOutputStream.java b/src/test/java/testdata/DebugOutputStream.java index 535f6d6..3b83b82 100644 --- a/src/test/java/testdata/DebugOutputStream.java +++ b/src/test/java/testdata/DebugOutputStream.java @@ -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; } diff --git a/src/test/java/testdata/TestDriver.java b/src/test/java/testdata/TestDriver.java index 8b4a952..eb0fa09 100644 --- a/src/test/java/testdata/TestDriver.java +++ b/src/test/java/testdata/TestDriver.java @@ -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 { /** * 使い捨てテスト本体。 - *

テストが終わったら必ず元に戻して - * アノテーション"Test"をコメントアウトするように。 + *

テストを行う時は + * アノテーション"Ignore"をコメントアウト。 * @throws Exception テスト失敗 */ - //@Test + @Test + @Ignore public void main() throws Exception{ + assertTrue(true); +// fail(); + return; } } -- 2.11.0