private static int parseInteger(final String text) {
        // This methods expects |text| is not null.
        final String textTrimmed = text.trim();

        final int length = textTrimmed.length();
        if ("null".equals(textTrimmed)) {
            throw new NullPointerException("\"" + text + "\" is considered to be null.");
        }

        if (length > 9) {
            final long longValue = Long.parseLong(textTrimmed);
            if (longValue < Integer.MIN_VALUE || longValue > Integer.MAX_VALUE) {
                throw new NumberFormatException("Overflow: \"" + text + "\" is out of range of int.");
            }
            return Integer.valueOf((int) longValue);
        }
        if (length == 0) {
            throw new NullPointerException("\"" + text + "\" is considered to be an empty string.");
        }
        return Integer.valueOf(parseIntegerInternal(textTrimmed));
    }
@Test
    public void testParseInteger() {
        assertInteger("11", 11, 1234);
        assertInteger("  13", 13, 1234);
        assertInteger("  17  ", 17, 1234);
        assertInteger("111111111", 111111111, 1234);
        assertInteger("-11", -11, 1234);
    }