### Question:
SomeBean { public void addMessage(Severity severity, String summary, String detail) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, summary, detail)); }  void addMessage(Severity severity, String summary, String detail); String logout();  }### Answer:
@Test public void testAddMessage() { ArgumentCaptor<String> clientIdCaptor = ArgumentCaptor .forClass(String.class); ArgumentCaptor<FacesMessage> facesMessageCaptor = ArgumentCaptor .forClass(FacesMessage.class); someBean.addMessage(FacesMessage.SEVERITY_ERROR, "error", "something went wrong"); verify(facesContext).addMessage(clientIdCaptor.capture(), facesMessageCaptor.capture()); assertNull(clientIdCaptor.getValue()); FacesMessage captured = facesMessageCaptor.getValue(); assertEquals(FacesMessage.SEVERITY_ERROR, captured.getSeverity()); assertEquals("error", captured.getSummary()); assertEquals("something went wrong", captured.getDetail()); }
@Test public void testAddMessage() { Capture<String> clientIdCapture = new Capture<String>(); Capture<FacesMessage> facesMessageCapture = new Capture<FacesMessage>(); expect(FacesContext.getCurrentInstance()).andReturn(facesContext) .once(); facesContext.addMessage(capture(clientIdCapture), capture(facesMessageCapture)); expectLastCall().once(); PowerMock.replay(FacesContext.class); replay(facesContext); someBean.addMessage(FacesMessage.SEVERITY_ERROR, "error", "something went wrong"); PowerMock.verify(FacesContext.class); verify(facesContext); assertNull(clientIdCapture.getValue()); FacesMessage captured = facesMessageCapture.getValue(); assertEquals(FacesMessage.SEVERITY_ERROR, captured.getSeverity()); assertEquals("error", captured.getSummary()); assertEquals("something went wrong", captured.getDetail()); }