/*
 * FileFormatTest.java
 * 
 * Author: http://www.hrtdotnet.jp/
 * 
 */

package jp.hrtdotnet.java.text;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import jp.hrtdotnet.java.HTestCase;

/**
 *
 * @version 
 * @author hrtdotnet.jp
 * <br>http://www.hrtdotnet.jp/
 * @since 
 */
public class FileFormatTest extends HTestCase {

    private String[] params1 = new String[]{"あいうえお","け","なにぬねの","と","さ"};
    private String lineSep1 = "\r\n";
    private String expected1 = "あいうえお" + lineSep1 + 
        "かきくけこ" + lineSep1 + 
        "さしすせそ" + lineSep1 + 
        "たちつてと" + lineSep1 + 
        "なにぬねの" + lineSep1 +
        lineSep1 +
        lineSep1;

    private String lineSep2 = "\n";
    private String expected2 = "あいうえお" + lineSep2 + 
        "かきくけこ" + lineSep2 + 
        "さしすせそ" + lineSep2 + 
        "たちつてと" + lineSep2 + 
        "なにぬねの" + lineSep2 +
        lineSep2 +
        lineSep2;

    private String lineSep3 = "\r\n";
    private String expected3 = lineSep3 + 
        "あいうえお" + lineSep3 + 
        "かきくけこ" + lineSep3 + 
        "さしすせそ" + lineSep3 + 
        lineSep3 +
        "たちつてと" + lineSep3 + 
        "なにぬねの";
    
    /* (非 Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
    }

    /* (非 Javadoc)
     * @see junit.framework.TestCase#tearDown()
     */
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    /**
     * {@link jp.hrtdotnet.java.text.FileFormat#FileFormat(java.io.File, java.lang.String)} のためのテスト・メソッド。
     * @throws IOException 
     */
    public void testFileFormat() throws IOException {
        File file = new File(testClassResources.getString("file"));
        String fileCharsetName = testClassResources.getString("fileCharsetName");
        FileFormat format = new FileFormat(file, fileCharsetName);
        assertEquals(expected1,format.format(params1));
        
        try {
            new FileFormat(null, fileCharsetName);
            fail();
        } catch (NullPointerException e) {
        }

        try {
            new FileFormat(file, null);
            fail();
        } catch (NullPointerException e) {
        }

        try {
            new FileFormat(file, "");
            fail();
        } catch (IllegalArgumentException e) {
        }
    
        File file2 = new File(testClassResources.getString("file2"));
        format = new FileFormat(file2, fileCharsetName);
        assertEquals(expected3,format.format(params1));
        
        File directory = new File(testClassResources.getString("directory"));
        try {
            format = new FileFormat(directory, fileCharsetName);
            fail();
        } catch (IOException e) {
        }
    }

    public void testFileFormat2() throws IOException {
        File file = new File(testClassResources.getString("file"));
        String fileCharsetName = testClassResources.getString("fileCharsetName");
        FileFormat format = new FileFormat(file, fileCharsetName, "\n");
        assertEquals(expected2,format.format(params1));

        try {
            new FileFormat(null, fileCharsetName, "\n");
            fail();
        } catch (NullPointerException e) {
        }

        try {
            new FileFormat(file, null, "\n");
            fail();
        } catch (NullPointerException e) {
        }

        try {
            new FileFormat(file, "", "\n");
            fail();
        } catch (IllegalArgumentException e) {
        }
    
        try {
            new FileFormat(file, fileCharsetName, null);
            fail();
        } catch (NullPointerException e) {
        }

        try {
            new FileFormat(file, fileCharsetName, "");
            fail();
        } catch (IllegalArgumentException e) {
        }
    
    
    }
    
    /**
     * {@link jp.hrtdotnet.java.text.FileFormat#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)} のためのテスト・メソッド。
     */
    public void testFormatObjectStringBufferFieldPosition() {
        //不要
    }

    /**
     * {@link jp.hrtdotnet.java.text.FileFormat#parseObject(java.lang.String, java.text.ParsePosition)} のためのテスト・メソッド。
     */
    public void testParseObjectStringParsePosition() {
        //不要
    }

    /**
     * {@link jp.hrtdotnet.java.text.FileFormat#formatToCharacterIterator(java.lang.Object)} のためのテスト・メソッド。
     */
    public void testFormatToCharacterIteratorObject() {
        //不要
    }

    /**
     * {@link jp.hrtdotnet.java.text.FileFormat#parseObject(java.lang.String)} のためのテスト・メソッド。
     */
    public void testParseObjectString() {
        //不要
    }

    /**
     * {@link jp.hrtdotnet.java.text.FileFormat#clone()} のためのテスト・メソッド。
     * @throws IOException 
     * @throws FileNotFoundException 
     * @throws UnsupportedEncodingException 
     */
    public void testClone() throws UnsupportedEncodingException, FileNotFoundException, IOException {
        File file = new File(testClassResources.getString("file"));
        String fileCharsetName = testClassResources.getString("fileCharsetName");
        FileFormat format = new FileFormat(file, fileCharsetName);
        format.clone();
    }

}
