/*
 * DirectoryNotEmptyExceptionTest 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>DirectoryNotEmptyException</code>クラスの機能試験クラス。
 *
 * @author  佐藤隆之. 
 * @version $Revision: 1.1.1.1 $, $Date: 2010-10-16 00:03:45 $
 */
public class DirectoryNotEmptyExceptionTest 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(DirectoryNotEmptyExceptionTest.class, (args.length == 0) ? null : args[0]);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /* -- test case -- */

  public void constructor_path()
  {
    MSG("通常の操作の場合");

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

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

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

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

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

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

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

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

    try {
      throw new DirectoryNotEmptyException("aaa/bbb");
    } catch (Exception e) {
      EQUAL(e.toString(), "ts.util.file.DirectoryNotEmptyException: The directory is not empty: aaa/bbb");
    }
  }

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

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

    try {
      throw new DirectoryNotEmptyException("aaa/bbb", null);
    } catch (Exception e) {
      EQUAL(e.toString(), "ts.util.file.DirectoryNotEmptyException: The directory is not empty: aaa/bbb");
    }
  }
}
