Message { static Message get(String input) { List<Field> fields = new ArrayList<>(); String msgType = null; for (String part : input.split("\\|")) { Field field = Field.get(part); if (field.getTag() == MsgType) msgType = field.getValue(); else fields.add(field); } if (msgType == null) throw new IllegalArgumentException("MsgType(35) missing"); return new Message(msgType, fields); } private  Message(String msgType, List<Field> fields); @Override String toString();  }
@Test(expected=IllegalArgumentException.class) public void missingMsgType() { Message.get("1=foo|2=bar"); }