Created
January 14, 2018 03:17
-
-
Save masa-x/bd261a6e1c46dd51f84724ce4db0451c to your computer and use it in GitHub Desktop.
Withdrawal_test.go 機能追加前
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package usecase | |
import ( | |
"testing" | |
"../testutil" | |
) | |
// 正常系のテスト | |
func TestWithdrawal(t *testing.T){ | |
// 準備 | |
outputBoundary := createDummyOutputBoundary() | |
dataAccessor := createDummyDataAccessor(200) | |
dummyInput := make(map[string]string) | |
dummyInput["amount_of_money"] = "100" | |
// 実行 | |
testee := CreateWithdrawal(outputBoundary, dataAccessor) | |
testee.Input(dummyInput) | |
// テスト | |
// 実行が成功し、amount of money に指定した分だけ残高が減っていること | |
dataSource := outputBoundary.getDataSource() | |
testutil.Compare(t, len(dataSource), 4) | |
testutil.Compare(t, dataSource["result"], "Success") | |
testutil.Compare(t, dataSource["process"], "Withdrawal") | |
testutil.Compare(t, dataSource["amount_of_money"], "100") | |
testutil.Compare(t, dataSource["balance"], "100") | |
testutil.Compare(t, dataAccessor.GetBalance().Value(), 100) | |
} | |
// 異常系、誤った値を入力した場合 | |
func TestWithdrawal_InvalidValue(t *testing.T){ | |
// 準備 | |
outputBoundary := createDummyOutputBoundary() | |
dataAccessor := createDummyDataAccessor(200) | |
dummyInput := make(map[string]string) | |
dummyInput["amount_of_money"] = "abc" | |
// 実行 | |
testee := CreateWithdrawal(outputBoundary, dataAccessor) | |
testee.Input(dummyInput) | |
// テスト | |
// 実行が失敗し、残高が変わっていないこと | |
dataSource := outputBoundary.getDataSource() | |
testutil.Compare(t, len(dataSource), 3) | |
testutil.Compare(t, dataSource["result"], "Failed") | |
testutil.Compare(t, dataSource["process"], "Withdrawal") | |
testutil.Compare(t, dataSource["amount_of_money"], "abc") | |
testutil.Compare(t, dataAccessor.GetBalance().Value(), 200) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment