Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Added tests for ConversionUtils.stringToJInteger (closes snowplow/sno…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderdean committed Oct 13, 2014
1 parent 91a1690 commit 4ef2770
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,40 @@ class StringToDoublelikeSpec extends Specification with DataTables with Validati

}

class StringToJIntegerSpec extends Specification with DataTables with ValidationMatchers { def is =

"This is a specification to test the stringToJInteger function" ^
p^
"stringToJInteger should fail if the supplied String is not parseable as an Integer" ! e1^
"stringToJInteger should convert valid Strings to Java Integers" ! e2^
end

val FieldName = "val"
def err: (String) => String = input => "Field [%s]: cannot convert [%s] to Int".format(FieldName, input)

def e1 =
"SPEC NAME" || "INPUT STR" | "EXPECTED" |
"Empty string" !! "" ! err("") |
"Floating point #1" !! "1999." ! err("1999.") |
"Floating point #2" !! "1999.00" ! err("1999.00") |
"Hexadecimal number" !! "0x54" ! err("0x54") |
"NaN" !! "NaN" ! err("NaN") |
"Sci. notation" !! "6.72E5" ! err("6.72E5") |> {
(_, str, expected) =>
ConversionUtils.stringToJInteger(FieldName, str) must beFailing(expected)
}

def e2 =
"SPEC NAME" || "INPUT STR" | "EXPECTED" |
"Integer #1" !! "0" ! 0 |
"Integer #2" !! "23" ! 23 |
"Negative integer #1" !! "-2012103" ! -2012103 |
"Negative integer #2" !! "-1" ! -1 |> {
(_, str, expected) =>
ConversionUtils.stringToJInteger(FieldName, str) must beSuccessful(expected)
}
}

class StringToBooleanlikeJByteSpec extends Specification with DataTables with ValidationMatchers { def is =

"This is a specification to test the stringToBooleanlikeJByte function" ^
Expand Down

0 comments on commit 4ef2770

Please sign in to comment.