OSDN Git Service

パッケージ変更。テスト整備。
[mikutoga/TogaGem.git] / src / test / java / jp / sfjp / mikutoga / bin / parser / TextDecoderTest.java
@@ -1,8 +1,10 @@
 /*
  */
 
 /*
  */
 
-package jp.sourceforge.mikutoga.parser;
+package jp.sfjp.mikutoga.bin.parser;
 
 
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
@@ -91,15 +93,6 @@ public class TextDecoderTest {
     }
 
     /**
     }
 
     /**
-     * Test of prepareBuffer method, of class TextDecoder.
-     */
-    @Test
-    public void testPrepareBuffer() {
-        System.out.println("prepareBuffer");
-        return;
-    }
-
-    /**
      * Test of setChopMode, getChopMode method, of class TextDecoder.
      * @throws Exception
      */
      * Test of setChopMode, getChopMode method, of class TextDecoder.
      * @throws Exception
      */
@@ -138,9 +131,11 @@ public class TextDecoderTest {
         assertDecoded("41:00:42", "A", decoder);
         assertDecoded("00:41:42", "", decoder);
         assertDecoded("41:00:88", "A", decoder);
         assertDecoded("41:00:42", "A", decoder);
         assertDecoded("00:41:42", "", decoder);
         assertDecoded("41:00:88", "A", decoder);
+        assertDecoded("", "", decoder);
 
         decoder.setZeroChopMode(false);
         assertDecoded("41:00:42", "A\u0000B", decoder);
 
         decoder.setZeroChopMode(false);
         assertDecoded("41:00:42", "A\u0000B", decoder);
+        assertDecoded("", "", decoder);
 
         return;
     }
 
         return;
     }
@@ -278,19 +273,25 @@ public class TextDecoderTest {
                                 TextDecoder decoder)
             throws Exception{
         byte[] bdata = byteArray(bin);
                                 TextDecoder decoder)
             throws Exception{
         byte[] bdata = byteArray(bin);
-        assertDecoded(bin, desired, decoder, bdata.length);
+        ByteBuffer bBuf = ByteBuffer.wrap(bdata);
+        assertDecoded(bBuf, desired, decoder);
         return;
     }
 
     public void assertDecoded(String bin, String desired,
                                 TextDecoder decoder, int len)
             throws Exception{
         return;
     }
 
     public void assertDecoded(String bin, String desired,
                                 TextDecoder decoder, int len)
             throws Exception{
-        byte[] bdata;
-
-        bdata = byteArray(bin);
+        byte[] bdata = byteArray(bin);
+        ByteBuffer bBuf = ByteBuffer.wrap(bdata, 0, len);
+        assertDecoded(bBuf, desired, decoder);
+        return;
+    }
 
 
+    public void assertDecoded(ByteBuffer bBuf, String desired,
+                                TextDecoder decoder)
+            throws Exception{
         String result;
         String result;
-        result = decoder.decode(0, bdata, 0, len);
+        result = decoder.decode(bBuf);
 
         assertEquals(desired, result);
 
 
         assertEquals(desired, result);
 
@@ -300,14 +301,13 @@ public class TextDecoderTest {
     public void assertFormatError(String bin,
                                     TextDecoder decoder, int len)
             throws Exception{
     public void assertFormatError(String bin,
                                     TextDecoder decoder, int len)
             throws Exception{
-        byte[] bdata;
-
-        bdata = byteArray(bin);
+        byte[] bdata = byteArray(bin);
+        ByteBuffer bBuf = ByteBuffer.wrap(bdata, 0, len);
 
         try{
 
         try{
-            decoder.decode(0, bdata, 0, len);
+            decoder.decode(bBuf);
             fail();
             fail();
-        }catch(MmdFormatException e){
+        }catch(CharacterCodingException e){
             // OK
         }
 
             // OK
         }