Dimensions { public static Dimensions fromString(final String string) { if (string.matches(PATTERN_SIMPLE.pattern())) { return new Dimensions(Integer.parseInt(string)); } else if (string.matches(PATTERN_X.pattern())) { final Matcher matcher = PATTERN_X.matcher(string); matcher.find(); return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); } throw new IllegalArgumentException(string); } Dimensions(final int height, final int width);  Dimensions(final int squareSize); int getHeight(); int getWidth(); Dimensions multiply(final int factor); Dimensions divide(final int divisor); Dimensions scaleToWidth(final int newWidth); Dimensions scaleToHeight(final int newHeight); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); static Dimensions fromString(final String string);  }
@Test public void fromString_square() { assertThat(Dimensions.fromString("50")).isEqualTo(new Dimensions(50)); }
@Test public void fromString_usex() { assertThat(Dimensions.fromString("50x60")).isEqualTo(new Dimensions(50, 60)); }
@Test public void fromString_useX() { assertThat(Dimensions.fromString("50X60")).isEqualTo(new Dimensions(50, 60)); }
@Test(expected = IllegalArgumentException.class) public void fromString_illegal() { Dimensions.fromString("toto"); }