package com.google.code.yanf4j.test.unittest.core.impl;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.google.code.yanf4j.buffer.IoBuffer;
import com.google.code.yanf4j.core.CodecFactory.Encoder;
import com.google.code.yanf4j.core.impl.TextLineCodecFactory;


/**
 * 
 * 
 * 
 * @author boyan
 * 
 * @since 1.0, 2009-12-24 10:33:59
 */

public class TextLineCodecFactoryUnitTest {
    TextLineCodecFactory textLineCodecFactory;


    @Before
    public void setUp() {
        this.textLineCodecFactory = new TextLineCodecFactory();
    }


    @Test
    public void testEncodeNormal() throws Exception {
        Encoder encoder = this.textLineCodecFactory.getEncoder();
        Assert.assertNotNull(encoder);
        IoBuffer buffer = encoder.encode("hello", null);
        Assert.assertNotNull(buffer);
        Assert.assertTrue(buffer.hasRemaining());
        Assert.assertArrayEquals("hello\r\n".getBytes("utf-8"), buffer.array());

    }


    @Test
    public void testEncodeEmpty() throws Exception {
        Encoder encoder = this.textLineCodecFactory.getEncoder();
        Assert.assertNull(encoder.encode(null, null));
        Assert.assertEquals(TextLineCodecFactory.SPLIT, encoder.encode("", null));
    }


    @Test
    public void decodeNormal() throws Exception {
        Encoder encoder = this.textLineCodecFactory.getEncoder();
        Assert.assertNotNull(encoder);
        IoBuffer buffer = encoder.encode("hello", null);

        String str = (String) this.textLineCodecFactory.getDecoder().decode(buffer, null);
        Assert.assertEquals("hello", str);
    }


    @Test
    public void decodeEmpty() throws Exception {
        Assert.assertNull(this.textLineCodecFactory.getDecoder().decode(null, null));
        Assert.assertEquals("", this.textLineCodecFactory.getDecoder().decode(TextLineCodecFactory.SPLIT, null));
    }

}

@@ -301,18 +301,16 @@
 ory;%0D%0A%0D%0A
-%0D%0A
 /**%0D%0A * 
@@ -432,20 +432,17 @@
 Test %7B%0D%0A
-    
+%09
 TextLine
@@ -479,22 +479,17 @@
 ory;%0D%0A%0D%0A
-%0D%0A    
+%09
 @Before%0D
@@ -489,20 +489,17 @@
 Before%0D%0A
-    
+%09
 public v
@@ -513,24 +513,18 @@
 Up() %7B%0D%0A
-        
+%09%09
 this.tex
@@ -576,34 +576,62 @@
 );%0D%0A
-    %7D%0D%0A%0D%0A%0D%0A    
+%09%09TextLineCodecFactory.SPLIT.clear();%0D%0A%09%7D%0D%0A%0D%0A%09
 @Test%0D%0A
-    
+%09
 publ
@@ -673,32 +673,26 @@
 xception %7B%0D%0A
-        
+%09%09
 Encoder enco
@@ -734,32 +734,26 @@
 Encoder();%0D%0A
-        
+%09%09
 Assert.asser
@@ -768,32 +768,26 @@
 (encoder);%0D%0A
-        
+%09%09
 IoBuffer buf
@@ -820,32 +820,26 @@
 o%22, null);%0D%0A
-        
+%09%09
 Assert.asser
@@ -853,32 +853,26 @@
 l(buffer);%0D%0A
-        
+%09%09
 Assert.asser
@@ -898,32 +898,26 @@
 aining());%0D%0A
-        
+%09%09
 Assert.asser
@@ -984,34 +984,23 @@
 %0D%0A%0D%0A
-    
+%09
 %7D%0D%0A%0D%0A
-%0D%0A    
+%09
 @Test%0D%0A
-    
+%09
 publ
@@ -1041,32 +1041,26 @@
 xception %7B%0D%0A
-        
+%09%09
 Encoder enco
@@ -1102,32 +1102,26 @@
 Encoder();%0D%0A
-        
+%09%09
 Assert.asser
@@ -1152,32 +1152,26 @@
 l, null));%0D%0A
-        
+%09%09
 Assert.asser
@@ -1238,34 +1238,23 @@
 );%0D%0A
-    
+%09
 %7D%0D%0A%0D%0A
-%0D%0A    
+%09
 @Test%0D%0A
-    
+%09
 publ
@@ -1296,24 +1296,18 @@
 tion %7B%0D%0A
-        
+%09%09
 Encoder 
@@ -1353,32 +1353,26 @@
 Encoder();%0D%0A
-        
+%09%09
 Assert.asser
@@ -1391,24 +1391,18 @@
 oder);%0D%0A
-        
+%09%09
 IoBuffer
@@ -1445,24 +1445,18 @@
 ll);%0D%0A%0D%0A
-        
+%09%09
 String s
@@ -1527,32 +1527,26 @@
 er, null);%0D%0A
-        
+%09%09
 Assert.asser
@@ -1573,34 +1573,23 @@
 );%0D%0A
-    
+%09
 %7D%0D%0A%0D%0A
-%0D%0A    
+%09
 @Test%0D%0A
-    
+%09
 publ
@@ -1630,24 +1630,18 @@
 tion %7B%0D%0A
-        
+%09%09
 Assert.a
@@ -1715,16 +1715,10 @@
 );%0D%0A
-        
+%09%09
 Asse
@@ -1824,12 +1824,9 @@
 );%0D%0A
-    
+%09
 %7D%0D%0A%0D

Fix TextLineCodecFactoryUnitTest::decodeNormal