<commit_before>package com.akexorcist.sleepingforless.ui;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;

import com.akexorcist.sleepingforless.R;
import com.akexorcist.sleepingforless.view.bookmark.BookmarkActivity;
import com.akexorcist.sleepingforless.view.feed.FeedAdapter;
import com.akexorcist.sleepingforless.view.search.SearchActivity;
import com.akexorcist.sleepingforless.view.settings.SettingsActivity;
import com.flipboard.bottomsheet.BottomSheetLayout;
import com.robotium.solo.Condition;
import com.robotium.solo.Solo;

/**
 * Created by Akexorcist on 4/17/2016 AD.
 */
@SuppressWarnings("rawtypes")
public class FeedActivityTest extends ActivityInstrumentationTestCase2 {

    private static final String PACKAGE_NAME = "com.akexorcist.sleepingforless.view.feed";
    private static final String ACTIVITY_NAME = "FeedActivity";

    private Solo solo;

    private static Class<?> launcherActivityClass;

    static {
        try {
            launcherActivityClass = Class.forName(PACKAGE_NAME + "." + ACTIVITY_NAME);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("unchecked")
    public FeedActivityTest() throws ClassNotFoundException {
        super(launcherActivityClass);
    }

    public void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation());
        getActivity();
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
        super.tearDown();
    }

    public void testRun() {
        solo.waitForActivity("FeedActivity", 1000);
        solo.clickOnView(solo.getView(R.id.fab_menu));
        solo.sleep(1000);
    }

    public void testFabMenuClick() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View shadow = solo.getView(R.id.view_content_shadow);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        assertEquals(View.INVISIBLE, fabMenu.getVisibility());
        assertEquals(View.VISIBLE, shadow.getVisibility());
        solo.clickOnView(shadow);
        solo.sleep(500);
        assertEquals(View.VISIBLE, fabMenu.getVisibility());
        assertEquals(View.GONE, shadow.getVisibility());
    }

    public void testPostFetch() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        final RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedList.getAdapter().getItemCount() > 0;
            }
        }, 4000);
        assertEquals(31, feedList.getAdapter().getItemCount());
    }

    public void testPostScrollDownToLoadMore() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        final RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedList.getAdapter().getItemCount() > 0;
            }
        }, 4000);
        feedList.smoothScrollToPosition(31);
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedList.getAdapter().getItemCount() > 31;
            }
        }, 4000);
        assertEquals(61, feedList.getAdapter().getItemCount());
    }

    public void testPostPullToRefresh() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        final RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        final SwipeRefreshLayout pullRefresh = (SwipeRefreshLayout) solo.getView(R.id.srl_feed_list);
        final FeedAdapter feedAdapter = (FeedAdapter) feedList.getAdapter();
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedAdapter.getItemCount() > 0;
            }
        }, 4000);
        assertEquals(31, feedAdapter.getItemCount());
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                pullRefresh.setRefreshing(true);
            }
        });
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return !pullRefresh.isRefreshing();
            }
        }, 4000);
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedAdapter.getItemCount() > 1;
            }
        }, 4000);
        assertEquals(31, feedAdapter.getItemCount());
    }

    public void testClickOnMenuSettings() {
        String settingActivityName = SettingsActivity.class.getSimpleName();
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSettings = solo.getView(R.id.btn_menu_settings);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSettings);
        solo.sleep(1000);
        assertEquals(settingActivityName, solo.getCurrentActivity().getClass().getSimpleName());
    }

    public void testClickOnMenuBookmark() {
        String bookmarkActivityName = BookmarkActivity.class.getSimpleName();
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSettings = solo.getView(R.id.btn_menu_bookmark);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSettings);
        solo.sleep(1000);
        assertEquals(bookmarkActivityName, solo.getCurrentActivity().getClass().getSimpleName());
    }

    public void testClickOnMenuSearch() {
        String searchActivityName = SearchActivity.class.getSimpleName();
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSettings = solo.getView(R.id.btn_menu_search);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSettings);
        solo.sleep(1000);
        assertEquals(searchActivityName, solo.getCurrentActivity().getClass().getSimpleName());
    }

    public void testClickOnSameSortType() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSort = solo.getView(R.id.btn_menu_sort);
        BottomSheetLayout bottomSheetSort = (BottomSheetLayout) solo.getView(R.id.bsl_menu);
        assertEquals(false, bottomSheetSort.isSheetShowing());
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSort);
        solo.sleep(500);
        assertEquals(true, bottomSheetSort.isSheetShowing());
        solo.clickOnMenuItem("Published Date");
        solo.sleep(500);
        assertEquals(false, bottomSheetSort.isSheetShowing());
    }

    public void testClickOnDefferentSortType() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        View fabMenu = solo.getView(R.id.fab_menu);<commit_msg>Add more test Fix uncoverage test<commit_after>package com.akexorcist.sleepingforless.ui;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.test.ActivityInstrumentationTestCase2;
import android.view.Display;
import android.view.View;

import com.akexorcist.sleepingforless.R;
import com.akexorcist.sleepingforless.view.bookmark.BookmarkActivity;
import com.akexorcist.sleepingforless.view.feed.FeedAdapter;
import com.akexorcist.sleepingforless.view.post.PostByIdActivity;
import com.akexorcist.sleepingforless.view.search.SearchActivity;
import com.akexorcist.sleepingforless.view.settings.SettingsActivity;
import com.flipboard.bottomsheet.BottomSheetLayout;
import com.robotium.solo.Condition;
import com.robotium.solo.Solo;

/**
 * Created by Akexorcist on 4/17/2016 AD.
 */
@SuppressWarnings("rawtypes")
public class FeedActivityTest extends ActivityInstrumentationTestCase2 {

    private static final String PACKAGE_NAME = "com.akexorcist.sleepingforless.view.feed";
    private static final String ACTIVITY_NAME = "FeedActivity";

    private Solo solo;

    private static Class<?> launcherActivityClass;

    static {
        try {
            launcherActivityClass = Class.forName(PACKAGE_NAME + "." + ACTIVITY_NAME);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("unchecked")
    public FeedActivityTest() throws ClassNotFoundException {
        super(launcherActivityClass);
    }

    public void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation());
        getActivity();
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
        super.tearDown();
    }

    public void testFabMenuClick() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View shadow = solo.getView(R.id.view_content_shadow);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        assertEquals(View.INVISIBLE, fabMenu.getVisibility());
        assertEquals(View.VISIBLE, shadow.getVisibility());
        solo.clickOnView(shadow);
        solo.sleep(500);
        assertEquals(View.VISIBLE, fabMenu.getVisibility());
        assertEquals(View.GONE, shadow.getVisibility());
    }

    public void testPostFetch() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        final RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedList.getAdapter().getItemCount() > 0;
            }
        }, 4000);
        assertEquals(31, feedList.getAdapter().getItemCount());
    }

    public void testPostScrollDownToLoadMore() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        final RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedList.getAdapter().getItemCount() > 0;
            }
        }, 4000);
        feedList.smoothScrollToPosition(31);
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedList.getAdapter().getItemCount() > 31;
            }
        }, 4000);
        assertEquals(61, feedList.getAdapter().getItemCount());
    }

    public void testPostPullToRefresh() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        final RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        final SwipeRefreshLayout pullRefresh = (SwipeRefreshLayout) solo.getView(R.id.srl_feed_list);
        final FeedAdapter feedAdapter = (FeedAdapter) feedList.getAdapter();
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedAdapter.getItemCount() > 0;
            }
        }, 4000);
        assertEquals(31, feedAdapter.getItemCount());
        Display display = solo.getCurrentActivity().getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        solo.drag(width / 2, width / 2, height / 2, height / 2 + height / 3, 20);
        assertEquals(true, pullRefresh.isRefreshing());
        solo.sleep(300);
        assertEquals(1, feedAdapter.getItemCount());
        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return !pullRefresh.isRefreshing();
            }
        }, 4000);
        assertEquals(31, feedAdapter.getItemCount());
    }

    public void testClickOnMenuSettings() {
        String settingActivityName = SettingsActivity.class.getSimpleName();
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSettings = solo.getView(R.id.btn_menu_settings);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSettings);
        solo.waitForActivity(settingActivityName, 1000);
        assertEquals(settingActivityName, solo.getCurrentActivity().getClass().getSimpleName());
    }

    public void testClickOnMenuBookmark() {
        String bookmarkActivityName = BookmarkActivity.class.getSimpleName();
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSettings = solo.getView(R.id.btn_menu_bookmark);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSettings);
        solo.waitForActivity(bookmarkActivityName, 1000);
        assertEquals(bookmarkActivityName, solo.getCurrentActivity().getClass().getSimpleName());
    }

    public void testClickOnMenuSearch() {
        String searchActivityName = SearchActivity.class.getSimpleName();
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSettings = solo.getView(R.id.btn_menu_search);
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSettings);
        solo.sleep(1000);
        solo.waitForActivity(searchActivityName, 1000);
        assertEquals(searchActivityName, solo.getCurrentActivity().getClass().getSimpleName());
    }

    public void testClickOnPost() {
        String postActivityName = PostByIdActivity.class.getSimpleName();
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        final RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);

        solo.waitForCondition(new Condition() {
            @Override
            public boolean isSatisfied() {
                return feedList.getAdapter().getItemCount() > 0;
            }
        }, 4000);
        solo.clickInRecyclerView(0);
        solo.sleep(800);
        assertEquals(postActivityName, solo.getCurrentActivity().getClass().getSimpleName());
    }

    public void testClickOnSameSortType() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        View fabMenu = solo.getView(R.id.fab_menu);
        View menuSort = solo.getView(R.id.btn_menu_sort);
        BottomSheetLayout bottomSheetSort = (BottomSheetLayout) solo.getView(R.id.bsl_menu);
        assertEquals(false, bottomSheetSort.isSheetShowing());
        solo.clickOnView(fabMenu);
        solo.sleep(500);
        solo.clickOnView(menuSort);
        solo.sleep(500);
        assertEquals(true, bottomSheetSort.isSheetShowing());
        solo.clickOnMenuItem("Published Date");
        solo.sleep(500);
        assertEquals(false, bottomSheetSort.isSheetShowing());
    }

    public void testClickOnDifferentSortType() {
        solo.waitForActivity(ACTIVITY_NAME, 1000);
        RecyclerView feedList = (RecyclerView) solo.getView(R.id.rv_feed_list);
        View fabMenu = solo.getView(R.id.fab_menu);
{'fraction_non_alphanumeric': 0.10630407911001236, 'fraction_numerical': 0.018020948539457418, 'mean_word_length': 2.909460834181078, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3875982', 'n_tokens_mistral': 4616, 'n_tokens_neox': 4386, 'n_words': 714}