### Question:
Whassup { public List<WhatsAppMessage> getMessages(long timestamp, int max) throws IOException { Cursor cursor = queryMessages(timestamp, max); try { if (cursor != null) { List<WhatsAppMessage> messages = new ArrayList<WhatsAppMessage>(cursor.getCount()); while (cursor.moveToNext()) { messages.add(new WhatsAppMessage(cursor)); } return messages; } else { return Collections.emptyList(); } } finally { if (cursor != null) { cursor.close(); } } } Whassup(Context context);   Whassup(DecryptorFactory decryptorFactory, DBProvider dbProvider, DBOpener dbOpener); Cursor queryMessages(); Cursor queryMessages(long timestamp, int max); long getMostRecentTimestamp(boolean ignoreGroups); List<WhatsAppMessage> getMessages(long timestamp, int max); List<WhatsAppMessage> getMessages(); boolean hasBackupDB();  }### Answer:
@Test public void shouldGetMedia() throws Exception { List<WhatsAppMessage> messages = whassup.getMessages(); WhatsAppMessage msg = null; for (WhatsAppMessage message : messages) { if (message.getId() == 82) { msg = message; break; } } assertThat(msg).isNotNull(); assertThat(msg.getMedia()).isNotNull(); Media mediaData = msg.getMedia(); assertThat(mediaData).isNotNull(); assertThat(mediaData.getFileSize()).isEqualTo(67731L); assertThat(mediaData.getFile().getAbsolutePath()).isEqualTo("/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20130526-WA0000.jpg"); }
@Test public void shouldReturnMessagesInAscendingTimestampOrder() throws Exception { List<WhatsAppMessage> messages = whassup.getMessages(); assertThat(messages).isSortedAccordingTo(WhatsAppMessage.TimestampComparator.INSTANCE); WhatsAppMessage first = messages.get(0); WhatsAppMessage last = messages.get(messages.size() - 1); assertThat(first.getTimestamp()).isBefore(last.getTimestamp()); }
@Test public void shouldGetAllMessages() throws Exception { List<WhatsAppMessage> messages = whassup.getMessages(); assertThat(messages).isNotEmpty(); assertThat(messages).hasSize(82); }
@Test public void shouldGetMessagesSinceASpecificTimestamp() throws Exception { List<WhatsAppMessage> messages = whassup.getMessages(1367349391104L, -1); assertThat(messages).isNotEmpty(); assertThat(messages).hasSize(15); }
@Test public void shouldGetMessagesSinceASpecificTimestampAndLimit() throws Exception { List<WhatsAppMessage> messages = whassup.getMessages(1367349391104L, 3); assertThat(messages).isNotEmpty(); assertThat(messages).hasSize(3); }