### Question:
Price { public static Price of(String price) { price = price.replaceAll("\\s", ""); if (!pattern.matcher(price).matches()) { throw new IllegalArgumentException("Price has to be in following format: ###,##"); } return new Price(Long.parseLong(price.replace(",", ""))); } Price(long value); static Price of(String price); long asCents(); static Price fromCents(long cents); @Override int hashCode(); @Override boolean equals(Object other); @Override String toString(); Price plus(Price another); Price minus(Price another);  }### Answer:
@Test public void shouldCreateValidPrice() throws Exception { Price price = Price.of("234,23"); assertThat(price).isNotNull(); }
@Test public void shouldTwoPricesBeEqual() throws Exception { Price price = Price.of("234,23"); assertThat(price).isEqualTo(Price.of("234,23")); }
@Test(expected=IllegalArgumentException.class) public void shouldFailForInvalidFormat() throws Exception { Price.of(""); }
@Test(expected=IllegalArgumentException.class) public void shouldFailForInvalidFormat2() throws Exception { Price.of("abc"); }
@Test(expected=IllegalArgumentException.class) public void shouldFailForInvalidFormat3() throws Exception { Price.of("abc,de"); }
@Test(expected=IllegalArgumentException.class) public void shouldFailForInvalidFormat4() throws Exception { Price.of("123"); }
@Test(expected=IllegalArgumentException.class) public void shouldFailForInvalidFormat5() throws Exception { Price.of("123,455"); }
@Test(expected=IllegalArgumentException.class) public void shouldFailForInvalidFormat6() throws Exception { Price.of(",45"); }
@Test(expected=IllegalArgumentException.class) public void shouldFailForInvalidFormat7() throws Exception { Price.of("a 0,45"); }
@Test public void shouldIgnoreLeadingAndTrailingWhitespaces() throws Exception { Price price = Price.of(" 0,45 "); assertThat(price).isEqualTo(Price.of("0,45")); }