<commit_before>package org.mercycorps.translationcards;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.net.Uri;
import android.widget.TextView;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import static junit.framework.Assert.assertNotNull;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.robolectric.Shadows.shadowOf;

@Config(constants = BuildConfig.class, sdk = 21)
@RunWith(RobolectricGradleTestRunner.class)
public class DecksActivityTest {

    private DecksActivity decksActivity;

    @Before
    public void setUp() throws Exception {
        decksActivity = Robolectric.setupActivity(DecksActivity.class);
    }

    @Test
    public void onCreate_shouldCreateDecksActivity() {
        assertNotNull(decksActivity);

        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);
        assertThat(decksListView, is(notNullValue()));

        TextView decksTitle = (TextView) decksActivity.findViewById(R.id.decks_title);
        assertThat(decksTitle.getText().toString(), is("My Decks"));
    }

    @Test
    public void initFeedbackButton_shouldShowFeedbackButton() {
        Button feedbackButton = (Button) decksActivity.findViewById(R.id.feedback_button);

        assertThat(feedbackButton.getText().toString(), is("GIVE FEEDBACK"));
    }

    @Test
    public void initFeedbackButton_shouldLaunchFeedbackForm() {
        decksActivity.findViewById(R.id.feedback_button).performClick();

        Intent expectedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://docs.google.com/forms/d/1p8nJlpFSv03MXWf67pjh_fHyOfjbK9LJgF8hORNcvNM/viewform?entry.1158658650=0.2.1"));
        assertThat(shadowOf(decksActivity).getNextStartedActivity(), is(expectedIntent));
    }

    @Test
    public void initDecksList_shouldHaveDefaultDeck() {
        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);

        assertThat(decksListView.getAdapter().getCount(), is(2));
        assertThat(((Deck) (decksListView.getAdapter().getItem(0))).getLabel(), is("Default"));
    }

    @Test
    public void initDecksList_shouldPopulateDefaultDeckCard() {
        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);
        View decksListItem = decksListView.getAdapter().getView(0, null, decksListView);

        TextView deckName = (TextView) decksListItem.findViewById(R.id.deck_name);
        assertThat(deckName.getText().toString(), is("Default"));

        TextView deckPublisher = (TextView) decksListItem.findViewById(R.id.deck_information);
        assertThat(deckPublisher.getText().toString(), is("My Deck, 02/02/16"));

        TextView originLanguage = (TextView) decksListItem.findViewById(R.id.origin_language);
        assertThat(originLanguage.getText().toString(), is("ENGLISH"));

        TextView translationLanguages = (TextView) decksListItem.findViewById(R.id.translation_languages);
        assertThat(translationLanguages.getText().toString(), is("ARABIC   FARSI   PASHTO"));
    }

    @Test
    public void initDecksList_shouldOpenMainActivityWhenItemClicked() {
        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);
        View decksListItem = decksListView.getAdapter().getView(0, null, decksListView);

        TextView deckName = (TextView) decksListItem.findViewById(R.id.deck_name);
        deckName.performClick();

        Intent expectedIntent = new Intent(decksActivity, TranslationsActivity.class);
        expectedIntent.putExtra("DeckId", 1);
        Intent nextStartedActivity = shadowOf(decksActivity).getNextStartedActivity();<commit_msg>Pat #3 Fix static date issue<commit_after>package org.mercycorps.translationcards;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.net.Uri;
import android.widget.TextView;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import java.text.SimpleDateFormat;
import java.util.Date;

import static junit.framework.Assert.assertNotNull;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.robolectric.Shadows.shadowOf;

@Config(constants = BuildConfig.class, sdk = 21)
@RunWith(RobolectricGradleTestRunner.class)
public class DecksActivityTest {

    private DecksActivity decksActivity;

    @Before
    public void setUp() throws Exception {
        decksActivity = Robolectric.setupActivity(DecksActivity.class);
    }

    @Test
    public void onCreate_shouldCreateDecksActivity() {
        assertNotNull(decksActivity);

        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);
        assertThat(decksListView, is(notNullValue()));

        TextView decksTitle = (TextView) decksActivity.findViewById(R.id.decks_title);
        assertThat(decksTitle.getText().toString(), is("My Decks"));
    }

    @Test
    public void initFeedbackButton_shouldShowFeedbackButton() {
        Button feedbackButton = (Button) decksActivity.findViewById(R.id.feedback_button);

        assertThat(feedbackButton.getText().toString(), is("GIVE FEEDBACK"));
    }

    @Test
    public void initFeedbackButton_shouldLaunchFeedbackForm() {
        decksActivity.findViewById(R.id.feedback_button).performClick();

        Intent expectedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://docs.google.com/forms/d/1p8nJlpFSv03MXWf67pjh_fHyOfjbK9LJgF8hORNcvNM/viewform?entry.1158658650=0.2.1"));
        assertThat(shadowOf(decksActivity).getNextStartedActivity(), is(expectedIntent));
    }

    @Test
    public void initDecksList_shouldHaveDefaultDeck() {
        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);

        assertThat(decksListView.getAdapter().getCount(), is(2));
        assertThat(((Deck) (decksListView.getAdapter().getItem(0))).getLabel(), is("Default"));
    }

    @Test
    public void initDecksList_shouldPopulateDefaultDeckCard() {
        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);
        View decksListItem = decksListView.getAdapter().getView(0, null, decksListView);

        TextView deckName = (TextView) decksListItem.findViewById(R.id.deck_name);
        assertThat(deckName.getText().toString(), is("Default"));

        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
        String date = dateFormat.format(new Date());
        TextView deckInformation = (TextView) decksListItem.findViewById(R.id.deck_information);
        assertThat(deckInformation.getText().toString(), is("My Deck, "+ date));

        TextView originLanguage = (TextView) decksListItem.findViewById(R.id.origin_language);
        assertThat(originLanguage.getText().toString(), is("ENGLISH"));

        TextView translationLanguages = (TextView) decksListItem.findViewById(R.id.translation_languages);
        assertThat(translationLanguages.getText().toString(), is("ARABIC   FARSI   PASHTO"));
    }

    @Test
    public void initDecksList_shouldOpenMainActivityWhenItemClicked() {
        ListView decksListView = (ListView) decksActivity.findViewById(R.id.decks_list);
        View decksListItem = decksListView.getAdapter().getView(0, null, decksListView);

        TextView deckName = (TextView) decksListItem.findViewById(R.id.deck_name);
        deckName.performClick();

        Intent expectedIntent = new Intent(decksActivity, TranslationsActivity.class);
        expectedIntent.putExtra("DeckId", 1);
        Intent nextStartedActivity = shadowOf(decksActivity).getNextStartedActivity();
{'fraction_non_alphanumeric': 0.10977848488557092, 'fraction_numerical': 0.007710194590625383, 'mean_word_length': 4.6710617626648165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5278020', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2284, 'n_words': 382}