/*
 * FileAlreadyExistsExceptionTest class.
 *
 * Copyright (C) 2007 SATOH Takayuki All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package ts.util.file;

import ts.tester.function.coverage.FunctionTester;
import ts.tester.function.print.*;
import java.io.IOException;

/**
 * <code>FileAlreadyExistsException</code>クラスの機能試験クラス。
 *
 * @author  佐藤隆之. 
 * @version $Revision: 1.1.1.1 $, $Date: 2010-10-16 00:03:45 $
 */
public class FileAlreadyExistsExceptionTest extends FunctionTester
{
  public static void main(String[] args)
  {
    try {
      PrinterGroup group = new PrinterGroup();
      group.addPrinter(new ConsolePrinter());
      group.addPrinter(new HtmlPrinter("SATOH Takayuki"));
      setPrinter(group);

      run(FileAlreadyExistsExceptionTest.class, (args.length == 0) ? null : args[0]);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /* -- test case -- */

  public void constructor_path()
  {
    MSG("通常の操作の場合");
    try {
      throw new FileAlreadyExistsException("aaa/bbb.ccc");
    } catch (FileAlreadyExistsException e) {
      EQUAL(e.getPath(), "aaa/bbb.ccc");
      NULL(e.getMessage());
    } catch (Exception e) {
      NG(e);
    }
  }

  public void constructor_path_01()
  {
    MSG("引数がヌルの場合");
    try {
      throw new FileAlreadyExistsException(null);
    } catch (FileAlreadyExistsException e) {
      NULL(e.getPath());
      NULL(e.getMessage());
    } catch (Exception e) {
      NG(e);
    }
  }

  public void constructor_path_msg()
  {
    MSG("通常の操作の場合");
    try {
      throw new FileAlreadyExistsException("aaa/bbb.ccc", "あいうえお");
    } catch (FileAlreadyExistsException e) {
      EQUAL(e.getPath(), "aaa/bbb.ccc");
      EQUAL(e.getMessage(), "あいうえお");
    } catch (Exception e) {
      NG(e);
    }
  }

  public void constructor_path_msg_01()
  {
    MSG("引数がヌルの場合");
    try {
      throw new FileAlreadyExistsException(null, null);
    } catch (FileAlreadyExistsException e) {
      NULL(e.getPath());
      NULL(e.getMessage());
    } catch (Exception e) {
      NG(e);
    }

    try {
      throw new FileAlreadyExistsException("aaa/bbb.ccc", null);
    } catch (FileAlreadyExistsException e) {
      EQUAL(e.getPath(), "aaa/bbb.ccc");
      NULL(e.getMessage());
    } catch (Exception e) {
      NG(e);
    }

    try {
      throw new FileAlreadyExistsException(null, "あかさたな");
    } catch (FileAlreadyExistsException e) {
      NULL(e.getPath());
      EQUAL(e.getMessage(), "あかさたな");
    } catch (Exception e) {
      NG(e);
    }
  }

  public void super_class()
  {
    MSG("IOExceptionを継承しているかどうか");
    try {
      throw new FileAlreadyExistsException("aaa/bbb.ccc", "あいうえお");
    } catch (IOException e) {
      EQUAL(e.getMessage(), "あいうえお");
    } catch (Exception e) {
      NG(e);
    }
  }

  public void _toString()
  {
    MSG("例外メッセージを指定しなかった場合");

    try {
      throw new FileAlreadyExistsException("aaa/bbb");
    } catch (Exception e) {
      EQUAL(e.toString(), "ts.util.file.FileAlreadyExistsException: The file already exists: aaa/bbb");
    }
  }

  public void _toString_1()
  {
    MSG("例外メッセージを指定した場合");

    try {
      throw new FileAlreadyExistsException("aaa/bbb", "ccc");
    } catch (Exception e) {
      EQUAL(e.toString(),
        "ts.util.file.FileAlreadyExistsException: ccc: aaa/bbb");
    }
    try {
      throw new FileAlreadyExistsException("aaa/bbb", null);
    } catch (Exception e) {
      EQUAL(e.toString(), "ts.util.file.FileAlreadyExistsException: The file already exists: aaa/bbb");
    }
  }
}
