Field { static Field get(String s) { Matcher matcher = PATTERN.matcher(s); if (!matcher.matches()) throw new IllegalArgumentException(); int tag = Integer.parseInt(matcher.group("tag")); String value = matcher.group("value"); return new Field(tag, value); } Field(int tag, String value); @Override String toString();  }
@Test public void longTag() { Field.get("12345=foo"); }
@Test(expected=IllegalArgumentException.class) public void missingTag() { Field.get("=foo"); }
@Test(expected=IllegalArgumentException.class) public void tooLongTag() { Field.get("123456=foo"); }
@Test(expected=IllegalArgumentException.class) public void invalidTag() { Field.get("foo=bar"); }
@Test(expected=IllegalArgumentException.class) public void missingValue() { Field.get("123="); }