Skip to content

Commit

Permalink
Improvements from review at PR geb#136
Browse files Browse the repository at this point in the history
Make parseNumber return null for null and remove thereby not necessary
null checks

Parse Integer instead of BigInteger

Throw NumberFormatException if all considered parsings fail

Remove @nonnull for it is currently not used in the code base

Contributes to geb/issues#548
  • Loading branch information
mkutz committed Dec 12, 2018
1 parent 9cc5fac commit 5d98258
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions module/geb-core/src/main/groovy/geb/module/NumberInput.groovy
Expand Up @@ -15,8 +15,6 @@
*/
package geb.module

import javax.annotation.Nonnull

class NumberInput extends AbstractInput {

final String inputType = "number"
Expand All @@ -31,30 +29,28 @@ class NumberInput extends AbstractInput {
}

Number getMin() {
String minString = attr("min")
minString ? parseNumber(minString) : null
parseNumber(attr("min"))
}

Number getMax() {
String maxString = attr("max")
maxString ? parseNumber(maxString) : null
parseNumber(attr("max"))
}

Number getStep() {
String stepString = attr("step")
stepString ? parseNumber(stepString) : 1
parseNumber(attr("step"))
}

private static Number parseNumber(@Nonnull String string) {
if (!string?.number) {
throw new NumberFormatException("Value \"${string}\" of ${this} is not a number.")
private Number parseNumber(String string) {
if (null == string) {
return null
}
if (string?.bigDecimal) {
if (string.bigDecimal) {
return string.toBigDecimal()
}
if (string?.bigInteger) {
return string.toBigInteger()
if (string.integer) {
return string.toInteger()
}
throw new NumberFormatException("Value \"${string}\" of ${this} is not a number.")
}

}

0 comments on commit 5d98258

Please sign in to comment.