PmMessageUtil { public static PmMessage findMostSevereMessage(PmObject pm, Severity minSeverity) { TreeSet<PmMessage> messages = new TreeSet<PmMessage>(new PmMessage.MessageComparator()); messages.addAll(PmMessageApi.getPmTreeMessages(pm, minSeverity)); return messages.isEmpty() ? null : messages.iterator().next(); }  static PmMessage makeMsg(PmObject pm, Severity severity, String key, Object... resArgs); static PmMessage makeExceptionMsg(PmObject pm, Severity severity, Throwable e); static PmMessage makeMsgOneMany(PmObject pm, String keybase, int number, Object... resArgs); static PmMessage makeMsgOneMany(PmObject pm, Severity severity, String keybase, int number, Object... resArgs); static void makeOptionalInfoMsg(PmObject pm, String key, Object... msgArgs); static List<PmMessage> getPmMessages(PmObject pm); static List<PmMessage> getPmErrors(PmObject pm); static PmMessage findMostSevereMessage(PmObject pm, Severity minSeverity); static PmMessage findMostSevereMessage(PmObject pm); static List<PmMessage> clearSubTreeMessages(PmObject pm); static List<PmMessage> getSubTreeMessages(PmObject pm, Severity minSeverity);  }
@Test public void testFindMostSevereMessage() { PmConversationImpl myPm = new PmConversationImpl(); PmMessage infoMsg = PmMessageApi.addMessage(myPm, Severity.INFO, "infoMsgKey"); PmMessage warnMsg = PmMessageApi.addMessage(myPm, Severity.WARN, "warnMsgKey"); PmMessage errorMsg = PmMessageApi.addMessage(myPm, Severity.ERROR, "errorMsgKey"); assertEquals(errorMsg, PmMessageUtil.findMostSevereMessage(myPm)); myPm.clearPmMessages(null, Severity.ERROR); assertEquals(warnMsg, PmMessageUtil.findMostSevereMessage(myPm)); myPm.clearPmMessages(null, Severity.WARN); assertEquals(infoMsg, PmMessageUtil.findMostSevereMessage(myPm)); myPm.clearPmMessages(null, null); Assert.assertNull(PmMessageUtil.findMostSevereMessage(myPm)); }