HouseId implements Identity { @Override public boolean isValidFormat() { return !(id.length() != LENGTH || !TextUtils.isDigitOnly(id)); } HouseId(String id); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); @Override boolean validate(); @Override boolean isValidFormat(); @Override String prettyPrint(); @Override String getId(); static final int LENGTH; }
@Test public void validFormatId() { HouseId hid = new HouseId("12345678901"); assertTrue("12345678901 is valid format id", hid.isValidFormat()); }
@Test public void acceptPrettyId() { HouseId hid = new HouseId("1234-567890-1"); assertTrue("1234-567890-1 is valid format", hid.isValidFormat()); }
@Test public void setInvalidFormatId() { HouseId hid; hid = new HouseId("123456"); assertFalse("Id's length 6 must be invalid", hid.isValidFormat()); hid = new HouseId("1234567890"); assertFalse("Id's length 10 must be invalid", hid.isValidFormat()); hid = new HouseId(""); assertFalse("Id's length 0 must be invalid", hid.isValidFormat()); hid = new HouseId("123456789012"); assertFalse("Id's length 12 must be invalid", hid.isValidFormat()); hid = new HouseId("123456789012345"); assertFalse("Id's length 15 must be invalid", hid.isValidFormat()); hid = new HouseId("ab34/6789x1"); assertFalse("Not only digit must be invalid", hid.isValidFormat()); hid = new HouseId("1234x678901"); assertFalse("Not only digit must be invalid", hid.isValidFormat()); hid = new HouseId("-----------"); assertFalse("only slash sign must be invalid", hid.isValidFormat()); }