@Test public void test_problemWithCobolPattern() { try { parser.parseDecimalPlaces("999"); fail(); } catch (IllegalArgumentException err) { assertEquals("Unable to parse out the decimal points from cobol pattern (999)", err.getMessage()); } }
public int parseDecimalPlaces(String pattern) { if (pattern.toLowerCase().indexOf("v") == -1) { throw new IllegalArgumentException(MessageFormat.format(NOT_A_DECIMAL_PATTERN, new Object[]{pattern})); } String decimal = pattern.split("v|V")[1]; if (Pattern.matches(NO_MULTIPLIER.pattern(), decimal)) { return decimal.length(); } Matcher matcher = MULTIPLIER.matcher(decimal); matcher.find(); return Integer.parseInt(matcher.group(1)); }
CobolDecimalPatternParser { public int parseDecimalPlaces(String pattern) { if (pattern.toLowerCase().indexOf("v") == -1) { throw new IllegalArgumentException(MessageFormat.format(NOT_A_DECIMAL_PATTERN, new Object[]{pattern})); } String decimal = pattern.split("v|V")[1]; if (Pattern.matches(NO_MULTIPLIER.pattern(), decimal)) { return decimal.length(); } Matcher matcher = MULTIPLIER.matcher(decimal); matcher.find(); return Integer.parseInt(matcher.group(1)); } }
CobolDecimalPatternParser { public int parseDecimalPlaces(String pattern) { if (pattern.toLowerCase().indexOf("v") == -1) { throw new IllegalArgumentException(MessageFormat.format(NOT_A_DECIMAL_PATTERN, new Object[]{pattern})); } String decimal = pattern.split("v|V")[1]; if (Pattern.matches(NO_MULTIPLIER.pattern(), decimal)) { return decimal.length(); } Matcher matcher = MULTIPLIER.matcher(decimal); matcher.find(); return Integer.parseInt(matcher.group(1)); }  }
CobolDecimalPatternParser { public int parseDecimalPlaces(String pattern) { if (pattern.toLowerCase().indexOf("v") == -1) { throw new IllegalArgumentException(MessageFormat.format(NOT_A_DECIMAL_PATTERN, new Object[]{pattern})); } String decimal = pattern.split("v|V")[1]; if (Pattern.matches(NO_MULTIPLIER.pattern(), decimal)) { return decimal.length(); } Matcher matcher = MULTIPLIER.matcher(decimal); matcher.find(); return Integer.parseInt(matcher.group(1)); }  int parseDecimalPlaces(String pattern); }
CobolDecimalPatternParser { public int parseDecimalPlaces(String pattern) { if (pattern.toLowerCase().indexOf("v") == -1) { throw new IllegalArgumentException(MessageFormat.format(NOT_A_DECIMAL_PATTERN, new Object[]{pattern})); } String decimal = pattern.split("v|V")[1]; if (Pattern.matches(NO_MULTIPLIER.pattern(), decimal)) { return decimal.length(); } Matcher matcher = MULTIPLIER.matcher(decimal); matcher.find(); return Integer.parseInt(matcher.group(1)); }  int parseDecimalPlaces(String pattern);  }