Skip to content

Commit 63b2c31

Browse files
committed
Added test case with isInteger() method.
1 parent 458652a commit 63b2c31

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

core-groovy/src/test/groovy/com/baeldung/strings/ConvertStringToInt.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ class ConvertStringToInt {
9696
def invalidString = null
9797
invalidString.toInteger()
9898
}
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+
}
99110
}

0 commit comments

Comments
 (0)