BootstrappedMessages extends UINamingContainer { public List<FacesMessage> getFacesMessages() { List<FacesMessage> messageList = new ArrayList<>(); Iterator<FacesMessage> messageItr = getFacesContext().getMessages(null); while (messageItr.hasNext()) { FacesMessage message = messageItr.next(); messageList.add(message); messageItr.remove(); } return messageList; }  List<FacesMessage> getFacesMessages();  }
@Test public void the_message_list_contains_all_global_messages() { final FacesMessage message = new FacesMessage(SEVERITY_INFO, "", ""); prepareExpectedMessages(singletonList(message)); List<FacesMessage> facesMessages = new BootstrappedMessages().getFacesMessages(); assertThat(facesMessages).isEqualTo(singletonList(message)); }
@Test public void the_message_list_does_not_contain_messages_that_belong_to_a_component() { final FacesMessage componentMessage = new FacesMessage(SEVERITY_INFO, "", ""); prepareExpectedMessages(emptyList()); getCurrentInstance().addMessage("foo", componentMessage); List<FacesMessage> facesMessages = new BootstrappedMessages().getFacesMessages(); assertThat(facesMessages).isEqualTo(emptyList()); new Verifications() { { getCurrentInstance().getMessages("foo"); times = 0; } }; }