<commit_before>package com.jamieadkins.gwent;

import android.support.test.runner.AndroidJUnit4;

import com.jamieadkins.gwent.card.CardFilter;
import com.jamieadkins.gwent.data.CardDetails;
import com.jamieadkins.gwent.data.Faction;
import com.jamieadkins.gwent.data.Rarity;
import com.jamieadkins.gwent.data.Type;
import com.jamieadkins.gwent.data.interactor.CardsInteractor;
import com.jamieadkins.gwent.data.interactor.CardsInteractorFirebase;
import com.jamieadkins.gwent.data.interactor.RxDatabaseEvent;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.reactivex.observers.TestObserver;

import static org.junit.Assert.assertTrue;

/**
 * To work on unit tests, switch the Test Artifact in the Build Variants view.
 */
@RunWith(AndroidJUnit4.class)
public class CardsInteractorTest {
    private static final String VALID_CARD_ID = "122212"; // Nenneke.
    private static final int CARD_COUNT = 300;
    private CardsInteractor cardsInteractor;
    private CardFilter cardFilter;

    @Before
    public void setUp() {
        cardsInteractor = CardsInteractorFirebase.getInstance();
    }

    @Test
    public void testGetCard() throws Exception {
        TestObserver<RxDatabaseEvent<CardDetails>> observer = TestObserver.create();
        cardsInteractor.getCard(VALID_CARD_ID).subscribe(observer);

        // Wait until complete.
        observer.awaitTerminalEvent();

        observer.assertComplete();
        observer.assertNoErrors();
        observer.assertValueCount(1);
        CardDetails result = ((RxDatabaseEvent<CardDetails>) observer.getEvents().get(0).get(0)).getValue();
        assertTrue(result.getIngameId().equals(VALID_CARD_ID));
    }

    @Test
    public void testGetCardsNoFilter() throws Exception {
        TestObserver<RxDatabaseEvent<CardDetails>> observer = TestObserver.create();
        cardFilter = new CardFilter();
        cardsInteractor.getCards(cardFilter).subscribe(observer);

        // Wait until complete.
        observer.awaitTerminalEvent();
        observer.assertComplete();
        observer.assertNoErrors();

        assertTrue(observer.getEvents().get(0).size() > CARD_COUNT);
    }

    @Test
    public void testGetCardsFactionFilter() throws Exception {
        TestObserver<RxDatabaseEvent<CardDetails>> observer = TestObserver.create();
        cardFilter = new CardFilter();
        cardFilter.put(Faction.MONSTERS, false);
        cardFilter.put(Faction.NILFGAARD, false);
        cardFilter.put(Faction.SKELLIGE, false);
        cardFilter.put(Faction.SCOIATAEL, false);
        cardFilter.put(Faction.NEUTRAL, false);
        cardFilter.put(Faction.NORTHERN_REALMS, true);
        cardsInteractor.getCards(cardFilter).subscribe(observer);

        // Wait until complete.
        observer.awaitTerminalEvent();<commit_msg>Fixed syntax error in tests<commit_after>package com.jamieadkins.gwent;

import android.support.test.runner.AndroidJUnit4;

import com.jamieadkins.gwent.card.CardFilter;
import com.jamieadkins.gwent.data.CardDetails;
import com.jamieadkins.gwent.data.Faction;
import com.jamieadkins.gwent.data.Rarity;
import com.jamieadkins.gwent.data.Type;
import com.jamieadkins.gwent.data.interactor.CardsInteractor;
import com.jamieadkins.gwent.data.interactor.CardsInteractorFirebase;
import com.jamieadkins.gwent.data.interactor.RxDatabaseEvent;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.reactivex.observers.TestObserver;

import static org.junit.Assert.assertTrue;

/**
 * To work on unit tests, switch the Test Artifact in the Build Variants view.
 */
@RunWith(AndroidJUnit4.class)
public class CardsInteractorTest {
    private static final String VALID_CARD_ID = "122212"; // Nenneke.
    private static final int CARD_COUNT = 300;
    private CardsInteractor cardsInteractor;
    private CardFilter cardFilter;

    @Before
    public void setUp() {
        cardsInteractor = CardsInteractorFirebase.getInstance();
    }

    @Test
    public void testGetCard() throws Exception {
        TestObserver<RxDatabaseEvent<CardDetails>> observer = TestObserver.create();
        cardsInteractor.getCard(VALID_CARD_ID).subscribe(observer);

        // Wait until complete.
        observer.awaitTerminalEvent();

        observer.assertComplete();
        observer.assertNoErrors();
        observer.assertValueCount(1);
        CardDetails result = ((RxDatabaseEvent<CardDetails>) observer.getEvents().get(0).get(0)).getValue();
        assertTrue(result.getIngameId().equals(VALID_CARD_ID));
    }

    @Test
    public void testGetCardsNoFilter() throws Exception {
        TestObserver<RxDatabaseEvent<CardDetails>> observer = TestObserver.create();
        cardFilter = new CardFilter();
        cardsInteractor.getCards(cardFilter).subscribe(observer);

        // Wait until complete.
        observer.awaitTerminalEvent();
        observer.assertComplete();
        observer.assertNoErrors();

        assertTrue(observer.getEvents().get(0).size() > CARD_COUNT);
    }

    @Test
    public void testGetCardsFactionFilter() throws Exception {
        TestObserver<RxDatabaseEvent<CardDetails>> observer = TestObserver.create();
        cardFilter = new CardFilter();
        cardFilter.put(Faction.MONSTERS_ID, false);
        cardFilter.put(Faction.NILFGAARD_ID, false);
        cardFilter.put(Faction.SKELLIGE_ID, false);
        cardFilter.put(Faction.SCOIATAEL_ID, false);
        cardFilter.put(Faction.NEUTRAL_ID, false);
        cardFilter.put(Faction.NORTHERN_REALMS_ID, true);
        cardsInteractor.getCards(cardFilter).subscribe(observer);

        // Wait until complete.
        observer.awaitTerminalEvent();
{'fraction_non_alphanumeric': 0.10332749562171628, 'fraction_numerical': 0.005253940455341506, 'mean_word_length': 3.835732430143946, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '3524255', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1672, 'n_words': 295}