package jp.terasoluna.fw.file.dao;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
/**
* {@link jp.terasoluna.fw.file.dao.FileException} クラスのテスト。
* <p>
* <h4>【クラスの概要】</h4> ファイルアクセス機能で発生する例外をラップするRuntimeException
* <p>
* @see jp.terasoluna.fw.file.dao.FileException
*/
public class FileExceptionTest {
/**
* testFileExceptionException01() <br>
* <br>
* (正常系) <br>
* 観点:E <br>
* <br>
* 入力値:(引数) e:Exceptionクラスのインスタンス<br>
* <br>
* 期待値:(状態変化) FileException.cause:引数eと同じオブジェクト。<br>
* (状態変化) FileException.fileName:nullが設定<br>
* <br>
* コンストラクタの引数で受け取ったExceptionをラップすることを確認する。<br>
* 正常ケース <br>
* @throws Exception このメソッドで発生した例外
*/
@Test
public void testFileExceptionException01() throws Exception {
// テスト対象のインスタンス化
// コンストラクタの試験なので、不要
// 引数の設定
Exception e = new Exception();
// 前提条件の設定
// なし
// テスト実施
FileException fe = new FileException(e);
// 返却値の確認
// なし
// 状態変化の確認
assertSame(e, fe.getCause());
assertNull(ReflectionTestUtils.getField(fe, "fileName"));
}
/**
* testFileExceptionExceptionString01() <br>
* <br>
* (正常系) <br>
* 観点:E <br>
* <br>
* 入力値:(引数) e:not null<br>
* Exceptionクラスのインスタンス<br>
* (引数) fileName:not null<br>
* 空Stringクラスのインスタンス<br>
* <br>
* 期待値:(状態変化) FileException.fileName:引数filenameと同じオブジェクト<br>
* (状態変化) FileException.cause:引数eと同じオブジェクト。<br>
* <br>
* コンストラクタの引数で受け取ったExceptionをラップすることを確認する。<br>
* fileNameが属性に設定されることを確認する。 <br>
* @throws Exception このメソッドで発生した例外
*/
@Test
public void testFileExceptionExceptionString01() throws Exception {
// テスト対象のインスタンス化
// コンストラクタの試験なので、不要
// 引数の設定
Exception e = new Exception();
String fileName = new String();
// 前提条件の設定
// なし
// テスト実施
FileException fe = new FileException(e, fileName);
// 返却値の確認
// なし
// 状態変化の確認
assertSame(fileName, ReflectionTestUtils.getField(fe, "fileName"));
assertSame(e, fe.getCause());
}
/**
* testFileExceptionString01() <br>
* <br>
* (正常系) <br>
* 観点:E <br>
* <br>
* 入力値:(引数) message:not null<br>
* 空のStringインスタンス<br>
* <br>
* 期待値:(状態変化) FileException.detailMessage: 引数StringObjectと同じStringオブジェクト<br>
* (状態変化) FileException.fileName:null<br>
* <br>
* コンストラクタ引数に例外メッセージを設定する。<br>
* 例外オブジェクト生成後にメッセージが格納されていることを確認する。 <br>
* @throws Exception このメソッドで発生した例外
*/
@Test
public void testFileExceptionString01() throws Exception {
// テスト対象のインスタンス化
// コンストラクタの試験なので、不要
// 引数の設定
String message = new String();
// 前提条件の設定
// なし
// テスト実施
FileException fe = new FileException(message);
// 返却値の確認
// なし
// 状態変化の確認
assertSame(message, ReflectionTestUtils.getField(fe, "detailMessage"));
assertNull(ReflectionTestUtils.getField(fe, "fileName"));
}
/**
* testFileExceptionStringString01() <br>
* <br>
* (正常系) <br>
* 観点:E <br>
* <br>
* 入力値:(引数) message:not null<br>
* 空のStringインスタンス<br>
* (引数) fileName:not null<br>
* 空のStringインスタンス<br>
* <br>
* 期待値:(状態変化) FileException.detailMessage: 引数StringObjectと同じオブジェクト。<br>
* (状態変化) FileException.fileName:引数filenameと同じオブジェクト<br>
* <br>
* コンストラクタ引数に例外メッセージを設定する。<br>
* 例外オブジェクト生成後にメッセージが格納されていることを確認する。<br>
* fileNameが属性に設定されることを確認する。 <br>
* @throws Exception このメソッドで発生した例外
*/
@Test
public void testFileExceptionStringString01() throws Exception {
// テスト対象のインスタンス化
// コンストラクタの試験なので、不要
// 引数の設定
String message = new String();
String fileName = new String();
// 前提条件の設定
// なし
// テスト実施
FileException fe = new FileException(message, fileName);
// 返却値の確認
// なし
// 状態変化の確認
assertSame(message, ReflectionTestUtils.getField(fe, "detailMessage"));
assertSame(fileName, ReflectionTestUtils.getField(fe, "fileName"));
}
/**
* testFileExceptionStringException01() <br>
* <br>
* (正常系) <br>
* 観点:E <br>
* <br>
* 入力値:(引数) message:not null<br>
* 空のStringインスタンス<br>
* (引数) e:not null<br>
* Exceptionクラスのインスタンス<br>
* <br>
* 期待値:(状態変化) FileException.detailMessage:引数stringObjectと同じオブジェクト。<br>
* (状態変化) FileException.cause:引数eと同じオブジェクト<br>
* (状態変化) FileException.fileName:null<br>
* <br>
* コンストラクタ引数に例外メッセージを設定する。<br>
* 例外オブジェクト生成後にメッセージが格納されていることを確認する。<br>
* messageが属性に設定されることを確認する。 <br>
* @throws Exception このメソッドで発生した例外
*/
@Test
public void testFileExceptionStringException01() throws Exception {
// テスト対象のインスタンス化
// コンストラクタの試験なので、不要
// 引数の設定
Exception e = new Exception();
String message = new String();
// 前提条件の設定
// なし
// テスト実施
FileException fe = new FileException(message, e);
// 返却値の確認
// なし
// 状態変化の確認
assertSame(message, ReflectionTestUtils.getField(fe, "detailMessage"));
assertNull(ReflectionTestUtils.getField(fe, "fileName"));
assertSame(e, ReflectionTestUtils.getField(fe, "cause"));
}
/**
* testFileExceptionStringExceptionString01() <br>
* <br>
* (正常系) <br>
* 観点:E <br>
* <br>
* 入力値:(引数) message:not null<br>
* 空のStringインスタンス<br>
* (引数) e:not null<br>
* Exceptionクラスのインスタンス<br>
* (引数) fileName:not null<br>
* 空のStringインスタンス<br>
* <br>
* 期待値:(状態変化) FileException.detailMessage:引数stringObjectと 同じオブジェクト。<br>
* (状態変化) FileException.cause:引数eと同じオブジェクト<br>
* (状態変化) FileException.fileName:引数filenameと同じオブジェクト<br>
* <br>
* コンストラクタの引数で受け取ったExceptionをラップすることを確認する。<br>
* コンストラクタ引数に例外メッセージを設定する。<br>
* 例外オブジェクト生成後にメッセージが格納されていることを確認する。<br>
* fileNameが属性に設定されることを確認する。 <br>
* @throws Exception このメソッドで発生した例外
*/
@Test
public void testFileExceptionStringExceptionString01() throws Exception {
// テスト対象のインスタンス化
// コンストラクタの試験なので、不要
// 引数の設定
Exception e = new Exception();
String message = new String();
String fileName = new String();
// 前提条件の設定
// なし
// テスト実施
FileException fe = new FileException(message, e, fileName);
// 返却値の確認
// なし
// 状態変化の確認
assertSame(message, ReflectionTestUtils.getField(fe, "detailMessage"));
assertSame(fileName, ReflectionTestUtils.getField(fe, "fileName"));
assertSame(e, ReflectionTestUtils.getField(fe, "cause"));
}
/**
* testGetFileName01() <br>
* <br>
* (正常系) <br>
* 観点:F <br>
* <br>
* 入力値:(状態) fileName:not null<br>
* 空のStringインスタンス<br>
* <br>
* 期待値:(戻り値) String:前提条件のfilenameと同じオブジェクト<br>
* <br>
* 属性が正しく取得できることを確認する。 <br>
* @throws Exception このメソッドで発生した例外
*/
@Test
public void testGetFileName01() throws Exception {
// テスト対象のインスタンス化
FileException fe = new FileException(new String());
// 引数の設定
// なし
// 前提条件の設定
String fileName = new String();
ReflectionTestUtils.setField(fe, "fileName", fileName);
// テスト実施
String result = fe.getFileName();
// 返却値の確認
assertSame(fileName, result);
// 状態変化の確認
// なし
}
}