### Question:
WebDavFolder extends Folder<WebDavMessage> { private int getMessageCount(boolean read) throws MessagingException { String isRead; int messageCount = 0; Map<String, String> headers = new HashMap<String, String>(); String messageBody; if (read) { isRead = "True"; } else { isRead = "False"; } messageBody = store.getMessageCountXml(isRead); headers.put("Brief", "t"); DataSet dataset = store.processRequest(this.folderUrl, "SEARCH", messageBody, headers); if (dataset != null) { messageCount = dataset.getMessageCount(); } if (K9MailLib.isDebug() && DEBUG_PROTOCOL_WEBDAV) { Timber.v("Counted messages and webdav returned: %d", messageCount); } return messageCount; } WebDavFolder(WebDavStore nStore, String id); void setUrl(String url); @Override void open(int mode); @Override Map<String, String> copyMessages(List<? extends Message> messages, Folder folder); @Override Map<String, String> moveMessages(List<? extends Message> messages, Folder folder); @Override void delete(List<? extends Message> msgs, String trashFolderName); @Override int getMessageCount(); @Override int getUnreadMessageCount(); @Override int getFlaggedMessageCount(); @Override boolean isOpen(); @Override int getMode(); @Override String getId(); @Override String getParentId(); @Override String getName(); @Override boolean exists(); @Override boolean canHaveSubFolders(); @Override void close(); @Override boolean create(FolderType type); @Override void delete(boolean recursive); @Override WebDavMessage getMessage(String uid); @Override List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener); @Override boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate); @Override void fetch(List<WebDavMessage> messages, FetchProfile fp, MessageRetrievalListener<WebDavMessage> listener); @Override void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value); @Override Map<String, String> appendMessages(List<? extends Message> messages); List<? extends Message> appendWebDavMessages(List<? extends Message> messages); @Override boolean equals(Object o); @Override String getUidFromMessageId(Message message); @Override void setFlags(final Set<Flag> flags, boolean value); String getUrl();  }### Answer:
@Test public void can_fetch_message_count() throws Exception { int messageCount = 23; HashMap<String, String> headers = new HashMap<>(); headers.put("Brief", "t"); String messageCountXml = "<xml>MessageCountXml</xml>"; when(mockStore.getMessageCountXml("True")).thenReturn(messageCountXml); when(mockStore.processRequest("https: "SEARCH", messageCountXml, headers)).thenReturn(mockDataSet); when(mockDataSet.getMessageCount()).thenReturn(messageCount); int result = folder.getMessageCount(); assertEquals(messageCount, result); }