diff --git a/accountCreditedDrawdown_test.go b/accountCreditedDrawdown_test.go index c206da59..b9184a5d 100644 --- a/accountCreditedDrawdown_test.go +++ b/accountCreditedDrawdown_test.go @@ -25,24 +25,18 @@ func TestMockAccountCreditedDrawdown(t *testing.T) { func TestDrawdownCreditAccountNumberAlphaNumeric(t *testing.T) { creditDD := mockAccountCreditedDrawdown() creditDD.DrawdownCreditAccountNumber = "®" - - err := creditDD.Validate() - - require.NotNil(t, err) expected := fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, creditDD.DrawdownCreditAccountNumber).Error() - require.Equal(t, expected, err.Error()) + + require.EqualError(t, creditDD.Validate(), expected) } // TestAccountCreditedDrawdownNumberRequired validates AccountCreditedDrawdown is required func TestDrawdownCreditAccountNumberRequired(t *testing.T) { creditDD := mockAccountCreditedDrawdown() creditDD.DrawdownCreditAccountNumber = "" - - err := creditDD.Validate() - - require.NotNil(t, err) expected := fieldError("DrawdownCreditAccountNumber", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + + require.EqualError(t, creditDD.Validate(), expected) } // TestParseAccountCreditedDrawdownWrongLength parses a wrong AccountCreditedDrawdown record length @@ -53,9 +47,8 @@ func TestParseAccountCreditedDrawdownWrongLength(t *testing.T) { err := r.parseAccountCreditedDrawdown() - require.NotNil(t, err) expected := r.parseError(NewTagWrongLengthErr(15, len(r.line))).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestParseAccountCreditedDrawdownReaderParseError parses a wrong AccountCreditedDrawdown reader parse error @@ -63,21 +56,16 @@ func TestParseAccountCreditedDrawdownReaderParseError(t *testing.T) { var line = "{5400}12345678Z" r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - crediDD := mockAccountCreditedDrawdown() - fwm.SetAccountCreditedDrawdown(crediDD) err := r.parseAccountCreditedDrawdown() - require.NotNil(t, err) expected := r.parseError(fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, "12345678Z")).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, "12345678Z")).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestAccountCreditedDrawdownTagError validates AccountCreditedDrawdown tag @@ -87,7 +75,6 @@ func TestAccountCreditedDrawdownTagError(t *testing.T) { err := creditDD.Validate() - require.NotNil(t, err) expected := fieldError("tag", ErrValidTagForType, creditDD.tag).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } diff --git a/accountDebitedDrawdown_test.go b/accountDebitedDrawdown_test.go index e788048d..89227b1e 100644 --- a/accountDebitedDrawdown_test.go +++ b/accountDebitedDrawdown_test.go @@ -26,26 +26,24 @@ func TestMockAccountDebitedDrawdown(t *testing.T) { require.NoError(t, debitDD.Validate(), "mockAccountDebitedDrawdown does not validate and will break other tests") } -// TestADDIdentifierAlphaNumeric validates Name is alphanumeric +// TestADDIdentifierAlphaNumeric validates Identifier is alphanumeric func TestADDIdentifierAlphaNumeric(t *testing.T) { debitDD := mockAccountDebitedDrawdown() debitDD.Identifier = "®" err := debitDD.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, debitDD.Identifier).Error()) } -// TestADDNameAlphaNumeric validates Identifier is alphanumeric +// TestADDNameAlphaNumeric validates Name is alphanumeric func TestADDNameAlphaNumeric(t *testing.T) { debitDD := mockAccountDebitedDrawdown() debitDD.Name = "®" err := debitDD.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, debitDD.Name).Error()) } // TestADDAddressLineOneAlphaNumeric validates AddressLineOne is alphanumeric @@ -55,8 +53,7 @@ func TestADDAddressLineOneAlphaNumeric(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, debitDD.Address.AddressLineOne).Error()) } // TestADDAddressLineTwoAlphaNumeric validates AddressLineTwo is alphanumeric @@ -66,8 +63,7 @@ func TestADDAddressLineTwoAlphaNumeric(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, debitDD.Address.AddressLineTwo).Error()) } // TestADDAddressLineThreeAlphaNumeric validates AddressLineThree is alphanumeric @@ -77,8 +73,7 @@ func TestADDAddressLineThreeAlphaNumeric(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, debitDD.Address.AddressLineThree).Error()) } // TestADDIdentifierRequired validates Identifier is required @@ -88,9 +83,7 @@ func TestADDIdentifierRequired(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - expected := fieldError("Identifier", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error()) } // TestADDNameRequired validates Name is required @@ -100,9 +93,7 @@ func TestADDNameRequired(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - expected := fieldError("Name", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("Name", ErrFieldRequired).Error()) } // TestADDIdentificationRequired validates IdentificationCode is required @@ -112,9 +103,7 @@ func TestADDIdentificationCodeRequired(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - expected := fieldError("IdentificationCode", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error()) } // TestADDIdentificationCodeValid validates IdentificationCode @@ -124,9 +113,7 @@ func TestADDIdentificationCodeValid(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - expected := fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error()) } // TestADDIdentificationCodeBogus validates IdentificationCode if the IdentificationCode is bogus @@ -136,9 +123,7 @@ func TestIdentificationCodeBogus(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - expected := fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error()) } // TestParseAccountDebitedDrawdownWrongLength parses a wrong AccountDebitedDrawdown record length @@ -149,9 +134,7 @@ func TestParseAccountDebitedDrawdownWrongLength(t *testing.T) { err := r.parseAccountDebitedDrawdown() - require.NotNil(t, err) - expected := r.parseError(NewTagWrongLengthErr(181, len(r.line))).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(181, len(r.line))).Error()) } // TestParseAccountDebitedDrawdownReaderParseError parses a wrong AccountDebitedDrawdown reader parse error @@ -159,19 +142,16 @@ func TestParseAccountDebitedDrawdownReaderParseError(t *testing.T) { var line = "{4400}D123456789 debitDD ®ame Address One Address Two Address Three " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - debitDD := mockAccountDebitedDrawdown() - fwm.SetAccountDebitedDrawdown(debitDD) err := r.parseAccountDebitedDrawdown() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "debitDD ®ame")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "debitDD ®ame")).Error() + require.EqualError(t, err, expected) } // TestAccountDebitedDrawdownTagError validates AccountDebitedDrawdown tag @@ -181,6 +161,5 @@ func TestAccountDebitedDrawdownTagError(t *testing.T) { err := debitDD.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, debitDD.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, debitDD.tag).Error()) } diff --git a/actualAmountPaid_test.go b/actualAmountPaid_test.go index 71c35be2..b420b407 100644 --- a/actualAmountPaid_test.go +++ b/actualAmountPaid_test.go @@ -29,8 +29,7 @@ func TestActualAmountPaidAmountRequired(t *testing.T) { err := aap.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Amount", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error()) } // TestActualAmountPaidCurrencyCodeRequired validates ActualAmountPaid CurrencyCode is required @@ -40,8 +39,7 @@ func TestCurrencyCodeRequired(t *testing.T) { err := aap.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("CurrencyCode", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error()) } // TestActualAmountPaidAmountValid validates Amount @@ -51,8 +49,7 @@ func TestActualAmountPaidAmountValid(t *testing.T) { err := aap.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Amount", ErrNonAmount, aap.RemittanceAmount.Amount).Error(), err.Error()) + require.EqualError(t, err, fieldError("Amount", ErrNonAmount, aap.RemittanceAmount.Amount).Error()) } // TestActualAmountPaidCurrencyCodeValid validates Amount @@ -62,8 +59,7 @@ func TestActualAmountPaidCurrencyCodeValid(t *testing.T) { err := aap.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("CurrencyCode", ErrNonCurrencyCode, aap.RemittanceAmount.CurrencyCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, aap.RemittanceAmount.CurrencyCode).Error()) } // TestParseActualAmountPaidWrongLength parses a wrong ActualAmountPaid record length @@ -71,15 +67,10 @@ func TestParseActualAmountPaidWrongLength(t *testing.T) { var line = "{8450}USD1234.56 " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - aap := mockActualAmountPaid() - fwm.SetActualAmountPaid(aap) err := r.parseActualAmountPaid() - require.NotNil(t, err) - expected := NewTagWrongLengthErr(28, len(r.line)) - require.Contains(t, err.Error(), expected.Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(28, len(r.line))).Error()) } // TestParseActualAmountPaidReaderParseError parses a wrong ActualAmountPaid reader parse error @@ -87,19 +78,16 @@ func TestParseActualAmountPaidReaderParseError(t *testing.T) { var line = "{8450}USD1234.56Z " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - aap := mockActualAmountPaid() - fwm.SetActualAmountPaid(aap) err := r.parseActualAmountPaid() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected := r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected = r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) } // TestActualAmountPaidTagError validates ActualAmountPaid tag @@ -109,6 +97,5 @@ func TestActualAmountPaidTagError(t *testing.T) { err := aap.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, aap.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, aap.tag).Error()) } diff --git a/adjustment_test.go b/adjustment_test.go index 98e2b6b0..541f9855 100644 --- a/adjustment_test.go +++ b/adjustment_test.go @@ -32,8 +32,7 @@ func TestAdjustmentReasonCodeValid(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrAdjustmentReasonCode.Error()) + require.EqualError(t, err, fieldError("AdjustmentReasonCode", ErrAdjustmentReasonCode, adj.AdjustmentReasonCode).Error()) } // TestCreditDebitIndicatorValid validates Adjustment CreditDebitIndicator @@ -43,8 +42,7 @@ func TestCreditDebitIndicatorValid(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrCreditDebitIndicator.Error()) + require.EqualError(t, err, fieldError("CreditDebitIndicator", ErrCreditDebitIndicator, adj.CreditDebitIndicator).Error()) } // TestAdjustmentAmountValid validates Adjustment Amount @@ -54,8 +52,7 @@ func TestAdjustmentAmountValid(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + require.EqualError(t, err, fieldError("Amount", ErrNonAmount, adj.RemittanceAmount.Amount).Error()) } // TestAdjustmentCurrencyCodeValid validates Adjustment CurrencyCode @@ -65,8 +62,7 @@ func TestAdjustmentCurrencyCodeValid(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonCurrencyCode.Error()) + require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, adj.RemittanceAmount.CurrencyCode).Error()) } // TestAdjustmentReasonCodeRequired validates Adjustment AdjustmentReasonCode is required @@ -76,8 +72,7 @@ func TestAdjustmentReasonCodeRequired(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AdjustmentReasonCode", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("AdjustmentReasonCode", ErrFieldRequired).Error()) } // TestCreditDebitIndicatorRequired validates Adjustment CreditDebitIndicator is required @@ -87,8 +82,7 @@ func TestCreditDebitIndicatorRequired(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("CreditDebitIndicator", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("CreditDebitIndicator", ErrFieldRequired).Error()) } // TestAdjustmentAmountRequired validates Adjustment Amount is required @@ -98,8 +92,7 @@ func TestAdjustmentAmountRequired(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Amount", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error()) } // TestAdjustmentCurrencyCodeRequired validates Adjustment CurrencyCode is required @@ -109,8 +102,7 @@ func TestAdjustmentCurrencyCodeRequired(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("CurrencyCode", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error()) } // TestParseAdjustmentWrongLength parses a wrong Adjustment record length @@ -121,8 +113,7 @@ func TestParseAdjustmentWrongLength(t *testing.T) { err := r.parseAdjustment() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(174, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(174, len(r.line))).Error()) } // TestParseAdjustmentReaderParseError parses a wrong Adjustment reader parse error @@ -133,13 +124,13 @@ func TestParseAdjustmentReaderParseError(t *testing.T) { err := r.parseAdjustment() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected := r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected = r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) } // TestAdjustmentTagError validates Adjustment tag @@ -149,6 +140,5 @@ func TestAdjustmentTagError(t *testing.T) { err := adj.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, adj.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, adj.tag).Error()) } diff --git a/amountNegotiatedDiscount_test.go b/amountNegotiatedDiscount_test.go index f5af9a4b..2261c3ba 100644 --- a/amountNegotiatedDiscount_test.go +++ b/amountNegotiatedDiscount_test.go @@ -29,8 +29,7 @@ func TestAmountNegotiatedDiscountValid(t *testing.T) { err := nd.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + require.EqualError(t, err, fieldError("Amount", ErrNonAmount, nd.RemittanceAmount.Amount).Error()) } // TestAmountNegotiatedDiscountCurrencyCodeValid validates AmountNegotiatedDiscount CurrencyCode @@ -40,8 +39,7 @@ func TestAmountNegotiatedDiscountCurrencyCodeValid(t *testing.T) { err := nd.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonCurrencyCode.Error()) + require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, nd.RemittanceAmount.CurrencyCode).Error()) } // TestAmountNegotiatedDiscountAmountRequired validates AmountNegotiatedDiscount Amount is required @@ -51,8 +49,7 @@ func TestAmountNegotiatedDiscountRequired(t *testing.T) { err := nd.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Amount", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error()) } // TestAmountNegotiatedDiscountCurrencyCodeRequired validates AmountNegotiatedDiscount CurrencyCode is required @@ -62,8 +59,7 @@ func TestAmountNegotiatedDiscountCurrencyCodeRequired(t *testing.T) { err := nd.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("CurrencyCode", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error()) } // TestParseAmountNegotiatedDiscountWrongLength parses a wrong AmountNegotiatedDiscount record length @@ -74,8 +70,7 @@ func TestParseAmountNegotiatedDiscountWrongLength(t *testing.T) { err := r.parseAmountNegotiatedDiscount() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(28, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(28, len(r.line))).Error()) } // TestParseAmountNegotiatedDiscountReaderParseError parses a wrong AmountNegotiatedDiscount reader parse error @@ -86,13 +81,13 @@ func TestParseAmountNegotiatedDiscountReaderParseError(t *testing.T) { err := r.parseAmountNegotiatedDiscount() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected := r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected = r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) } // TestAmountNegotiatedDiscountTagError validates AmountNegotiatedDiscount tag @@ -102,6 +97,5 @@ func TestAmountNegotiatedDiscountTagError(t *testing.T) { err := nd.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, nd.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, nd.tag).Error()) } diff --git a/amount_test.go b/amount_test.go index aa9bf139..38316085 100644 --- a/amount_test.go +++ b/amount_test.go @@ -28,8 +28,7 @@ func TestAmountValid(t *testing.T) { err := a.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + require.EqualError(t, err, fieldError("Amount", ErrNonAmount, a.Amount).Error()) } // TestAmountRequired validates Amount is required @@ -39,8 +38,7 @@ func TestAmountRequired(t *testing.T) { err := a.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Amount", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error()) } // TestParseAmountWrongLength parses a wrong Amount record length @@ -51,8 +49,7 @@ func TestParseAmountWrongLength(t *testing.T) { err := r.parseAmount() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(18, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(18, len(r.line))).Error()) } // TestParseAmountReaderParseError parses a wrong Amount reader parse error @@ -63,13 +60,13 @@ func TestParseAmountReaderParseError(t *testing.T) { err := r.parseAmount() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected := r.parseError(fieldError("Amount", ErrNonAmount, "00000Z030022")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + expected = r.parseError(fieldError("Amount", ErrNonAmount, "00000Z030022")).Error() + require.EqualError(t, err, expected) } // TestAmountTagError validates Amount tag @@ -79,6 +76,5 @@ func TestAmountTagError(t *testing.T) { err := a.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, a.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, a.tag).Error()) } diff --git a/beneficiaryCustomer_test.go b/beneficiaryCustomer_test.go index 0896f010..742bf2a5 100644 --- a/beneficiaryCustomer_test.go +++ b/beneficiaryCustomer_test.go @@ -33,8 +33,7 @@ func TestBeneficiaryCustomerSwiftFieldTagAlphaNumeric(t *testing.T) { err := bc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("SwiftFieldTag", ErrNonAlphanumeric, bc.CoverPayment.SwiftFieldTag).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftFieldTag", ErrNonAlphanumeric, bc.CoverPayment.SwiftFieldTag).Error()) } // TestBeneficiaryCustomerSwiftLineOneAlphaNumeric validates BeneficiaryCustomer SwiftLineOne is alphanumeric @@ -44,8 +43,7 @@ func TestBeneficiaryCustomerSwiftLineOneAlphaNumeric(t *testing.T) { err := bc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("SwiftLineOne", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftLineOne", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineOne).Error()) } // TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric validates BeneficiaryCustomer SwiftLineTwo is alphanumeric @@ -55,8 +53,7 @@ func TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric(t *testing.T) { err := bc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("SwiftLineTwo", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftLineTwo", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineTwo).Error()) } // TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric validates BeneficiaryCustomer SwiftLineThree is alphanumeric @@ -66,8 +63,7 @@ func TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric(t *testing.T) { err := bc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("SwiftLineThree", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftLineThree", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineThree).Error()) } // TestBeneficiaryCustomerSwiftLineFourAlphaNumeric validates BeneficiaryCustomer SwiftLineFour is alphanumeric @@ -77,8 +73,7 @@ func TestBeneficiaryCustomerSwiftLineFourAlphaNumeric(t *testing.T) { err := bc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("SwiftLineFour", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftLineFour", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFour).Error()) } // TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric validates BeneficiaryCustomer SwiftLineFive is alphanumeric @@ -88,8 +83,7 @@ func TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric(t *testing.T) { err := bc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("SwiftLineFive", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftLineFive", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFive).Error()) } // TestBeneficiaryCustomerSwiftLineSixAlphaNumeric validates BeneficiaryCustomer SwiftLineSix is alphanumeric @@ -99,8 +93,7 @@ func TestBeneficiaryCustomerSwiftLineSixAlphaNumeric(t *testing.T) { err := sr.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("SwiftLineSix", ErrInvalidProperty, sr.CoverPayment.SwiftLineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftLineSix", ErrInvalidProperty, sr.CoverPayment.SwiftLineSix).Error()) } // TestParseBeneficiaryCustomerWrongLength parses a wrong BeneficiaryCustomer record length @@ -111,8 +104,7 @@ func TestParseBeneficiaryCustomerWrongLength(t *testing.T) { err := r.parseBeneficiaryCustomer() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(186, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(186, len(r.line))).Error()) } // TestParseBeneficiaryCustomerReaderParseError parses a wrong BeneficiaryCustomer reader parse error @@ -123,13 +115,13 @@ func TestParseBeneficiaryCustomerReaderParseError(t *testing.T) { err := r.parseBeneficiaryCustomer() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("SwiftLineOne", ErrNonAlphanumeric, "Swift ®ine One")).Error() + require.EqualError(t, err, expected) } // TestBeneficiaryCustomerTagError validates a BeneficiaryCustomer tag @@ -139,6 +131,5 @@ func TestBeneficiaryCustomerTagError(t *testing.T) { err := bc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, bc.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, bc.tag).Error()) } diff --git a/beneficiaryFI_test.go b/beneficiaryFI_test.go index 12624664..263c6b2a 100644 --- a/beneficiaryFI_test.go +++ b/beneficiaryFI_test.go @@ -33,8 +33,7 @@ func TestBeneficiaryFIIdentificationCodeValid(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error()) } // TestBeneficiaryFIIdentificationCodeFI validates BeneficiaryFI IdentificationCode is an FI code @@ -44,8 +43,7 @@ func TestBeneficiaryFIIdentificationCodeFI(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error()) } // TestBeneficiaryFIIdentifierAlphaNumeric validates BeneficiaryFI Identifier is alphanumeric @@ -55,8 +53,7 @@ func TestBeneficiaryFIIdentifierAlphaNumeric(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Identifier", ErrNonAlphanumeric, bfi.FinancialInstitution.Identifier).Error(), err.Error()) + require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, bfi.FinancialInstitution.Identifier).Error()) } // TestBeneficiaryFINameAlphaNumeric validates BeneficiaryFI Name is alphanumeric @@ -66,8 +63,7 @@ func TestBeneficiaryFINameAlphaNumeric(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Name", ErrNonAlphanumeric, bfi.FinancialInstitution.Name).Error(), err.Error()) + require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, bfi.FinancialInstitution.Name).Error()) } // TestBeneficiaryFIAddressLineOneAlphaNumeric validates BeneficiaryFI AddressLineOne is alphanumeric @@ -77,8 +73,7 @@ func TestBeneficiaryFIAddressLineOneAlphaNumeric(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineOne", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineOne).Error()) } // TestBeneficiaryFIAddressLineTwoAlphaNumeric validates BeneficiaryFI AddressLineTwo is alphanumeric @@ -88,8 +83,7 @@ func TestBeneficiaryFIAddressLineTwoAlphaNumeric(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineTwo", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineTwo).Error()) } // TestBeneficiaryFIAddressLineThreeAlphaNumeric validates BeneficiaryFI AddressLineThree is alphanumeric @@ -99,8 +93,7 @@ func TestBeneficiaryFIAddressLineThreeAlphaNumeric(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineThree", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineThree).Error()) } // TestBeneficiaryFIIdentificationCodeRequired validates BeneficiaryFI IdentificationCode is required @@ -110,8 +103,7 @@ func TestBeneficiaryFIIdentificationCodeRequired(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("IdentificationCode", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error()) } // TestBeneficiaryFIIdentifierRequired validates BeneficiaryFI Identifier is required @@ -121,8 +113,7 @@ func TestBeneficiaryFIIdentifierRequired(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Identifier", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error()) } // TestParseBeneficiaryFIWrongLength parses a wrong BeneficiaryFI record length @@ -133,8 +124,7 @@ func TestParseBeneficiaryFIWrongLength(t *testing.T) { err := r.parseBeneficiaryFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(181, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(181, len(r.line))).Error()) } // TestParseBeneficiaryFIReaderParseError parses a wrong BeneficiaryFI reader parse error @@ -145,13 +135,13 @@ func TestParseBeneficiaryFIReaderParseError(t *testing.T) { err := r.parseBeneficiaryFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "F® Name")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "F® Name")).Error() + require.EqualError(t, err, expected) } // TestBeneficiaryFITagError validates a BeneficiaryFI tag @@ -161,6 +151,5 @@ func TestBeneficiaryFITagError(t *testing.T) { err := bfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, bfi.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, bfi.tag).Error()) } diff --git a/beneficiaryIntermediaryFI_test.go b/beneficiaryIntermediaryFI_test.go index 87a5b24e..7f1e9e71 100644 --- a/beneficiaryIntermediaryFI_test.go +++ b/beneficiaryIntermediaryFI_test.go @@ -33,8 +33,7 @@ func TestBeneficiaryIntermediaryFIIdentificationCodeValid(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bifi.FinancialInstitution.IdentificationCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bifi.FinancialInstitution.IdentificationCode).Error()) } // TestBeneficiaryIntermediaryFIIdentificationCodeFI validates BeneficiaryIntermediaryFI IdentificationCode is an FI code @@ -44,8 +43,7 @@ func TestBeneficiaryIntermediaryFIIdentificationCodeFI(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bifi.FinancialInstitution.IdentificationCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, bifi.FinancialInstitution.IdentificationCode).Error()) } // TestBeneficiaryIntermediaryFIIdentifierAlphaNumeric validates BeneficiaryIntermediaryFI Identifier is alphanumeric @@ -55,8 +53,7 @@ func TestBeneficiaryIntermediaryFIIdentifierAlphaNumeric(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Identifier", ErrNonAlphanumeric, bifi.FinancialInstitution.Identifier).Error(), err.Error()) + require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, bifi.FinancialInstitution.Identifier).Error()) } // TestBeneficiaryIntermediaryFINameAlphaNumeric validates BeneficiaryIntermediaryFI Name is alphanumeric @@ -66,8 +63,7 @@ func TestBeneficiaryIntermediaryFINameAlphaNumeric(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Name", ErrNonAlphanumeric, bifi.FinancialInstitution.Name).Error(), err.Error()) + require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, bifi.FinancialInstitution.Name).Error()) } // TestBeneficiaryIntermediaryFIAddressLineOneAlphaNumeric validates BeneficiaryIntermediaryFI AddressLineOne is alphanumeric @@ -77,8 +73,7 @@ func TestBeneficiaryIntermediaryFIAddressLineOneAlphaNumeric(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineOne", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineOne).Error()) } // TestBeneficiaryIntermediaryFIAddressLineTwoAlphaNumeric validates BeneficiaryIntermediaryFI AddressLineTwo is alphanumeric @@ -88,8 +83,7 @@ func TestBeneficiaryIntermediaryFIAddressLineTwoAlphaNumeric(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineTwo", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineTwo).Error()) } // TestBeneficiaryIntermediaryFIAddressLineThreeAlphaNumeric validates BeneficiaryIntermediaryFI AddressLineThree is alphanumeric @@ -99,8 +93,7 @@ func TestBeneficiaryIntermediaryFIAddressLineThreeAlphaNumeric(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineThree", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineThree).Error()) } // TestBeneficiaryIntermediaryFIIdentificationCodeRequired validates BeneficiaryIntermediaryFI IdentificationCode is required @@ -110,8 +103,7 @@ func TestBeneficiaryIntermediaryFIIdentificationCodeRequired(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.IdentificationCode", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.IdentificationCode", ErrFieldRequired).Error()) } // TestBeneficiaryIntermediaryFIIdentifierRequired validates BeneficiaryIntermediaryFI Identifier is required @@ -121,8 +113,7 @@ func TestBeneficiaryIntermediaryFIIdentifierRequired(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.Identifier", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.Identifier", ErrFieldRequired).Error()) } // TestParseBeneficiaryIntermediaryFIWrongLength parses a wrong BeneficiaryIntermediaryFI record length @@ -133,8 +124,7 @@ func TestParseBeneficiaryIntermediaryFIWrongLength(t *testing.T) { err := r.parseBeneficiaryIntermediaryFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(181, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(181, len(r.line))).Error()) } // TestParseBeneficiaryIntermediaryFIReaderParseError parses a wrong BeneficiaryIntermediaryFI reader parse error @@ -148,13 +138,13 @@ func TestParseBeneficiaryIntermediaryFIReaderParseError(t *testing.T) { err := r.parseBeneficiaryIntermediaryFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "F® Name")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "F® Name")).Error() + require.EqualError(t, err, expected) } // TestBeneficiaryIntermediaryFITagError validates a BeneficiaryFI tag @@ -164,6 +154,5 @@ func TestBeneficiaryIntermediaryFITagError(t *testing.T) { err := bifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, bifi.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, bifi.tag).Error()) } diff --git a/beneficiaryReference_test.go b/beneficiaryReference_test.go index fad795eb..bbe899ab 100644 --- a/beneficiaryReference_test.go +++ b/beneficiaryReference_test.go @@ -28,8 +28,7 @@ func TestBeneficiaryReferenceAlphaNumeric(t *testing.T) { err := br.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("BeneficiaryReference", ErrNonAlphanumeric, br.BeneficiaryReference).Error(), err.Error()) + require.EqualError(t, err, fieldError("BeneficiaryReference", ErrNonAlphanumeric, br.BeneficiaryReference).Error()) } // TestParseBeneficiaryReferenceWrongLength parses a wrong BeneficiaryReference record length @@ -40,8 +39,7 @@ func TestParseBeneficiaryReferenceWrongLength(t *testing.T) { err := r.parseBeneficiaryReference() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(22, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(22, len(r.line))).Error()) } // TestParseBeneficiaryReferenceReaderParseError parses a wrong BeneficiaryReference reader parse error @@ -52,13 +50,13 @@ func TestParseBeneficiaryReferenceReaderParseError(t *testing.T) { err := r.parseBeneficiaryReference() - require.NotNil(t, err.Error()) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("BeneficiaryReference", ErrNonAlphanumeric, "Reference®")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err.Error()) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("BeneficiaryReference", ErrNonAlphanumeric, "Reference®")).Error() + require.EqualError(t, err, expected) } // TestBeneficiaryReferenceTagError validates a BeneficiaryReference tag @@ -68,6 +66,5 @@ func TestBeneficiaryReferenceTagError(t *testing.T) { err := br.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, br.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, br.tag).Error()) } diff --git a/beneficiary_test.go b/beneficiary_test.go index 2ab2241e..4cd9101f 100644 --- a/beneficiary_test.go +++ b/beneficiary_test.go @@ -33,8 +33,7 @@ func TestBeneficiaryIdentificationCodeValid(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, ben.Personal.IdentificationCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, ben.Personal.IdentificationCode).Error()) } // TestBeneficiaryIdentifierAlphaNumeric validates Beneficiary Identifier is alphanumeric @@ -44,8 +43,7 @@ func TestBeneficiaryIdentifierAlphaNumeric(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Identifier", ErrNonAlphanumeric, ben.Personal.Identifier).Error(), err.Error()) + require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, ben.Personal.Identifier).Error()) } // TestBeneficiaryNameAlphaNumeric validates Beneficiary Name is alphanumeric @@ -55,8 +53,7 @@ func TestBeneficiaryNameAlphaNumeric(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Name", ErrNonAlphanumeric, ben.Personal.Name).Error(), err.Error()) + require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, ben.Personal.Name).Error()) } // TestBeneficiaryAddressLineOneAlphaNumeric validates Beneficiary AddressLineOne is alphanumeric @@ -66,8 +63,7 @@ func TestBeneficiaryAddressLineOneAlphaNumeric(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineOne", ErrNonAlphanumeric, ben.Personal.Address.AddressLineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, ben.Personal.Address.AddressLineOne).Error()) } // TestBeneficiaryAddressLineTwoAlphaNumeric validates Beneficiary AddressLineTwo is alphanumeric @@ -77,8 +73,7 @@ func TestBeneficiaryAddressLineTwoAlphaNumeric(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineTwo", ErrNonAlphanumeric, ben.Personal.Address.AddressLineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, ben.Personal.Address.AddressLineTwo).Error()) } // TestBeneficiaryAddressLineThreeAlphaNumeric validates Beneficiary AddressLineThree is alphanumeric @@ -88,8 +83,7 @@ func TestBeneficiaryAddressLineThreeAlphaNumeric(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AddressLineThree", ErrNonAlphanumeric, ben.Personal.Address.AddressLineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, ben.Personal.Address.AddressLineThree).Error()) } // TestBeneficiaryIdentificationCodeRequired validates Beneficiary IdentificationCode is required @@ -99,8 +93,7 @@ func TestBeneficiaryIdentificationCodeRequired(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("IdentificationCode", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error()) } // TestBeneficiaryIdentifierRequired validates Beneficiary Identifier is required @@ -110,8 +103,7 @@ func TestBeneficiaryIdentifierRequired(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Identifier", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error()) } // TestParseBeneficiaryWrongLength parses a wrong Beneficiary record length @@ -122,8 +114,7 @@ func TestParseBeneficiaryWrongLength(t *testing.T) { err := r.parseBeneficiary() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(181, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(181, len(r.line))).Error()) } // TestParseBeneficiaryReaderParseError parses a wrong Beneficiary reader parse error @@ -134,13 +125,13 @@ func TestParseBeneficiaryReaderParseError(t *testing.T) { err := r.parseBeneficiary() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "Na®e")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "Na®e")).Error() + require.EqualError(t, err, expected) } // TestBeneficiaryTagError validates Beneficiary tag @@ -150,6 +141,5 @@ func TestBeneficiaryTagError(t *testing.T) { err := ben.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, ben.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, ben.tag).Error()) } diff --git a/businessFunctionCode_test.go b/businessFunctionCode_test.go index 48a46f74..3972456a 100644 --- a/businessFunctionCode_test.go +++ b/businessFunctionCode_test.go @@ -29,8 +29,7 @@ func TestBusinessFunctionCodeValid(t *testing.T) { err := bfc.Validate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrBusinessFunctionCode.Error()) + require.EqualError(t, err, fieldError("BusinessFunctionCode", ErrBusinessFunctionCode, bfc.BusinessFunctionCode).Error()) } // TestBusinessFunctionCodeRequired validates BusinessFunctionCode is required @@ -40,8 +39,7 @@ func TestBusinessFunctionCodeRequired(t *testing.T) { err := bfc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("BusinessFunctionCode", ErrFieldRequired, bfc.BusinessFunctionCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("BusinessFunctionCode", ErrFieldRequired, bfc.BusinessFunctionCode).Error()) } // TestParseBusinessFunctionCodeWrongLength parses a wrong BusinessFunctionCode record length @@ -52,8 +50,7 @@ func TestParseBusinessFunctionCodeWrongLength(t *testing.T) { err := r.parseBusinessFunctionCode() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(12, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(12, len(r.line))).Error()) } // TestParseBusinessFunctionCodeReaderParseError parses a wrong BusinessFunctionCode reader parse error @@ -64,13 +61,13 @@ func TestParseBusinessFunctionCodeReaderParseError(t *testing.T) { err := r.parseBusinessFunctionCode() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrBusinessFunctionCode.Error()) + expected := r.parseError(fieldError("BusinessFunctionCode", ErrBusinessFunctionCode, "CTA")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrBusinessFunctionCode.Error()) + expected = r.parseError(fieldError("BusinessFunctionCode", ErrBusinessFunctionCode, "CTA")).Error() + require.EqualError(t, err, expected) } // TestBusinessFunctionCodeTagError validates a BusinessFunctionCode tag @@ -80,6 +77,5 @@ func TestBusinessFunctionCodeTagError(t *testing.T) { err := bfc.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, bfc.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, bfc.tag).Error()) } diff --git a/charges_test.go b/charges_test.go index 077e0aaa..f365deb8 100644 --- a/charges_test.go +++ b/charges_test.go @@ -31,8 +31,7 @@ func TestPaymentNotificationIndicatorValid(t *testing.T) { err := c.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("ChargeDetails", ErrChargeDetails, c.ChargeDetails).Error(), err.Error()) + require.EqualError(t, err, fieldError("ChargeDetails", ErrChargeDetails, c.ChargeDetails).Error()) } func TestChargesCrash(t *testing.T) { diff --git a/currencyInstructedAmount_test.go b/currencyInstructedAmount_test.go index 0acde8e4..cfdc6074 100644 --- a/currencyInstructedAmount_test.go +++ b/currencyInstructedAmount_test.go @@ -29,8 +29,7 @@ func TestCurrencyInstructedAmountSwiftFieldTagAlphaNumeric(t *testing.T) { err := cia.Validate() - require.NotEmpty(t, err) - require.Equal(t, fieldError("SwiftFieldTag", ErrNonAlphanumeric, cia.SwiftFieldTag).Error(), err.Error()) + require.EqualError(t, err, fieldError("SwiftFieldTag", ErrNonAlphanumeric, cia.SwiftFieldTag).Error()) } // TestCurrencyInstructedAmountValid validates CurrencyInstructedAmount Amount is valid @@ -40,8 +39,7 @@ func TestCurrencyInstructedAmountValid(t *testing.T) { err := cia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("Amount", ErrNonAmount, cia.Amount).Error(), err.Error()) + require.EqualError(t, err, fieldError("Amount", ErrNonAmount, cia.Amount).Error()) } // TestParseCurrencyInstructedAmountWrongLength parses a wrong CurrencyInstructedAmount record length @@ -52,8 +50,13 @@ func TestParseCurrencyInstructedAmountWrongLength(t *testing.T) { err := r.parseCurrencyInstructedAmount() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(29, len(r.line)).Error()) + expected := r.parseError(NewTagWrongLengthErr(29, len(r.line))).Error() + require.EqualError(t, err, expected) + + _, err = r.Read() + + expected = r.parseError(NewTagWrongLengthErr(29, len(r.line))).Error() + require.EqualError(t, err, expected) } // TestParseCurrencyInstructedAmountReaderParseError parses a wrong CurrencyInstructedAmount reader parse error @@ -64,13 +67,11 @@ func TestParseCurrencyInstructedAmountReaderParseError(t *testing.T) { err := r.parseCurrencyInstructedAmount() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "00000000Z001500,49")).Error()) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + require.EqualError(t, err, r.parseError(fieldError("Amount", ErrNonAmount, "00000000Z001500,49")).Error()) } // TestCurrencyInstructedAmountTagError validates a CurrencyInstructedAmount tag @@ -80,6 +81,5 @@ func TestCurrencyInstructedAmountTagError(t *testing.T) { err := cia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, cia.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, cia.tag).Error()) } diff --git a/dateRemittanceDocument_test.go b/dateRemittanceDocument_test.go index be1ae10f..ab995c37 100644 --- a/dateRemittanceDocument_test.go +++ b/dateRemittanceDocument_test.go @@ -29,8 +29,7 @@ func TestDateRemittanceDocumentDateRemittanceDocumentRequired(t *testing.T) { err := drd.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("DateRemittanceDocument", ErrFieldRequired).Error(), err.Error()) + require.EqualError(t, err, fieldError("DateRemittanceDocument", ErrFieldRequired).Error()) } // TestParseDateRemittanceDocumentWrongLength parses a wrong DateRemittanceDocument record length @@ -41,8 +40,7 @@ func TestParseDateRemittanceDocumentWrongLength(t *testing.T) { err := r.parseDateRemittanceDocument() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(14, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(14, len(r.line))).Error()) } // TestParseDateRemittanceDocumentReaderParseError parses a wrong DateRemittanceDocument reader parse error @@ -53,13 +51,11 @@ func TestParseDateRemittanceDocumentReaderParseError(t *testing.T) { err := r.parseDateRemittanceDocument() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrValidDate.Error()) + require.EqualError(t, err, r.parseError(ErrValidDate).Error()) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrValidDate.Error()) + require.EqualError(t, err, r.parseError(ErrValidDate).Error()) } // TestDateRemittanceDocumentTagError validates a DateRemittanceDocument tag @@ -69,6 +65,5 @@ func TestDateRemittanceDocumentTagError(t *testing.T) { err := drd.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, drd.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, drd.tag).Error()) } diff --git a/exchangeRate_test.go b/exchangeRate_test.go index 1064b250..7a708703 100644 --- a/exchangeRate_test.go +++ b/exchangeRate_test.go @@ -28,8 +28,7 @@ func TestExchangeRateNumeric(t *testing.T) { err := eRate.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("ExchangeRate", ErrNonAmount, eRate.ExchangeRate).Error(), err.Error()) + require.EqualError(t, err, fieldError("ExchangeRate", ErrNonAmount, eRate.ExchangeRate).Error()) } // TestParseExchangeRateWrongLength parses a wrong ExchangeRate record length @@ -40,8 +39,13 @@ func TestParseExchangeRateWrongLength(t *testing.T) { err := r.parseExchangeRate() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(18, len(r.line)).Error()) + expected := r.parseError(NewTagWrongLengthErr(18, len(r.line))).Error() + require.EqualError(t, err, expected) + + _, err = r.Read() + + expected = r.parseError(NewTagWrongLengthErr(18, len(r.line))).Error() + require.EqualError(t, err, expected) } // TestParseExchangeRateReaderParseError parses a wrong ExchangeRate reader parse error @@ -52,13 +56,11 @@ func TestParseExchangeRateReaderParseError(t *testing.T) { err := r.parseExchangeRate() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + require.EqualError(t, err, r.parseError(fieldError("ExchangeRate", ErrNonAmount, "1,2345Z")).Error()) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAmount.Error()) + require.EqualError(t, err, r.parseError(fieldError("ExchangeRate", ErrNonAmount, "1,2345Z")).Error()) } // TestExchangeRateTagError validates a ExchangeRate tag @@ -68,6 +70,5 @@ func TestExchangeRateTagError(t *testing.T) { err := eRate.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, eRate.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, eRate.tag).Error()) } diff --git a/fIBeneficiaryFIAdvice_test.go b/fIBeneficiaryFIAdvice_test.go index 465bd8f4..0aba3181 100644 --- a/fIBeneficiaryFIAdvice_test.go +++ b/fIBeneficiaryFIAdvice_test.go @@ -34,8 +34,7 @@ func TestFIBeneficiaryFIAdviceAdviceCodeValid(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, fibfia.Advice.AdviceCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("AdviceCode", ErrAdviceCode, fibfia.Advice.AdviceCode).Error()) } // TestFIBeneficiaryFIAdviceLineOneAlphaNumeric validates FIBeneficiaryFIAdvice LineOne is alphanumeric @@ -45,8 +44,7 @@ func TestFIBeneficiaryFIAdviceLineOneAlphaNumeric(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fibfia.Advice.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fibfia.Advice.LineOne).Error()) } // TestFIBeneficiaryFIAdviceLineTwoAlphaNumeric validates FIBeneficiaryFIAdvice LineTwo is alphanumeric @@ -56,8 +54,7 @@ func TestFIBeneficiaryFIAdviceLineTwoAlphaNumeric(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fibfia.Advice.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fibfia.Advice.LineTwo).Error()) } // TestFIBeneficiaryFIAdviceLineThreeAlphaNumeric validates FIBeneficiaryFIAdvice LineThree is alphanumeric @@ -67,8 +64,7 @@ func TestFIBeneficiaryFIAdviceLineThreeAlphaNumeric(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fibfia.Advice.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fibfia.Advice.LineThree).Error()) } // TestFIBeneficiaryFIAdviceLineFourAlphaNumeric validates FIBeneficiaryFIAdvice LineFour is alphanumeric @@ -78,8 +74,7 @@ func TestFIBeneficiaryFIAdviceLineFourAlphaNumeric(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fibfia.Advice.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fibfia.Advice.LineFour).Error()) } // TestFIBeneficiaryFIAdviceLineFiveAlphaNumeric validates FIBeneficiaryFIAdvice LineFive is alphanumeric @@ -89,8 +84,7 @@ func TestFIBeneficiaryFIAdviceLineFiveAlphaNumeric(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fibfia.Advice.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fibfia.Advice.LineFive).Error()) } // TestFIBeneficiaryFIAdviceLineSixAlphaNumeric validates FIBeneficiaryFIAdvice LineSix is alphanumeric @@ -100,8 +94,7 @@ func TestFIBeneficiaryFIAdviceLineSixAlphaNumeric(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fibfia.Advice.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fibfia.Advice.LineSix).Error()) } // TestParseFIBeneficiaryFIAdviceWrongLength parses a wrong FIBeneficiaryFIAdvice record length @@ -112,8 +105,7 @@ func TestParseFIBeneficiaryFIAdviceWrongLength(t *testing.T) { err := r.parseFIBeneficiaryFIAdvice() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error(), err.Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(200, len(r.line))).Error()) } // TestParseFIBeneficiaryFIAdviceReaderParseError parses a wrong FIBeneficiaryFIAdvice reader parse error @@ -124,13 +116,13 @@ func TestParseFIBeneficiaryFIAdviceReaderParseError(t *testing.T) { err := r.parseFIBeneficiaryFIAdvice() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) } // TestFIBeneficiaryFIAdviceTagError validates a FIBeneficiaryFIAdvice tag @@ -140,6 +132,5 @@ func TestFIBeneficiaryFIAdviceTagError(t *testing.T) { err := fibfia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, fibfia.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fibfia.tag).Error()) } diff --git a/fedWiremessage_test.go b/fedWiremessage_test.go index 7b91f7d6..661ea6ea 100644 --- a/fedWiremessage_test.go +++ b/fedWiremessage_test.go @@ -49,10 +49,8 @@ func TestFEDWireMessage_invalidAmount(t *testing.T) { // Validate File err := file.Validate() - require.NotNil(t, err) - expected := NewErrInvalidPropertyForProperty("Amount", fwm.Amount.Amount, "SubTypeCode", - fwm.TypeSubType.SubTypeCode).Error() - require.Equal(t, expected, err.Error()) + expected := NewErrInvalidPropertyForProperty("Amount", fwm.Amount.Amount, "SubTypeCode", fwm.TypeSubType.SubTypeCode).Error() + require.EqualError(t, err, expected) } func TestFEDWireMessage_previousMessageIdentifierInvalid(t *testing.T) { @@ -63,9 +61,8 @@ func TestFEDWireMessage_previousMessageIdentifierInvalid(t *testing.T) { err := fwm.checkPreviousMessageIdentifier() - require.NotNil(t, err) expected := fieldError("PreviousMessageIdentifier", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_invalidLocalInstrument(t *testing.T) { @@ -77,9 +74,8 @@ func TestFEDWireMessage_invalidLocalInstrument(t *testing.T) { err := fwm.validateLocalInstrumentCode() - require.NotNil(t, err) expected := fieldError("LocalInstrument", ErrLocalInstrumentNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_invalidCharges(t *testing.T) { @@ -94,10 +90,8 @@ func TestFEDWireMessage_invalidCharges(t *testing.T) { err := fwm.validateCharges() - require.NotNil(t, err) - expected := NewErrInvalidPropertyForProperty("LocalInstrumentCode", fwm.LocalInstrument.LocalInstrumentCode, - "Charges", fwm.Charges.String()).Error() - require.Equal(t, expected, err.Error()) + expected := NewErrInvalidPropertyForProperty("LocalInstrumentCode", fwm.LocalInstrument.LocalInstrumentCode, "Charges", fwm.Charges.String()).Error() + require.EqualError(t, err, expected) } func TestFEDWireMessage_invalidInstructedAmount(t *testing.T) { @@ -112,10 +106,8 @@ func TestFEDWireMessage_invalidInstructedAmount(t *testing.T) { err := fwm.validateInstructedAmount() - require.NotNil(t, err) - expected := NewErrInvalidPropertyForProperty("LocalInstrumentCode", fwm.LocalInstrument.LocalInstrumentCode, - "Instructed Amount", fwm.InstructedAmount.String()).Error() - require.Equal(t, expected, err.Error()) + expected := NewErrInvalidPropertyForProperty("LocalInstrumentCode", fwm.LocalInstrument.LocalInstrumentCode, "Instructed Amount", fwm.InstructedAmount.String()).Error() + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateExchangeRate_missingInstructedAmount(t *testing.T) { @@ -127,9 +119,8 @@ func TestFEDWireMessage_validateExchangeRate_missingInstructedAmount(t *testing. err := fwm.validateExchangeRate() - require.NotNil(t, err) expected := fieldError("InstructedAmount", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_isExchangeRateValid_missingLocalInstrumentCode(t *testing.T) { @@ -146,26 +137,20 @@ func TestFEDWireMessage_isExchangeRateValid_missingLocalInstrumentCode(t *testin err := fwm.validateExchangeRate() - require.NotNil(t, err) - expected := NewErrInvalidPropertyForProperty("LocalInstrumentCode", fwm.LocalInstrument.LocalInstrumentCode, - "ExchangeRate", fwm.ExchangeRate.ExchangeRate).Error() - require.Equal(t, expected, err.Error()) + expected := NewErrInvalidPropertyForProperty("LocalInstrumentCode", fwm.LocalInstrument.LocalInstrumentCode, "ExchangeRate", fwm.ExchangeRate.ExchangeRate).Error() + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateBeneficiaryIntermediaryFI(t *testing.T) { fwm := mockCustomerTransferData() - bifi := mockBeneficiaryIntermediaryFI() fwm.SetBeneficiaryIntermediaryFI(bifi) - fwm.BusinessFunctionCode.BusinessFunctionCode = CustomerTransfer // BeneficiaryFI required field check err := fwm.validateBeneficiaryIntermediaryFI() - require.NotNil(t, err) - expected := fieldError("BeneficiaryFI", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("BeneficiaryFI", ErrFieldRequired).Error()) bfi := mockBeneficiaryFI() fwm.SetBeneficiaryFI(bfi) @@ -173,24 +158,19 @@ func TestFEDWireMessage_validateBeneficiaryIntermediaryFI(t *testing.T) { // Beneficiary required field check err = fwm.validateBeneficiaryIntermediaryFI() - require.NotNil(t, err) - expected = fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("Beneficiary", ErrFieldRequired).Error()) } func TestFEDWireMessage_validateBeneficiaryFI(t *testing.T) { fwm := mockCustomerTransferData() bfi := mockBeneficiaryFI() fwm.SetBeneficiaryFI(bfi) - fwm.BusinessFunctionCode.BusinessFunctionCode = CustomerTransfer // Beneficiary required field check err := fwm.validateBeneficiaryFI() - require.NotNil(t, err) - expected := fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("Beneficiary", ErrFieldRequired).Error()) } func TestFEDWireMessage_validateOriginatorFI(t *testing.T) { @@ -202,9 +182,7 @@ func TestFEDWireMessage_validateOriginatorFI(t *testing.T) { // Originator required field check err := fwm.validateOriginatorFI() - require.NotNil(t, err) - expected := fieldError("Originator", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("Originator", ErrFieldRequired).Error()) fwm.BusinessFunctionCode.BusinessFunctionCode = CustomerTransferPlus o := mockOriginator() @@ -213,9 +191,7 @@ func TestFEDWireMessage_validateOriginatorFI(t *testing.T) { // OriginatorOptionF required field check err = fwm.validateOriginatorFI() - require.NotNil(t, err) - expected = fieldError("OriginatorOptionF", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, fieldError("OriginatorOptionF", ErrFieldRequired).Error()) } func TestFEDWireMessage_validateInstructingFI(t *testing.T) { @@ -227,9 +203,8 @@ func TestFEDWireMessage_validateInstructingFI(t *testing.T) { // Originator required field check err := fwm.validateInstructingFI() - require.NotNil(t, err) expected := fieldError("Originator", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) fwm.BusinessFunctionCode.BusinessFunctionCode = CustomerTransferPlus o := mockOriginator() @@ -238,9 +213,8 @@ func TestFEDWireMessage_validateInstructingFI(t *testing.T) { // OriginatorOptionF required field check err = fwm.validateInstructingFI() - require.NotNil(t, err) expected = fieldError("OriginatorOptionF", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestNewFEDWireMessage_validateOriginatorToBeneficiary(t *testing.T) { @@ -252,9 +226,8 @@ func TestNewFEDWireMessage_validateOriginatorToBeneficiary(t *testing.T) { // Beneficiary required field check err := fwm.validateOriginatorToBeneficiary() - require.NotNil(t, err) expected := fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) ben := mockBeneficiary() fwm.SetBeneficiary(ben) @@ -262,9 +235,8 @@ func TestNewFEDWireMessage_validateOriginatorToBeneficiary(t *testing.T) { // Originator required Field check err = fwm.validateOriginatorToBeneficiary() - require.NotNil(t, err) expected = fieldError("Originator", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) o := mockOriginator() fwm.SetOriginator(o) @@ -273,18 +245,16 @@ func TestNewFEDWireMessage_validateOriginatorToBeneficiary(t *testing.T) { // OriginatorOptionF required Field check err = fwm.validateOriginatorToBeneficiary() - require.NotNil(t, err) expected = fieldError("OriginatorOptionF", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) // check beneficiary still required fwm.SetBeneficiary(nil) err = fwm.validateOriginatorToBeneficiary() - require.NotNil(t, err) expected = fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateFIIntermediaryFI(t *testing.T) { @@ -296,9 +266,8 @@ func TestFEDWireMessage_validateFIIntermediaryFI(t *testing.T) { // BeneficiaryIntermediaryFI required field check err := fwm.validateFIIntermediaryFI() - require.NotNil(t, err) expected := fieldError("BeneficiaryIntermediaryFI", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) bifi := mockBeneficiaryIntermediaryFI() fwm.SetBeneficiaryIntermediaryFI(bifi) @@ -306,9 +275,8 @@ func TestFEDWireMessage_validateFIIntermediaryFI(t *testing.T) { // BeneficiaryFI required field check err = fwm.validateFIIntermediaryFI() - require.NotNil(t, err) expected = fieldError("BeneficiaryFI", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) bfi := mockBeneficiaryFI() fwm.SetBeneficiaryFI(bfi) @@ -316,9 +284,8 @@ func TestFEDWireMessage_validateFIIntermediaryFI(t *testing.T) { // Beneficiary required field check err = fwm.validateFIIntermediaryFI() - require.NotNil(t, err) expected = fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateFIIntermediaryFIAdvice(t *testing.T) { @@ -330,18 +297,16 @@ func TestFEDWireMessage_validateFIIntermediaryFIAdvice(t *testing.T) { // BeneficiaryIntermediaryFI required field check err := fwm.validateFIIntermediaryFIAdvice() - require.NotNil(t, err) expected := fieldError("BeneficiaryIntermediaryFI", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) bifi := mockBeneficiaryIntermediaryFI() fwm.SetBeneficiaryIntermediaryFI(bifi) // BeneficiaryFI required field check err = fwm.validateFIIntermediaryFIAdvice() - require.NotNil(t, err) expected = fieldError("BeneficiaryFI", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) bfi := mockBeneficiaryFI() fwm.SetBeneficiaryFI(bfi) @@ -349,9 +314,8 @@ func TestFEDWireMessage_validateFIIntermediaryFIAdvice(t *testing.T) { // Beneficiary required field check err = fwm.validateFIIntermediaryFIAdvice() - require.NotNil(t, err) expected = fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateFIBeneficiaryFI(t *testing.T) { @@ -363,9 +327,8 @@ func TestFEDWireMessage_validateFIBeneficiaryFI(t *testing.T) { // BeneficiaryFI required field check err := fwm.validateFIBeneficiaryFI() - require.NotNil(t, err) expected := fieldError("BeneficiaryFI", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) bfi := mockBeneficiaryFI() fwm.SetBeneficiaryFI(bfi) @@ -373,9 +336,8 @@ func TestFEDWireMessage_validateFIBeneficiaryFI(t *testing.T) { // Beneficiary required field check err = fwm.validateFIBeneficiaryFI() - require.NotNil(t, err) expected = fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateFIBeneficiaryFIAdvice(t *testing.T) { @@ -387,9 +349,8 @@ func TestFEDWireMessage_validateFIBeneficiaryFIAdvice(t *testing.T) { // BeneficiaryFI required field check err := fwm.validateFIBeneficiaryFIAdvice() - require.NotNil(t, err) expected := fieldError("BeneficiaryFI", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) bfi := mockBeneficiaryFI() fwm.SetBeneficiaryFI(bfi) @@ -397,9 +358,8 @@ func TestFEDWireMessage_validateFIBeneficiaryFIAdvice(t *testing.T) { // Beneficiary required field check err = fwm.validateFIBeneficiaryFIAdvice() - require.NotNil(t, err) expected = fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateFIBeneficiary(t *testing.T) { @@ -411,9 +371,8 @@ func TestFEDWireMessage_validateFIBeneficiary(t *testing.T) { // Beneficiary required field check err := fwm.validateFIBeneficiary() - require.NotNil(t, err) expected := fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateFIBeneficiaryAdvice(t *testing.T) { @@ -425,9 +384,8 @@ func TestFEDWireMessage_validateFIBeneficiaryAdvice(t *testing.T) { // Beneficiary required field check err := fwm.validateFIBeneficiaryAdvice() - require.NotNil(t, err) expected := fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateUnstructuredAddenda(t *testing.T) { @@ -442,10 +400,9 @@ func TestFEDWireMessage_validateUnstructuredAddenda(t *testing.T) { // UnstructuredAddenda Invalid Property err := fwm.validateUnstructuredAddenda() - require.NotNil(t, err) expected := NewErrInvalidPropertyForProperty("UnstructuredAddenda", fwm.UnstructuredAddenda.String(), "LocalInstrumentCode", fwm.LocalInstrument.LocalInstrumentCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateRelatedRemittance(t *testing.T) { @@ -460,9 +417,8 @@ func TestFEDWireMessage_validateRelatedRemittance(t *testing.T) { // RelatedRemittance Invalid Property err := fwm.validateRelatedRemittance() - require.NotNil(t, err) expected := fieldError("RelatedRemittance", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateRemittanceOriginator(t *testing.T) { @@ -477,9 +433,8 @@ func TestFEDWireMessage_validateRemittanceOriginator(t *testing.T) { // RemittanceOriginator Invalid Property err := fwm.validateRemittanceOriginator() - require.NotNil(t, err) expected := fieldError("RemittanceOriginator", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateRemittanceBeneficiary(t *testing.T) { @@ -494,9 +449,8 @@ func TestFEDWireMessage_validateRemittanceBeneficiary(t *testing.T) { // RemittanceBeneficiary Invalid Property err := fwm.validateRemittanceBeneficiary() - require.NotNil(t, err) expected := fieldError("RemittanceBeneficiary", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) fwm.RemittanceBeneficiary = nil fwm.LocalInstrument.LocalInstrumentCode = RemittanceInformationStructured @@ -504,9 +458,8 @@ func TestFEDWireMessage_validateRemittanceBeneficiary(t *testing.T) { // RemittanceBeneficiary Invalid Property err = fwm.validateRemittanceBeneficiary() - require.NotNil(t, err) expected = fieldError("RemittanceBeneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validatePrimaryRemittanceDocument(t *testing.T) { @@ -521,9 +474,8 @@ func TestFEDWireMessage_validatePrimaryRemittanceDocument(t *testing.T) { // PrimaryRemittanceDocument Invalid Property err := fwm.validatePrimaryRemittanceDocument() - require.NotNil(t, err) expected := fieldError("PrimaryRemittanceDocument", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateActualAmountPaid(t *testing.T) { @@ -538,9 +490,8 @@ func TestFEDWireMessage_validateActualAmountPaid(t *testing.T) { // ActualAmountPaid only permitted for CTP and RMTS err := fwm.validateActualAmountPaid() - require.NotNil(t, err) expected := fieldError("ActualAmountPaid", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } @@ -556,9 +507,8 @@ func TestFEDWireMessage_validateGrossAmountRemittanceDocument(t *testing.T) { // GrossAmountRemittanceDocument only permitted for CTP and RMTS err := fwm.validateGrossAmountRemittanceDocument() - require.NotNil(t, err) expected := fieldError("GrossAmountRemittanceDocument", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateAdjustment(t *testing.T) { @@ -573,9 +523,8 @@ func TestFEDWireMessage_validateAdjustment(t *testing.T) { // Adjustment Invalid Property err := fwm.validateAdjustment() - require.NotNil(t, err) expected := fieldError("Adjustment", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } @@ -591,9 +540,8 @@ func TestFEDWireMessage_validateDateRemittanceDocument(t *testing.T) { // DateRemittanceDocument Invalid Property err := fwm.validateDateRemittanceDocument() - require.NotNil(t, err) expected := fieldError("DateRemittanceDocument", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_validateSecondaryRemittanceDocument(t *testing.T) { @@ -608,9 +556,8 @@ func TestFEDWireMessage_validateSecondaryRemittanceDocument(t *testing.T) { // SecondaryRemittanceDocument Invalid Property err := fwm.validateSecondaryRemittanceDocument() - require.NotNil(t, err) expected := fieldError("SecondaryRemittanceDocument", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } func TestFEDWireMessage_isRemittanceFreeTextValid(t *testing.T) { @@ -625,9 +572,8 @@ func TestFEDWireMessage_isRemittanceFreeTextValid(t *testing.T) { // RemittanceFreeTextValid Invalid Property err := fwm.validateRemittanceFreeText() - require.NotNil(t, err) expected := fieldError("RemittanceFreeText", ErrNotPermitted).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestFEDWireMessage_validateBankTransfer test an invalid BankTransfer @@ -643,10 +589,9 @@ func TestFEDWireMessage_validateBankTransfer(t *testing.T) { err := fwm.validateBankTransfer() - require.NotNil(t, err) expected := NewErrBusinessFunctionCodeProperty("TypeSubType", tst.TypeCode+tst.SubTypeCode, fwm.BusinessFunctionCode.BusinessFunctionCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestFEDWireMessage_invalidTransTypeCodeBankTransfer test an invalid TransactionTypeCode @@ -659,10 +604,9 @@ func TestFEDWireMessage_invalidTransTypeCodeBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("BusinessFunctionCode.TransactionTypeCode", ErrTransactionTypeCode, fwm.BusinessFunctionCode.TransactionTypeCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidLocalInstrumentForBankTransfer test an invalid LocalInstrument @@ -676,9 +620,8 @@ func TestInvalidLocalInstrumentForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("LocalInstrument", ErrInvalidProperty, fwm.LocalInstrument).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidPaymentNotificationForBankTransfer test an invalid PaymentNotification @@ -692,9 +635,8 @@ func TestInvalidPaymentNotificationForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("PaymentNotification", ErrInvalidProperty, fwm.PaymentNotification).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidChargesForBankTransfer test an invalid Charges @@ -708,9 +650,8 @@ func TestInvalidChargesForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("Charges", ErrInvalidProperty, fwm.Charges).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidInstructedAmountForBankTransfer test an invalid InstructedAmount @@ -724,9 +665,8 @@ func TestInvalidInstructedAmountForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("InstructedAmount", ErrInvalidProperty, fwm.InstructedAmount).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidExchangeRateForBankTransfer test an invalid ExchangeRate @@ -740,9 +680,8 @@ func TestInvalidExchangeRateForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("ExchangeRate", ErrInvalidProperty, fwm.ExchangeRate).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidBeneficiaryIdentificationCodeForBankTransfer test an invalid BeneficiaryIdentificationCode @@ -757,10 +696,9 @@ func TestInvalidBeneficiaryIdentificationCodeForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("Beneficiary.Personal.IdentificationCode", ErrInvalidProperty, fwm.Beneficiary.Personal.IdentificationCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidAccountDebitedDrawdownForBankTransfer test an invalid AccountDebitedDrawdown @@ -774,9 +712,8 @@ func TestInvalidAccountDebitedDrawdownForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("AccountDebitedDrawdown", ErrInvalidProperty, fwm.AccountDebitedDrawdown).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidOriginatorIdentificationCodeForBankTransfer test an invalid Originator Personal.IdentificationCode @@ -791,10 +728,9 @@ func TestInvalidOriginatorIdentificationCodeForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("Originator.Personal.IdentificationCode", ErrInvalidProperty, fwm.Originator.Personal.IdentificationCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidOriginatorOptionFForBankTransfer test an invalid OriginatorOptionF @@ -808,9 +744,8 @@ func TestInvalidOriginatorOptionFForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("OriginatorOptionF", ErrInvalidProperty, fwm.OriginatorOptionF).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidAccountCreditedDrawdownForBankTransfer test an invalid AccountCreditedDrawdown @@ -824,9 +759,8 @@ func TestInvalidAccountCreditedDrawdownForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("AccountCreditedDrawdown", ErrInvalidProperty, fwm.AccountCreditedDrawdown).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidFIDrawdownDebitAccountAdviceForBankTransfer test an invalid FIDrawdownDebitAccountAdvice @@ -840,9 +774,8 @@ func TestInvalidFIDrawdownDebitAccountAdviceForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("FIDrawdownDebitAccountAdvice", ErrInvalidProperty, fwm.FIDrawdownDebitAccountAdvice).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidServiceMessageForBankTransfer test an invalid ServiceMessage @@ -856,9 +789,8 @@ func TestInvalidServiceMessageForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("ServiceMessage", ErrInvalidProperty, fwm.ServiceMessage).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidUnstructuredAddendaForBankTransfer test an invalid UnstructuredAddenda @@ -872,9 +804,8 @@ func TestInvalidUnstructuredAddendaForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("UnstructuredAddenda", ErrInvalidProperty, fwm.UnstructuredAddenda).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidCurrencyInstructedAmountForBankTransfer test an invalid CurrencyInstructedAmount @@ -888,9 +819,8 @@ func TestInvalidCurrencyInstructedAmountForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("CurrencyInstructedAmount", ErrInvalidProperty, fwm.CurrencyInstructedAmount).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidRelatedRemittanceForBankTransfer test an invalid RelatedRemittance @@ -904,9 +834,8 @@ func TestInvalidRelatedRemittanceForBankTransfer(t *testing.T) { err := fwm.checkProhibitedBankTransferTags() - require.NotNil(t, err) expected := fieldError("RelatedRemittance", ErrInvalidProperty, fwm.RelatedRemittance).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestTransactionTypeCodeForCustomerTransfer test an invalid TransactionTypeCode @@ -919,10 +848,9 @@ func TestInvalidTransactionTypeCodeForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("BusinessFunctionCode.TransactionTypeCode", ErrTransactionTypeCode, fwm.BusinessFunctionCode.TransactionTypeCode).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidLocalInstrumentForCustomerTransfer test an invalid LocalInstrument @@ -936,9 +864,8 @@ func TestInvalidLocalInstrumentForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("LocalInstrument", ErrInvalidProperty, fwm.LocalInstrument).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidPaymentNotificationForCustomerTransfer test an invalid PaymentNotification @@ -952,9 +879,8 @@ func TestInvalidPaymentNotificationForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("PaymentNotification", ErrInvalidProperty, fwm.PaymentNotification).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidAccountDebitedDrawdownForCustomerTransfer test an invalid AccountDebitedDrawdown @@ -968,9 +894,8 @@ func TestInvalidAccountDebitedDrawdownForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("AccountDebitedDrawdown", ErrInvalidProperty, fwm.AccountDebitedDrawdown).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidOriginatorOptionFForCustomerTransfer test an invalid OriginatorOptionF @@ -984,9 +909,8 @@ func TestInvalidOriginatorOptionFForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("OriginatorOptionF", ErrInvalidProperty, fwm.OriginatorOptionF).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidAccountCreditedDrawdownForCustomerTransfer test an invalid AccountCreditedDrawdown @@ -1000,9 +924,8 @@ func TestInvalidAccountCreditedDrawdownForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("AccountCreditedDrawdown", ErrInvalidProperty, fwm.AccountCreditedDrawdown).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidFIDrawdownDebitAccountAdviceForCustomerTransfer test an invalid FIDrawdownDebitAccountAdvice @@ -1016,9 +939,8 @@ func TestInvalidFIDrawdownDebitAccountAdviceForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("FIDrawdownDebitAccountAdvice", ErrInvalidProperty, fwm.FIDrawdownDebitAccountAdvice).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidServiceMessageForCustomerTransfer test an invalid ServiceMessage @@ -1032,9 +954,8 @@ func TestInvalidServiceMessageForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("ServiceMessage", ErrInvalidProperty, fwm.ServiceMessage).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidUnstructuredAddendaForCustomerTransfer test an invalid UnstructuredAddenda @@ -1048,9 +969,8 @@ func TestInvalidUnstructuredAddendaForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("UnstructuredAddenda", ErrInvalidProperty, fwm.UnstructuredAddenda).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidCurrencyInstructedAmountForCustomerTransfer test an invalid CurrencyInstructedAmount @@ -1064,9 +984,8 @@ func TestInvalidCurrencyInstructedAmountForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("CurrencyInstructedAmount", ErrInvalidProperty, fwm.CurrencyInstructedAmount).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidRelatedRemittanceForCustomerTransfer test an invalid RelatedRemittance @@ -1080,9 +999,8 @@ func TestInvalidRelatedRemittanceForCustomerTransfer(t *testing.T) { err := fwm.checkProhibitedCustomerTransferTags() - require.NotNil(t, err) expected := fieldError("RelatedRemittance", ErrInvalidProperty, fwm.RelatedRemittance).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentUnstructuredAddendaForCustomerTransferPlus tests UnstructuredAddenda is required for @@ -1101,9 +1019,8 @@ func TestLocalInstrumentUnstructuredAddendaForCustomerTransferPlus(t *testing.T) err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("UnstructuredAddenda", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentRelatedRemittanceForCustomerTransferPlus tests RelatedRemittance is required for @@ -1123,9 +1040,8 @@ func TestLocalInstrumentRelatedRemittanceForCustomerTransferPlus(t *testing.T) { err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("RelatedRemittance", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentBeneficiaryReferenceForCustomerTransferPlus tests BeneficiaryReference is required for @@ -1145,9 +1061,8 @@ func TestLocalInstrumentBeneficiaryReferenceForCustomerTransferPlus(t *testing.T err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("BeneficiaryReference", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentOrderingCustomerForCustomerTransferPlus tests OrderingCustomer is required for @@ -1169,9 +1084,8 @@ func TestLocalInstrumentOrderingCustomerForCustomerTransferPlus(t *testing.T) { err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("OrderingCustomer", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentBeneficiaryCustomerForCustomerTransferPlus tests BeneficiaryCustomer is required for @@ -1195,9 +1109,8 @@ func TestLocalInstrumentBeneficiaryCustomerForCustomerTransferPlus(t *testing.T) err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("BeneficiaryCustomer", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentProprietaryCodeForCustomerTransferPlus tests ProprietaryCode is required for @@ -1217,9 +1130,8 @@ func TestLocalInstrumentProprietaryCodeForCustomerTransferPlus(t *testing.T) { err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("ProprietaryCode", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentRemittanceOriginatorForCustomerTransferPlus tests RemittanceOriginator is required for @@ -1239,9 +1151,8 @@ func TestLocalInstrumentRemittanceOriginatorForCustomerTransferPlus(t *testing.T err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("RemittanceOriginator", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentRemittanceBeneficiaryForCustomerTransferPlus tests RemittanceBeneficiary is required for @@ -1263,9 +1174,8 @@ func TestLocalInstrumentRemittanceBeneficiaryForCustomerTransferPlus(t *testing. err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("RemittanceBeneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentPrimaryRemittanceDocumentForCustomerTransferPlus tests PrimaryRemittanceDocument is required for @@ -1289,9 +1199,8 @@ func TestLocalInstrumentPrimaryRemittanceDocumentForCustomerTransferPlus(t *test err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("PrimaryRemittanceDocument", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestLocalInstrumentActualAmountPaidForCustomerTransferPlus tests ActualAmountPaid is required for @@ -1317,9 +1226,8 @@ func TestLocalInstrumentActualAmountPaidForCustomerTransferPlus(t *testing.T) { err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("ActualAmountPaid", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestBeneficiaryForCustomerTransferPlus tests a Beneficiary is required @@ -1331,9 +1239,8 @@ func TestBeneficiaryIdentificationCodeForCustomerTransferPlus(t *testing.T) { err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("Beneficiary", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestOriginatorForCustomerTransferPlus tests an Originator is required @@ -1347,9 +1254,8 @@ func TestOriginatorIdentificationCodeForCustomerTransferPlus(t *testing.T) { err := fwm.checkMandatoryCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("Originator OR OriginatorOptionF", ErrFieldRequired).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidAccountDebitedDrawdownForCustomerTransferPlus test an invalid AccountDebitedDrawdown @@ -1363,9 +1269,8 @@ func TestInvalidAccountDebitedDrawdownForCustomerTransferPlus(t *testing.T) { err := fwm.checkProhibitedCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("AccountDebitedDrawdown", ErrInvalidProperty, fwm.AccountDebitedDrawdown).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } // TestInvalidAccountCreditedDrawdownForCustomerTransferPlus test an invalid AccountCreditedDrawdown @@ -1379,7 +1284,6 @@ func TestInvalidAccountCreditedDrawdownForCustomerTransferPlus(t *testing.T) { err := fwm.checkProhibitedCustomerTransferPlusTags() - require.NotNil(t, err) expected := fieldError("AccountCreditedDrawdown", ErrInvalidProperty, fwm.AccountCreditedDrawdown).Error() - require.Equal(t, expected, err.Error()) + require.EqualError(t, err, expected) } diff --git a/fiAdditionalFIToFI_test.go b/fiAdditionalFIToFI_test.go index 61cddb08..fde66128 100644 --- a/fiAdditionalFIToFI_test.go +++ b/fiAdditionalFIToFI_test.go @@ -4,7 +4,6 @@ import ( "strings" "testing" - "github.com/moov-io/base" "github.com/stretchr/testify/require" ) @@ -34,8 +33,7 @@ func TestFIAdditionalFIToFILineOneAlphaNumeric(t *testing.T) { err := fifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineOne).Error()) } // TestFIAdditionalFIToFILineTwoAlphaNumeric validates FIAdditionalFIToFI LineTwo is alphanumeric @@ -45,8 +43,7 @@ func TestFIAdditionalFIToFILineTwoAlphaNumeric(t *testing.T) { err := fifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineTwo).Error()) } // TestFIAdditionalFIToFILineThreeAlphaNumeric validates FIAdditionalFIToFI LineThree is alphanumeric @@ -56,8 +53,7 @@ func TestFIAdditionalFIToFILineThreeAlphaNumeric(t *testing.T) { err := fifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineThree).Error()) } // TestFIAdditionalFIToFILineFourAlphaNumeric validates FIAdditionalFIToFI LineFour is alphanumeric @@ -67,8 +63,7 @@ func TestFIAdditionalFIToFILineFourAlphaNumeric(t *testing.T) { err := fifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFour).Error()) } // TestFIAdditionalFIToFILineFiveAlphaNumeric validates FIAdditionalFIToFI LineFive is alphanumeric @@ -78,8 +73,7 @@ func TestFIAdditionalFIToFILineFiveAlphaNumeric(t *testing.T) { err := fifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFive).Error()) } // TestFIAdditionalFIToFILineSixAlphaNumeric validates FIAdditionalFIToFI LineSix is alphanumeric @@ -89,8 +83,7 @@ func TestFIAdditionalFIToFILineSixAlphaNumeric(t *testing.T) { err := fifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineSix).Error()) } // TestParseFIAdditionalFIToFIWrongLength parses a wrong FIAdditionalFIToFI record length @@ -100,9 +93,7 @@ func TestParseFIAdditionalFIToFIWrongLength(t *testing.T) { r.line = line err := r.parseFIAdditionalFIToFI() - - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(216, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(216, len(r.line))).Error()) } // TestParseFIAdditionalFIToFIReaderParseError parses a wrong FIAdditionalFIToFI reader parse error @@ -113,20 +104,13 @@ func TestParseFIAdditionalFIToFIReaderParseError(t *testing.T) { err := r.parseFIAdditionalFIToFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) - - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error() + require.EqualError(t, err, expected) } // TestFIAdditionalFIToFITagError validates a FIAdditionalFIToFI tag @@ -136,6 +120,5 @@ func TestFIAdditionalFIToFITagError(t *testing.T) { err := fifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, fifi.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fifi.tag).Error()) } diff --git a/fiBeneficiaryAdvice_test.go b/fiBeneficiaryAdvice_test.go index b90551ee..c830b7d1 100644 --- a/fiBeneficiaryAdvice_test.go +++ b/fiBeneficiaryAdvice_test.go @@ -33,9 +33,7 @@ func TestFIBeneficiaryAdviceCodeValid(t *testing.T) { fiba.Advice.AdviceCode = "Z" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, fiba.Advice.AdviceCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("AdviceCode", ErrAdviceCode, fiba.Advice.AdviceCode).Error()) } // TestFIBeneficiaryAdviceLineOneAlphaNumeric validates FIBeneficiaryAdvice LineOne is alphanumeric @@ -44,9 +42,7 @@ func TestFIBeneficiaryAdviceLineOneAlphaNumeric(t *testing.T) { fiba.Advice.LineOne = "®" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fiba.Advice.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fiba.Advice.LineOne).Error()) } // TestFIBeneficiaryAdviceLineTwoAlphaNumeric validates FIBeneficiaryAdvice LineTwo is alphanumeric @@ -55,9 +51,7 @@ func TestFIBeneficiaryAdviceLineTwoAlphaNumeric(t *testing.T) { fiba.Advice.LineTwo = "®" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fiba.Advice.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fiba.Advice.LineTwo).Error()) } // TestFIBeneficiaryAdviceLineThreeAlphaNumeric validates FIBeneficiaryAdvice LineThree is alphanumeric @@ -66,9 +60,7 @@ func TestFIBeneficiaryAdviceLineThreeAlphaNumeric(t *testing.T) { fiba.Advice.LineThree = "®" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fiba.Advice.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fiba.Advice.LineThree).Error()) } // TestFIBeneficiaryAdviceLineFourAlphaNumeric validates FIBeneficiaryAdvice LineFour is alphanumeric @@ -77,9 +69,7 @@ func TestFIBeneficiaryAdviceLineFourAlphaNumeric(t *testing.T) { fiba.Advice.LineFour = "®" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fiba.Advice.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fiba.Advice.LineFour).Error()) } // TestFIBeneficiaryAdviceLineFiveAlphaNumeric validates FIBeneficiaryAdvice LineFive is alphanumeric @@ -88,9 +78,7 @@ func TestFIBeneficiaryAdviceLineFiveAlphaNumeric(t *testing.T) { fiba.Advice.LineFive = "®" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fiba.Advice.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fiba.Advice.LineFive).Error()) } // TestFIBeneficiaryAdviceLineSixAlphaNumeric validates FIBeneficiaryAdvice LineSix is alphanumeric @@ -99,9 +87,7 @@ func TestFIBeneficiaryAdviceLineSixAlphaNumeric(t *testing.T) { fiba.Advice.LineSix = "®" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fiba.Advice.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fiba.Advice.LineSix).Error()) } // TestParseFIBeneficiaryAdviceWrongLength parses a wrong FIBeneficiaryAdvice record length @@ -112,8 +98,7 @@ func TestParseFIBeneficiaryAdviceWrongLength(t *testing.T) { err := r.parseFIBeneficiaryAdvice() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error(), err.Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(200, len(r.line))).Error()) } // TestParseFIBeneficiaryAdviceReaderParseError parses a wrong FIBeneficiaryAdvice reader parse error @@ -124,13 +109,13 @@ func TestParseFIBeneficiaryAdviceReaderParseError(t *testing.T) { err := r.parseFIBeneficiaryAdvice() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) } // TestFIBeneficiaryAdviceTagError validates a FIBeneficiaryAdvice tag @@ -138,7 +123,5 @@ func TestFIBeneficiaryAdviceTagError(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.tag = "{9999}" err := fiba.Validate() - - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, fiba.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fiba.tag).Error()) } diff --git a/fiBeneficiaryFI_test.go b/fiBeneficiaryFI_test.go index 7ead6ca6..4297d9d5 100644 --- a/fiBeneficiaryFI_test.go +++ b/fiBeneficiaryFI_test.go @@ -33,8 +33,7 @@ func TestFIBeneficiaryFILineOneAlphaNumeric(t *testing.T) { err := fibfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fibfi.FIToFI.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fibfi.FIToFI.LineOne).Error()) } // TestFIBeneficiaryFILineTwoAlphaNumeric validates FIBeneficiaryFI LineTwo is alphanumeric @@ -44,8 +43,7 @@ func TestFIBeneficiaryFILineTwoAlphaNumeric(t *testing.T) { err := fibfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fibfi.FIToFI.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fibfi.FIToFI.LineTwo).Error()) } // TestFIBeneficiaryFILineThreeAlphaNumeric validates FIBeneficiaryFI LineThree is alphanumeric @@ -55,8 +53,7 @@ func TestFIBeneficiaryFILineThreeAlphaNumeric(t *testing.T) { err := fibfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fibfi.FIToFI.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fibfi.FIToFI.LineThree).Error()) } // TestFIBeneficiaryFILineFourAlphaNumeric validates FIBeneficiaryFI LineFour is alphanumeric @@ -66,8 +63,7 @@ func TestFIBeneficiaryFILineFourAlphaNumeric(t *testing.T) { err := fibfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fibfi.FIToFI.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fibfi.FIToFI.LineFour).Error()) } // TestFIBeneficiaryFILineFiveAlphaNumeric validates FIBeneficiaryFI LineFive is alphanumeric @@ -77,8 +73,7 @@ func TestFIBeneficiaryFILineFiveAlphaNumeric(t *testing.T) { err := fibfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fibfi.FIToFI.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fibfi.FIToFI.LineFive).Error()) } // TestFIBeneficiaryFILineSixAlphaNumeric validates FIBeneficiaryFI LineSix is alphanumeric @@ -88,8 +83,7 @@ func TestFIBeneficiaryFILineSixAlphaNumeric(t *testing.T) { err := fibfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fibfi.FIToFI.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fibfi.FIToFI.LineSix).Error()) } // TestParseFIBeneficiaryFIWrongLength parses a wrong FIBeneficiaryFI record length @@ -100,8 +94,7 @@ func TestParseFIBeneficiaryFIWrongLength(t *testing.T) { err := r.parseFIBeneficiaryFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(201, len(r.line)).Error(), err.Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(201, len(r.line))).Error()) } // TestParseFIBeneficiaryFIReaderParseError parses a wrong FIBeneficiaryFI reader parse error @@ -112,13 +105,13 @@ func TestParseFIBeneficiaryFIReaderParseError(t *testing.T) { err := r.parseFIBeneficiaryFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) } // TestFIBeneficiaryFITagError validates a FIBeneficiaryFI tag @@ -128,6 +121,5 @@ func TestFIBeneficiaryFITagError(t *testing.T) { err := fibfi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, fibfi.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fibfi.tag).Error()) } diff --git a/fiBeneficiary_test.go b/fiBeneficiary_test.go index b2253318..e275ee43 100644 --- a/fiBeneficiary_test.go +++ b/fiBeneficiary_test.go @@ -33,8 +33,7 @@ func TestFIBeneficiaryLineOneAlphaNumeric(t *testing.T) { err := fib.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fib.FIToFI.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fib.FIToFI.LineOne).Error()) } // TestFIBeneficiaryLineTwoAlphaNumeric validates FIBeneficiary LineTwo is alphanumeric @@ -44,8 +43,7 @@ func TestFIBeneficiaryLineTwoAlphaNumeric(t *testing.T) { err := fib.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fib.FIToFI.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fib.FIToFI.LineTwo).Error()) } // TestFIBeneficiaryLineThreeAlphaNumeric validates FIBeneficiary LineThree is alphanumeric @@ -55,8 +53,7 @@ func TestFIBeneficiaryLineThreeAlphaNumeric(t *testing.T) { err := fib.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fib.FIToFI.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fib.FIToFI.LineThree).Error()) } // TestFIBeneficiaryLineFourAlphaNumeric validates FIBeneficiary LineFour is alphanumeric @@ -66,8 +63,7 @@ func TestFIBeneficiaryLineFourAlphaNumeric(t *testing.T) { err := fib.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fib.FIToFI.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fib.FIToFI.LineFour).Error()) } // TestFIBeneficiaryLineFiveAlphaNumeric validates FIBeneficiary LineFive is alphanumeric @@ -77,8 +73,7 @@ func TestFIBeneficiaryLineFiveAlphaNumeric(t *testing.T) { err := fib.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fib.FIToFI.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fib.FIToFI.LineFive).Error()) } // TestFIBeneficiaryLineSixAlphaNumeric validates FIBeneficiary LineSix is alphanumeric @@ -88,8 +83,7 @@ func TestFIBeneficiaryLineSixAlphaNumeric(t *testing.T) { err := fib.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fib.FIToFI.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fib.FIToFI.LineSix).Error()) } // TestParseFIBeneficiaryWrongLength parses a wrong FIBeneficiary record length @@ -99,9 +93,7 @@ func TestParseFIBeneficiaryWrongLength(t *testing.T) { r.line = line err := r.parseFIBeneficiary() - - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(201, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(201, len(r.line))).Error()) } // TestParseFIBeneficiaryReaderParseError parses a wrong FIBeneficiary reader parse error @@ -112,13 +104,13 @@ func TestParseFIBeneficiaryReaderParseError(t *testing.T) { err := r.parseFIBeneficiary() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error() + require.EqualError(t, err, expected) } // TestFIBeneficiaryTagError validates a FIBeneficiary tag @@ -128,6 +120,5 @@ func TestFIBeneficiaryTagError(t *testing.T) { err := fib.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, fib.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fib.tag).Error()) } diff --git a/fiDrawdownDebitAccountAdvice_test.go b/fiDrawdownDebitAccountAdvice_test.go index 2fab7ef1..c684a7a8 100644 --- a/fiDrawdownDebitAccountAdvice_test.go +++ b/fiDrawdownDebitAccountAdvice_test.go @@ -34,8 +34,7 @@ func TestFIDrawdownDebitAccountAdviceCodeValid(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, debitDDAdvice.Advice.AdviceCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("AdviceCode", ErrAdviceCode, debitDDAdvice.Advice.AdviceCode).Error()) } // TestFIDrawdownDebitAccountAdviceLineOneAlphaNumeric validates FIDrawdownDebitAccountAdvice LineOne is alphanumeric @@ -45,8 +44,7 @@ func TestFIDrawdownDebitAccountAdviceLineOneAlphaNumeric(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, debitDDAdvice.Advice.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, debitDDAdvice.Advice.LineOne).Error()) } // TestFIDrawdownDebitAccountAdviceLineTwoAlphaNumeric validates FIDrawdownDebitAccountAdvice LineTwo is alphanumeric @@ -56,8 +54,7 @@ func TestFIDrawdownDebitAccountAdviceLineTwoAlphaNumeric(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, debitDDAdvice.Advice.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, debitDDAdvice.Advice.LineTwo).Error()) } // TestFIDrawdownDebitAccountAdviceLineThreeAlphaNumeric validates FIDrawdownDebitAccountAdvice LineThree is alphanumeric @@ -67,8 +64,7 @@ func TestFIDrawdownDebitAccountAdviceLineThreeAlphaNumeric(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, debitDDAdvice.Advice.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, debitDDAdvice.Advice.LineThree).Error()) } // TestFIDrawdownDebitAccountAdviceLineFourAlphaNumeric validates FIDrawdownDebitAccountAdvice LineFour is alphanumeric @@ -78,8 +74,7 @@ func TestFIDrawdownDebitAccountAdviceLineFourAlphaNumeric(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFour).Error()) } // TestFIDrawdownDebitAccountAdviceLineFiveAlphaNumeric validates FIDrawdownDebitAccountAdvice LineFive is alphanumeric @@ -89,8 +84,7 @@ func TestFIDrawdownDebitAccountAdviceLineFiveAlphaNumeric(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFive).Error()) } // TestFIDrawdownDebitAccountAdviceLineSixAlphaNumeric validates FIDrawdownDebitAccountAdvice LineSix is alphanumeric @@ -100,8 +94,7 @@ func TestFIDrawdownDebitAccountAdviceLineSixAlphaNumeric(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, debitDDAdvice.Advice.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, debitDDAdvice.Advice.LineSix).Error()) } // TestParseFIDrawdownDebitAccountAdviceWrongLength parses a wrong FIDrawdownDebitAccountAdvice record length @@ -112,8 +105,7 @@ func TestParseFIDrawdownDebitAccountAdviceWrongLength(t *testing.T) { err := r.parseFIDrawdownDebitAccountAdvice() - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error(), err.Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(200, len(r.line))).Error()) } // TestParseFIDrawdownDebitAccountAdviceReaderParseError parses a wrong FIDrawdownDebitAccountAdvice reader parse error @@ -124,13 +116,13 @@ func TestParseFIDrawdownDebitAccountAdviceReaderParseError(t *testing.T) { err := r.parseFIDrawdownDebitAccountAdvice() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error() + require.EqualError(t, err, expected) } // TestFIDrawdownDebitAccountAdviceTagError validates a FIDrawdownDebitAccountAdvice tag @@ -140,6 +132,5 @@ func TestFIDrawdownDebitAccountAdviceTagError(t *testing.T) { err := debitDDAdvice.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, debitDDAdvice.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, debitDDAdvice.tag).Error()) } diff --git a/fiIntermediaryFIAdvice_test.go b/fiIntermediaryFIAdvice_test.go index 03d17ae7..47ad8c16 100644 --- a/fiIntermediaryFIAdvice_test.go +++ b/fiIntermediaryFIAdvice_test.go @@ -34,8 +34,7 @@ func TestFIIntermediaryFIAdviceAdviceCodeValid(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, fiifia.Advice.AdviceCode).Error(), err.Error()) + require.EqualError(t, err, fieldError("AdviceCode", ErrAdviceCode, fiifia.Advice.AdviceCode).Error()) } // TestFIIntermediaryFIAdviceLineOneAlphaNumeric validates FIIntermediaryFIAdvice LineOne is alphanumeric @@ -45,8 +44,7 @@ func TestFIIntermediaryFIAdviceLineOneAlphaNumeric(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fiifia.Advice.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fiifia.Advice.LineOne).Error()) } // TestFIIntermediaryFIAdviceLineTwoAlphaNumeric validates FIIntermediaryFIAdvice LineTwo is alphanumeric @@ -56,8 +54,7 @@ func TestFIIntermediaryFIAdviceLineTwoAlphaNumeric(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fiifia.Advice.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fiifia.Advice.LineTwo).Error()) } // TestFIIntermediaryFIAdviceLineThreeAlphaNumeric validates FIIntermediaryFIAdvice LineThree is alphanumeric @@ -67,8 +64,7 @@ func TestFIIntermediaryFIAdviceLineThreeAlphaNumeric(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fiifia.Advice.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fiifia.Advice.LineThree).Error()) } // TestFIIntermediaryFIAdviceLineFourAlphaNumeric validates FIIntermediaryFIAdvice LineFour is alphanumeric @@ -78,8 +74,7 @@ func TestFIIntermediaryFIAdviceLineFourAlphaNumeric(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fiifia.Advice.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fiifia.Advice.LineFour).Error()) } // TestFIIntermediaryFIAdviceLineFiveAlphaNumeric validates FIIntermediaryFIAdvice LineFive is alphanumeric @@ -89,8 +84,7 @@ func TestFIIntermediaryFIAdviceLineFiveAlphaNumeric(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fiifia.Advice.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fiifia.Advice.LineFive).Error()) } // TestFIIntermediaryFIAdviceLineSixAlphaNumeric validates FIIntermediaryFIAdvice LineSix is alphanumeric @@ -100,8 +94,7 @@ func TestFIIntermediaryFIAdviceLineSixAlphaNumeric(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fiifia.Advice.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fiifia.Advice.LineSix).Error()) } // TestParseFIIntermediaryFIAdviceWrongLength parses a wrong FIIntermediaryFIAdvice record length @@ -111,7 +104,7 @@ func TestParseFIIntermediaryFIAdviceWrongLength(t *testing.T) { r.line = line err := r.parseFIIntermediaryFIAdvice() - require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(200, len(r.line))).Error()) } // TestParseFIIntermediaryFIAdviceReaderParseError parses a wrong FIIntermediaryFIAdvice reader parse error @@ -122,13 +115,13 @@ func TestParseFIIntermediaryFIAdviceReaderParseError(t *testing.T) { err := r.parseFIIntermediaryFIAdvice() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ne")).Error() + require.EqualError(t, err, expected) } // TestFIIntermediaryFIAdviceTagError validates a FIIntermediaryFIAdvice tag @@ -138,6 +131,5 @@ func TestFIIntermediaryFIAdviceTagError(t *testing.T) { err := fiifia.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, fiifia.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fiifia.tag).Error()) } diff --git a/fiIntermediaryFI_test.go b/fiIntermediaryFI_test.go index e532f37c..5d8b8fa9 100644 --- a/fiIntermediaryFI_test.go +++ b/fiIntermediaryFI_test.go @@ -33,8 +33,7 @@ func TestFIIntermediaryFILineOneAlphaNumeric(t *testing.T) { err := fiifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fiifi.FIToFI.LineOne).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fiifi.FIToFI.LineOne).Error()) } // TestFIIntermediaryFILineTwoAlphaNumeric validates FIIntermediaryFI LineTwo is alphanumeric @@ -44,8 +43,7 @@ func TestFIIntermediaryFILineTwoAlphaNumeric(t *testing.T) { err := fiifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fiifi.FIToFI.LineTwo).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fiifi.FIToFI.LineTwo).Error()) } // TestFIIntermediaryFILineThreeAlphaNumeric validates FIIntermediaryFI LineThree is alphanumeric @@ -55,8 +53,7 @@ func TestFIIntermediaryFILineThreeAlphaNumeric(t *testing.T) { err := fiifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fiifi.FIToFI.LineThree).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fiifi.FIToFI.LineThree).Error()) } // TestFIIntermediaryFILineFourAlphaNumeric validates FIIntermediaryFI LineFour is alphanumeric @@ -66,8 +63,7 @@ func TestFIIntermediaryFILineFourAlphaNumeric(t *testing.T) { err := fiifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fiifi.FIToFI.LineFour).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fiifi.FIToFI.LineFour).Error()) } // TestFIIntermediaryFILineFiveAlphaNumeric validates FIIntermediaryFI LineFive is alphanumeric @@ -77,8 +73,7 @@ func TestFIIntermediaryFILineFiveAlphaNumeric(t *testing.T) { err := fiifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fiifi.FIToFI.LineFive).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fiifi.FIToFI.LineFive).Error()) } // TestFIIntermediaryFILineSixAlphaNumeric validates FIIntermediaryFI LineSix is alphanumeric @@ -88,8 +83,7 @@ func TestFIIntermediaryFILineSixAlphaNumeric(t *testing.T) { err := fiifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fiifi.FIToFI.LineSix).Error(), err.Error()) + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fiifi.FIToFI.LineSix).Error()) } // TestParseFIIntermediaryFIWrongLength parses a wrong FIIntermediaryFI record length @@ -99,9 +93,7 @@ func TestParseFIIntermediaryFIWrongLength(t *testing.T) { r.line = line err := r.parseFIIntermediaryFI() - - require.NotNil(t, err) - require.Contains(t, err.Error(), NewTagWrongLengthErr(201, len(r.line)).Error()) + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(201, len(r.line))).Error()) } // TestParseFIIntermediaryFIReaderParseError parses a wrong FIIntermediaryFI reader parse error @@ -112,13 +104,13 @@ func TestParseFIIntermediaryFIReaderParseError(t *testing.T) { err := r.parseFIIntermediaryFI() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ix")).Error() + require.EqualError(t, err, expected) _, err = r.Read() - require.NotNil(t, err) - require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ix")).Error() + require.EqualError(t, err, expected) } // TestFIIntermediaryFITagError validates a FIIntermediaryFI tag @@ -128,6 +120,5 @@ func TestFIIntermediaryFITagError(t *testing.T) { err := fiifi.Validate() - require.NotNil(t, err) - require.Equal(t, fieldError("tag", ErrValidTagForType, fiifi.tag).Error(), err.Error()) + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fiifi.tag).Error()) } diff --git a/fiPaymentMethodToBeneficiary_test.go b/fiPaymentMethodToBeneficiary_test.go index 0cf76c67..b8c89c6b 100644 --- a/fiPaymentMethodToBeneficiary_test.go +++ b/fiPaymentMethodToBeneficiary_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIPaymentMethodToBeneficiary creates a FIPaymentMethodToBeneficiary @@ -17,31 +18,28 @@ func mockFIPaymentMethodToBeneficiary() *FIPaymentMethodToBeneficiary { // TestMockFIPaymentMethodToBeneficiary validates mockFIPaymentMethodToBeneficiary func TestMockFIPaymentMethodToBeneficiary(t *testing.T) { pm := mockFIPaymentMethodToBeneficiary() - if err := pm.Validate(); err != nil { - t.Error("mockFIPaymentMethodToBeneficiary does not validate and will break other tests") - } + + require.NoError(t, pm.Validate(), "mockFIPaymentMethodToBeneficiary does not validate and will break other tests") } // TestPaymentMethodValid validates FIPaymentMethodToBeneficiary PaymentMethod func TestPaymentMethodValid(t *testing.T) { pm := NewFIPaymentMethodToBeneficiary() pm.PaymentMethod = "" - if err := pm.Validate(); err != nil { - if !base.Match(err, ErrFieldInclusion) { - t.Errorf("%T: %s", err, err) - } - } + + err := pm.Validate() + + require.EqualError(t, err, fieldError("PaymentMethod", ErrFieldInclusion, pm.PaymentMethod).Error()) } // TestAdditionalInformationAlphaNumeric validates FIPaymentMethodToBeneficiary AdditionalInformation is alphanumeric func TestAdditionalInformationAlphaNumeric(t *testing.T) { pm := NewFIPaymentMethodToBeneficiary() pm.AdditionalInformation = "®" - if err := pm.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := pm.Validate() + + require.EqualError(t, err, fieldError("AdditionalInformation", ErrNonAlphanumeric, pm.AdditionalInformation).Error()) } // TestParseFIPaymentMethodToBeneficiaryWrongLength parses a wrong FIPaymentMethodToBeneficiary record length @@ -49,15 +47,9 @@ func TestParseFIPaymentMethodToBeneficiaryWrongLength(t *testing.T) { var line = "{6420}CHECKAdditional Information " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - pm := mockFIPaymentMethodToBeneficiary() - fwm.SetFIPaymentMethodToBeneficiary(pm) + err := r.parseFIPaymentMethodToBeneficiary() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(41, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(41, len(r.line))).Error()) } // TestParseFIPaymentMethodToBeneficiaryReaderParseError parses a wrong FIPaymentMethodToBeneficiary reader parse error @@ -65,30 +57,24 @@ func TestParseFIPaymentMethodToBeneficiaryReaderParseError(t *testing.T) { var line = "{6420}CHECK®dditional Information " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - pm := mockFIPaymentMethodToBeneficiary() - fwm.SetFIPaymentMethodToBeneficiary(pm) + err := r.parseFIPaymentMethodToBeneficiary() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + expected := r.parseError(fieldError("AdditionalInformation", ErrNonAlphanumeric, "®dditional Information")).Error() + require.EqualError(t, err, expected) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + expected = r.parseError(fieldError("AdditionalInformation", ErrNonAlphanumeric, "®dditional Information")).Error() + require.EqualError(t, err, expected) } // TestFIPaymentMethodToBeneficiaryTagError validates a FIPaymentMethodToBeneficiary tag func TestFIPaymentMethodToBeneficiaryTagError(t *testing.T) { pm := mockFIPaymentMethodToBeneficiary() pm.tag = "{9999}" - if err := pm.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := pm.Validate() + + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, pm.tag).Error()) } diff --git a/fiReceiverFI_test.go b/fiReceiverFI_test.go index aaa259df..e27c5ef2 100644 --- a/fiReceiverFI_test.go +++ b/fiReceiverFI_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIReceiverFI creates a FIReceiverFI @@ -21,75 +22,68 @@ func mockFIReceiverFI() *FIReceiverFI { // TestMockFIReceiverFI validates mockFIReceiverFI func TestMockFIReceiverFI(t *testing.T) { firfi := mockFIReceiverFI() - if err := firfi.Validate(); err != nil { - t.Error("mockFIReceiverFI does not validate and will break other tests") - } + + require.NoError(t, firfi.Validate(), "mockFIReceiverFI does not validate and will break other tests") } // TestFIReceiverFILineOneAlphaNumeric validates FIReceiverFI LineOne is alphanumeric func TestFIReceiverFILineOneAlphaNumeric(t *testing.T) { firfi := mockFIReceiverFI() firfi.FIToFI.LineOne = "®" - if err := firfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := firfi.Validate() + + require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, firfi.FIToFI.LineOne).Error()) } // TestFIReceiverFILineTwoAlphaNumeric validates FIReceiverFI LineTwo is alphanumeric func TestFIReceiverFILineTwoAlphaNumeric(t *testing.T) { firfi := mockFIReceiverFI() firfi.FIToFI.LineTwo = "®" - if err := firfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := firfi.Validate() + + require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, firfi.FIToFI.LineTwo).Error()) } // TestFIReceiverFILineThreeAlphaNumeric validates FIReceiverFI LineThree is alphanumeric func TestFIReceiverFILineThreeAlphaNumeric(t *testing.T) { firfi := mockFIReceiverFI() firfi.FIToFI.LineThree = "®" - if err := firfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := firfi.Validate() + + require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, firfi.FIToFI.LineThree).Error()) } // TestFIReceiverFILineFourAlphaNumeric validates FIReceiverFI LineFour is alphanumeric func TestFIReceiverFILineFourAlphaNumeric(t *testing.T) { firfi := mockFIReceiverFI() firfi.FIToFI.LineFour = "®" - if err := firfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := firfi.Validate() + + require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, firfi.FIToFI.LineFour).Error()) } // TestFIReceiverFILineFiveAlphaNumeric validates FIReceiverFI LineFive is alphanumeric func TestFIReceiverFILineFiveAlphaNumeric(t *testing.T) { firfi := mockFIReceiverFI() firfi.FIToFI.LineFive = "®" - if err := firfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := firfi.Validate() + + require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, firfi.FIToFI.LineFive).Error()) } // TestFIReceiverFILineSixAlphaNumeric validates FIReceiverFI LineSix is alphanumeric func TestFIReceiverFILineSixAlphaNumeric(t *testing.T) { firfi := mockFIReceiverFI() firfi.FIToFI.LineSix = "®" - if err := firfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := firfi.Validate() + + require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, firfi.FIToFI.LineSix).Error()) } // TestParseFIReceiverFIWrongLength parses a wrong FIReceiverFI record length @@ -97,15 +91,9 @@ func TestParseFIReceiverFIWrongLength(t *testing.T) { var line = "{6100}Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - firfi := mockFIReceiverFI() - fwm.SetFIReceiverFI(firfi) + err := r.parseFIReceiverFI() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(201, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(201, len(r.line))).Error()) } // TestParseFIReceiverFIReaderParseError parses a wrong FIReceiverFI reader parse error @@ -113,30 +101,24 @@ func TestParseFIReceiverFIReaderParseError(t *testing.T) { var line = "{6100}Line Si® " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - firfi := mockFIReceiverFI() - fwm.SetFIReceiverFI(firfi) + err := r.parseFIReceiverFI() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error() + require.EqualError(t, err, expected) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error() + require.EqualError(t, err, expected) } // TestFIReceiverFITagError validates a FIReceiverFI tag func TestFIReceiverFITagError(t *testing.T) { firfi := mockFIReceiverFI() firfi.tag = "{9999}" - if err := firfi.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := firfi.Validate() + + require.EqualError(t, err, fieldError("tag", ErrValidTagForType, firfi.tag).Error()) } diff --git a/file_test.go b/file_test.go index 28ca12bf..5b946248 100644 --- a/file_test.go +++ b/file_test.go @@ -8,6 +8,8 @@ import ( "io/ioutil" "path/filepath" "testing" + + "github.com/stretchr/testify/require" ) func TestFile__FileFromJSON(t *testing.T) { @@ -20,15 +22,8 @@ func TestFile__FileFromJSON(t *testing.T) { } file, err := FileFromJSON(bs) - if err != nil { - t.Fatal(err) - } - t.Logf("file=%#v", file) - if file.ID != "" { - t.Error("id isn't set in JSON") - } - if file.FEDWireMessage.FIAdditionalFIToFI == nil { - t.Error("FIAdditionalFIToFI shouldn't be nil") - } + require.NoError(t, err) + require.Empty(t, file.ID, "id should not have been set") + require.NotNil(t, file.FEDWireMessage.FIAdditionalFIToFI, "FIAdditionalFIToFI shouldn't be nil") } diff --git a/grossAmountRemittanceDocument_test.go b/grossAmountRemittanceDocument_test.go index 6bb6f0e7..2093d49d 100644 --- a/grossAmountRemittanceDocument_test.go +++ b/grossAmountRemittanceDocument_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // GrossAmountRemittanceDocument creates a GrossAmountRemittanceDocument @@ -17,53 +18,40 @@ func mockGrossAmountRemittanceDocument() *GrossAmountRemittanceDocument { // TestMockGrossAmountRemittanceDocument validates mockGrossAmountRemittanceDocument func TestMockGrossAmountRemittanceDocument(t *testing.T) { gard := mockGrossAmountRemittanceDocument() - if err := gard.Validate(); err != nil { - t.Error("mockGrossAmountRemittanceDocument does not validate and will break other tests") - } + + require.NoError(t, gard.Validate(), "mockGrossAmountRemittanceDocument does not validate and will break other tests") } // TestGrossAmountRemittanceAmountRequired validates GrossAmountRemittance Amount is required func TestGrossAmountRemittanceAmountRequired(t *testing.T) { gard := mockGrossAmountRemittanceDocument() gard.RemittanceAmount.Amount = "" - if err := gard.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + require.EqualError(t, gard.Validate(), fieldError("Amount", ErrFieldRequired).Error()) } // TestGrossAmountRemittanceCurrencyCodeRequired validates GrossAmountRemittance CurrencyCode is required func TestGrossAmountRemittanceCurrencyCodeRequired(t *testing.T) { gard := mockGrossAmountRemittanceDocument() gard.RemittanceAmount.CurrencyCode = "" - if err := gard.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + require.EqualError(t, gard.Validate(), fieldError("CurrencyCode", ErrFieldRequired).Error()) } // TestGrossAmountRemittanceAmountValid validates Amount func TestGrossAmountRemittanceAmountValid(t *testing.T) { gard := mockGrossAmountRemittanceDocument() gard.RemittanceAmount.Amount = "X," - if err := gard.Validate(); err != nil { - if !base.Match(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + require.EqualError(t, gard.Validate(), fieldError("Amount", ErrNonAmount, gard.RemittanceAmount.Amount).Error()) } -// TestGrossAmountRemittanceCurrencyCodeValid validates Amount +// TestGrossAmountRemittanceCurrencyCodeValid validates CurrencyCode func TestGrossAmountRemittanceCurrencyCodeValid(t *testing.T) { gard := mockGrossAmountRemittanceDocument() gard.RemittanceAmount.CurrencyCode = "XZP" - if err := gard.Validate(); err != nil { - if !base.Match(err, ErrNonCurrencyCode) { - t.Errorf("%T: %s", err, err) - } - } + + require.EqualError(t, gard.Validate(), fieldError("CurrencyCode", ErrNonCurrencyCode, gard.RemittanceAmount.CurrencyCode).Error()) } // TestParseGrossAmountRemittanceWrongLength parses a wrong GrossAmountRemittance record length @@ -71,15 +59,10 @@ func TestParseGrossAmountRemittanceWrongLength(t *testing.T) { var line = "{8500}USD1234.56 " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - gard := mockGrossAmountRemittanceDocument() - fwm.SetGrossAmountRemittanceDocument(gard) + err := r.parseGrossAmountRemittanceDocument() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(28, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(28, len(r.line))).Error()) } // TestParseGrossAmountRemittanceReaderParseError parses a wrong GrossAmountRemittance reader parse error @@ -87,30 +70,22 @@ func TestParseGrossAmountRemittanceReaderParseError(t *testing.T) { var line = "{8500}USD1234.56Z " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - gard := mockGrossAmountRemittanceDocument() - fwm.SetGrossAmountRemittanceDocument(gard) + err := r.parseGrossAmountRemittanceDocument() - if err != nil { - if !base.Match(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + expected := r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + expected = r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error() + require.EqualError(t, err, expected) } // TestGrossAmountRemittanceTagError validates a GrossAmountRemittance tag func TestGrossAmountRemittanceTagError(t *testing.T) { gard := mockGrossAmountRemittanceDocument() gard.tag = "{9999}" - if err := gard.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + require.EqualError(t, gard.Validate(), fieldError("tag", ErrValidTagForType, gard.tag).Error()) }