package me.shoutto.sdk;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.io.File;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

/**
 * Unit tests for CreateShoutRequest
 */

@RunWith(PowerMockRunner.class)
@PrepareForTest({Log.class})
public class CreateShoutRequestTest {

    @Mock
    ContentResolver mockContentResolver;

    @Mock
    Context mockContext;

    @Mock
    Cursor mockCursor;

    @Mock
    File mockFile;

    @Mock
    Uri mockUri;

    @Test
    public void isValidTest() {
        CreateShoutRequest createShoutRequest = new CreateShoutRequest();

        // mockFile will be null
        assertFalse(createShoutRequest.isValid());

        // mockFile.length() will be 0
        createShoutRequest.setFile(mockFile);
        assertFalse(createShoutRequest.isValid());

        when(mockFile.length()).thenReturn(100l);
        createShoutRequest.setFile(mockFile);
        assertTrue(createShoutRequest.isValid());
    }

    @Test
    public void setFileFromMediaUriTest() {
        PowerMockito.mockStatic(Log.class);

        when(mockContext.getContentResolver()).thenReturn(mockContentResolver);
        CreateShoutRequest createShoutRequest = new CreateShoutRequest();
        createShoutRequest.setFileFromMediaUri(mockUri, mockContext);

        // Cursor is null
        assertNull(createShoutRequest.getFile());

        String[] filePathColumn = {MediaStore.MediaColumns.DATA};
        when(mockContentResolver.query(mockUri, filePathColumn, null, null, null)).thenReturn(mockCursor);
        createShoutRequest.setFileFromMediaUri(mockUri,mockContext);

        // filePath is null
        assertNull(createShoutRequest.getFile());

        when(mockCursor.getString(0)).thenReturn("mock file path");
        createShoutRequest.setFileFromMediaUri(mockUri,mockContext);

        // File should be set
        assertNotNull(createShoutRequest.getFile());
    }
}

@@ -182,16 +182,47 @@
 aStore;%0A
+import android.text.TextUtils;%0A
 import a
@@ -508,16 +508,140 @@
 o.File;%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.SortedSet;%0A%0Aimport static org.junit.Assert.assertEquals;
 %0Aimport 
@@ -954,16 +954,33 @@
 og.class
+, TextUtils.class
 %7D)%0Apubli
@@ -2634,11 +2634,975 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void adaptBaseEntity_ShouldReturnShoutObjectWithAdaptedProperties() %7B%0A        PowerMockito.mockStatic(TextUtils.class);%0A%0A        String description = %22description%22;%0A        String text = %22text%22;%0A        String topic = %22topic%22;%0A        List%3CString%3E tags = new ArrayList%3C%3E();%0A        tags.add(0, %22tag 1%22);%0A        tags.add(1, %22tag 2%22);%0A%0A        when(TextUtils.join(%22,%22, tags)).thenReturn(%22tag 1,tag 2%22);%0A%0A        CreateShoutRequest createShoutRequest = new CreateShoutRequest();%0A        createShoutRequest.setDescription(description);%0A        createShoutRequest.setTags(tags);%0A        createShoutRequest.setText(text);%0A        createShoutRequest.setTopic(topic);%0A%0A        Shout shout = (Shout)createShoutRequest.adaptToBaseEntity();%0A        assertEquals(description, shout.getDescription());%0A        assertEquals(%22tag 1,tag 2%22, shout.getTags());%0A        assertEquals(text, shout.getText());%0A        assertEquals(topic, shout.getTopic());%0A    %7D
 %0A%7D%0A

Add a new test for some new CreateShoutRequest functionality