### Question:
WhatsAppMessage implements Comparable<WhatsAppMessage> { public String getNumber() { if (TextUtils.isEmpty(key_remote_jid)) return null; String[] components = key_remote_jid.split("@", 2); if (components.length > 1) { if (!isGroupMessage()) { return components[0]; } else { return components[0].split("-")[0]; } } else { return null; } } WhatsAppMessage();  WhatsAppMessage(Cursor c); long getId(); boolean isReceived(); Date getTimestamp(); String getText(); String getFilteredText(); int getStatus(); double getLongitude(); double getLatitude(); int getRecipientCount(); String getNumber(); Media getMedia(); Receipt getReceipt(); boolean hasMediaAttached(); boolean hasText(); @Override String toString(); @Override int compareTo(WhatsAppMessage another); boolean isDirectMessage(); boolean isGroupMessage(); static final String TABLE; static final String GROUP; static final String DIRECT; }### Answer:
@Test public void shouldParseNumber() throws Exception { WhatsAppMessage m = new WhatsAppMessage(); m.key_remote_jid = "4915773981234@s.whatsapp.net"; assertThat(m.getNumber()).isEqualTo("4915773981234"); }
@Test public void shouldParseNumberFromGroupMessage() throws Exception { WhatsAppMessage m = new WhatsAppMessage(); m.key_remote_jid = "4915773981234-12345@g.us"; assertThat(m.getNumber()).isEqualTo("4915773981234"); }
@Test public void shouldParseNumberWithInvalidSpec() throws Exception { WhatsAppMessage m = new WhatsAppMessage(); assertThat(m.getNumber()).isNull(); m.key_remote_jid = "foobaz"; assertThat(m.getNumber()).isNull(); }