public PortRange(String spec) {
        Matcher portNumberMatcher = PORT_NUMBER_REGEX.matcher(spec);
        Matcher portRangeMatcher = PORT_RANGE_REGEX.matcher(spec);
        if (portNumberMatcher.find()) {
            int port = Integer.parseInt(spec);
            this.fromPort = port;
            this.toPort = port;
        } else if (portRangeMatcher.find()) {
            this.fromPort = Integer.parseInt(portRangeMatcher.group(1));
            this.toPort = Integer.parseInt(portRangeMatcher.group(2));
        } else {
            throw new IllegalArgumentException(String.format("Invalid port range specification: %s", spec));
        }

        validatePorts();
    }
@Test
    public void portRange() {
        // given
        String spec = "123-456";

        // when
        PortRange portRange = new PortRange(spec);

        // then
        assertEquals(123, portRange.getFromPort());
        assertEquals(456, portRange.getToPort());
    }