// Path: slyce-messaging/src/main/java/it/slyce/messaging/message/MediaMessage.java
// public class MediaMessage extends Message {
//     private String url;
// 
//     public String getUrl() {
//         return url;
//     }
// 
//     public void setUrl(String url) {
//         this.url = url;
//     }
// 
//     @Override
//     public MessageItem toMessageItem(Context context){
//         if (this.source == MessageSource.EXTERNAL_USER)
//             return new MessageExternalUserMediaItem(this, context);
//         else
//             return new MessageInternalUserMediaItem(this, context);
//     }
// }
// 
// Path: slyce-messaging/src/main/java/it/slyce/messaging/message/MessageSource.java
// public enum MessageSource {
//     LOCAL_USER,
//     EXTERNAL_USER,
//     GENERAL
// }
// 
// Path: slyce-messaging/src/main/java/it/slyce/messaging/message/TextMessage.java
// public class TextMessage extends Message {
//     private String text;
// 
//     public String getText() {
//         return text;
//     }
// 
//     public void setText(String text) {
//         this.text = text;
//     }
// 
//     @Override
//     public MessageItem toMessageItem(Context context){
//         if (this.source == MessageSource.EXTERNAL_USER)
//             return new MessageExternalUserTextItem(this, context);
//         else
//             return new MessageInternalUserTextItem(this, context);
//     }
// }
// 
// Path: slyce-messaging/src/main/java/it/slyce/messaging/utils/MessageUtils.java
// public class MessageUtils {
// 
//     public static void markMessageItemAtIndexIfFirstOrLastFromSource(int i, List<MessageItem> messageItems) {
//         if (i < 0 || i >= messageItems.size()) {
//             return;
//         }
// 
//         MessageItem messageItem = messageItems.get(i);
//         messageItem.setIsFirstConsecutiveMessageFromSource(false);
//         messageItem.setIsLastConsecutiveMessageFromSource(false);
// 
//         if (previousMessageIsNotFromSameSource(i, messageItems)) {
//             messageItem.setIsFirstConsecutiveMessageFromSource(true);
//         }
// 
//         if (isTheLastConsecutiveMessageFromSource(i, messageItems)) {
//             messageItem.setIsLastConsecutiveMessageFromSource(true);
//         }
//     }
// 
//     private static boolean previousMessageIsNotFromSameSource(int i, List<MessageItem> messageItems) {
//         return i == 0 ||
//                 previousMessageIsSpinner(i, messageItems) ||
//                 previousMessageIsFromAnotherSender(i, messageItems);
//     }
// 
//     private static boolean previousMessageIsFromAnotherSender(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i - 1).getMessageSource() != messageItems.get(i).getMessageSource();
//     }
// 
//     private static boolean previousMessageIsSpinner(int i, List<MessageItem> messageItems) {
//         return isSpinnerMessage(i - 1, messageItems);
//     }
// 
//     private static boolean isTheLastConsecutiveMessageFromSource(int i, List<MessageItem> messageItems) {
//         if (isSpinnerMessage(i, messageItems)) {
//             return false;
//         }
// 
//         return i == messageItems.size() - 1 ||
//                 nextMessageHasDifferentSource(i, messageItems) ||
//                 messageItems.get(i).getMessage() == null ||
//                 messageItems.get(i + 1).getMessage() == null ||
//                 nextMessageWasAtLeastAnHourAfterThisOne(i, messageItems);
//     }
// 
//     private static boolean nextMessageWasAtLeastAnHourAfterThisOne(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i + 1).getMessage().getDate() - messageItems.get(i).getMessage().getDate() > 1000 * 60 * 60; // one hour
//     }
// 
//     private static boolean nextMessageHasDifferentSource(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i).getMessageSource() != messageItems.get(i + 1).getMessageSource();
//     }
// 
//     private static boolean isSpinnerMessage(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i).getMessageItemType() == MessageItemType.SPINNER;
//     }
// }


import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import it.slyce.messaging.message.MediaMessage;
import it.slyce.messaging.message.MessageSource;
import it.slyce.messaging.message.TextMessage;
import it.slyce.messaging.message.messageItem.MessageItem;
import it.slyce.messaging.utils.MessageUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
package it.slyce.messaging;





/**
 * Created by audrey on 7/14/16.
 */
public class MessageUtilsTest {

    List<MessageItem> messageItems;

    @Before
    public void before() {
        messageItems = new ArrayList<>();

        // incoming text
        TextMessage firstIncoming = new TextMessage();
        firstIncoming.setSource(MessageSource.EXTERNAL_USER);
        firstIncoming.setText("hi");
        messageItems.add(firstIncoming.toMessageItem(null));
        // incoming text
        TextMessage secondIncoming = new TextMessage();
        secondIncoming.setSource(MessageSource.EXTERNAL_USER);
        secondIncoming.setText("second message");
        messageItems.add(secondIncoming.toMessageItem(null));
        // incoming image
// Path: slyce-messaging/src/main/java/it/slyce/messaging/message/MediaMessage.java
// public class MediaMessage extends Message {
//     private String url;
// 
//     public String getUrl() {
//         return url;
//     }
// 
//     public void setUrl(String url) {
//         this.url = url;
//     }
// 
//     @Override
//     public MessageItem toMessageItem(Context context){
//         if (this.source == MessageSource.EXTERNAL_USER)
//             return new MessageExternalUserMediaItem(this, context);
//         else
//             return new MessageInternalUserMediaItem(this, context);
//     }
// }
// 
// Path: slyce-messaging/src/main/java/it/slyce/messaging/message/MessageSource.java
// public enum MessageSource {
//     LOCAL_USER,
//     EXTERNAL_USER,
//     GENERAL
// }
// 
// Path: slyce-messaging/src/main/java/it/slyce/messaging/message/TextMessage.java
// public class TextMessage extends Message {
//     private String text;
// 
//     public String getText() {
//         return text;
//     }
// 
//     public void setText(String text) {
//         this.text = text;
//     }
// 
//     @Override
//     public MessageItem toMessageItem(Context context){
//         if (this.source == MessageSource.EXTERNAL_USER)
//             return new MessageExternalUserTextItem(this, context);
//         else
//             return new MessageInternalUserTextItem(this, context);
//     }
// }
// 
// Path: slyce-messaging/src/main/java/it/slyce/messaging/utils/MessageUtils.java
// public class MessageUtils {
// 
//     public static void markMessageItemAtIndexIfFirstOrLastFromSource(int i, List<MessageItem> messageItems) {
//         if (i < 0 || i >= messageItems.size()) {
//             return;
//         }
// 
//         MessageItem messageItem = messageItems.get(i);
//         messageItem.setIsFirstConsecutiveMessageFromSource(false);
//         messageItem.setIsLastConsecutiveMessageFromSource(false);
// 
//         if (previousMessageIsNotFromSameSource(i, messageItems)) {
//             messageItem.setIsFirstConsecutiveMessageFromSource(true);
//         }
// 
//         if (isTheLastConsecutiveMessageFromSource(i, messageItems)) {
//             messageItem.setIsLastConsecutiveMessageFromSource(true);
//         }
//     }
// 
//     private static boolean previousMessageIsNotFromSameSource(int i, List<MessageItem> messageItems) {
//         return i == 0 ||
//                 previousMessageIsSpinner(i, messageItems) ||
//                 previousMessageIsFromAnotherSender(i, messageItems);
//     }
// 
//     private static boolean previousMessageIsFromAnotherSender(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i - 1).getMessageSource() != messageItems.get(i).getMessageSource();
//     }
// 
//     private static boolean previousMessageIsSpinner(int i, List<MessageItem> messageItems) {
//         return isSpinnerMessage(i - 1, messageItems);
//     }
// 
//     private static boolean isTheLastConsecutiveMessageFromSource(int i, List<MessageItem> messageItems) {
//         if (isSpinnerMessage(i, messageItems)) {
//             return false;
//         }
// 
//         return i == messageItems.size() - 1 ||
//                 nextMessageHasDifferentSource(i, messageItems) ||
//                 messageItems.get(i).getMessage() == null ||
//                 messageItems.get(i + 1).getMessage() == null ||
//                 nextMessageWasAtLeastAnHourAfterThisOne(i, messageItems);
//     }
// 
//     private static boolean nextMessageWasAtLeastAnHourAfterThisOne(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i + 1).getMessage().getDate() - messageItems.get(i).getMessage().getDate() > 1000 * 60 * 60; // one hour
//     }
// 
//     private static boolean nextMessageHasDifferentSource(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i).getMessageSource() != messageItems.get(i + 1).getMessageSource();
//     }
// 
//     private static boolean isSpinnerMessage(int i, List<MessageItem> messageItems) {
//         return messageItems.get(i).getMessageItemType() == MessageItemType.SPINNER;
//     }
// }


// Path: slyce-messaging/src/test/java/it/slyce/messaging/MessageUtilsTest.java
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import it.slyce.messaging.message.MediaMessage;
import it.slyce.messaging.message.MessageSource;
import it.slyce.messaging.message.TextMessage;
import it.slyce.messaging.message.messageItem.MessageItem;
import it.slyce.messaging.utils.MessageUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

package it.slyce.messaging;





/**
 * Created by audrey on 7/14/16.
 */
public class MessageUtilsTest {

    List<MessageItem> messageItems;

    @Before
    public void before() {
        messageItems = new ArrayList<>();

        // incoming text
        TextMessage firstIncoming = new TextMessage();
        firstIncoming.setSource(MessageSource.EXTERNAL_USER);
        firstIncoming.setText("hi");
        messageItems.add(firstIncoming.toMessageItem(null));
        // incoming text
        TextMessage secondIncoming = new TextMessage();
        secondIncoming.setSource(MessageSource.EXTERNAL_USER);
        secondIncoming.setText("second message");
        messageItems.add(secondIncoming.toMessageItem(null));
        // incoming image
        MediaMessage incomingImage = new MediaMessage();