### Question:
MessageList implements Serializable, Iterable<Message> { public Optional<Message> getMessageWithHighestSeverity() { return messages.stream() .sorted(Comparator.comparing(Message::getSeverity).reversed()) .findFirst(); } MessageList(@NonNull Message... messages); void add(Message message); void add(@CheckForNull MessageList messageList); boolean isEmpty(); int size(); Message getMessage(int index); Optional<Message> getFirstMessage(Severity errorLevel); Optional<Message> getMessageByCode(@CheckForNull String code); MessageList getMessagesByCode(@CheckForNull String code); Optional<Severity> getSeverity(); String getText(); boolean containsErrorMsg(); MessageList getMessagesFor(Object object); MessageList getMessagesFor(Object object, @CheckForNull String property); MessageList getMessagesFor(Object object, @CheckForNull String property, int index); MessageList getMessagesByMarker(@CheckForNull ValidationMarker marker); MessageList getMessagesByMarker(Predicate<ValidationMarker> markerPredicate); MessageList sortBySeverity(); Optional<Message> getMessageWithHighestSeverity(); @Override Iterator<Message> iterator(); void clear(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); Stream<Message> stream(); static Collector<Message, ?, MessageList> collector();  }### Answer:
@Test public void testGetMessageWithHighestSeverity() { MessageList messages = new MessageList(Message.builder("info", Severity.INFO).create(), Message.builder("error", Severity.ERROR).create(), Message.builder("warning", Severity.WARNING).create()); Optional<Message> message = messages.getMessageWithHighestSeverity(); assertThat(message, is(present())); assertThat(message.get().getSeverity(), is(Severity.ERROR)); }
@Test public void testGetMessageWithHighestSeverity_null() { MessageList messages = new MessageList(); Optional<Message> message = messages.getMessageWithHighestSeverity(); assertThat(message, is(not(present()))); }