We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 458652a commit 63b2c31Copy full SHA for 63b2c31
1 file changed
core-groovy/src/test/groovy/com/baeldung/strings/ConvertStringToInt.groovy
@@ -96,4 +96,15 @@ class ConvertStringToInt {
96
def invalidString = null
97
invalidString.toInteger()
98
}
99
+
100
+ @Test
101
+ void givenString_whenUsingIsInteger_thenCheckIfCorrectValue() {
102
+ def invalidString = "123a"
103
+ def validString = "123"
104
+ def invalidNum = invalidString?.isInteger() ? invalidString as Integer : false
105
+ def correctNum = validString?.isInteger() ? validString as Integer : false
106
107
+ assertEquals(false, invalidNum)
108
+ assertEquals(123, correctNum)
109
+ }
110
0 commit comments