<commit_before>package org.wikipedia.test;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.test.filters.SmallTest;

import junit.framework.TestCase;

import org.json.JSONObject;
import org.wikipedia.ParcelableLruCache;
import org.wikipedia.dataclient.WikiSite;
import org.wikipedia.history.HistoryEntry;
import org.wikipedia.page.PageProperties;
import org.wikipedia.page.PageTitle;
import org.wikipedia.pageimages.PageImage;

@SmallTest
public class ParcelableTest extends TestCase {

    private void parcelAndTestObjects(Parcelable p) throws Exception {
        Parcel parcel = Parcel.obtain();
        p.writeToParcel(parcel, 0);

        parcel.setDataPosition(0);
        Parcelable.Creator<?> creator = (Parcelable.Creator<?>) p.getClass().getField("CREATOR").get(null);
        Parcelable newObject = (Parcelable) creator.createFromParcel(parcel);
        assertEquals(p, newObject);
    }

    public void testPageTitle() throws Exception {
        PageTitle title = new PageTitle(null, "Test", WikiSite.forLanguageCode("en"));
        parcelAndTestObjects(title);
    }

    public void testPageTitleTalk() throws Exception {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        PageTitle origTitle = new PageTitle("Talk", "India", wiki);
        parcelAndTestObjects(origTitle);
    }

    public void testWikiSite() throws Exception {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        parcelAndTestObjects(wiki);
    }

    public void testPageProperties() throws Exception {
        PageProperties props = new PageProperties(new JSONObject("{\"protection\":{\"edit\":[\"autoconfirmed\"],\"move\":[\"sysop\"]},\"id\":15580374,\"displaytitle\":\"Something\",\"revision\":615503846,\"lastmodified\":\"\",\"editable\":false,\"mainpage\":false}"));
        parcelAndTestObjects(props);
    }

    public void testLruCache() throws Exception {
        ParcelableLruCache<WikiSite> oldCache = new ParcelableLruCache<>(2, WikiSite.class);
        oldCache.put("english", WikiSite.forLanguageCode("en"));
        oldCache.put("tamil", WikiSite.forLanguageCode("ta"));

        Parcel parcel = Parcel.obtain();
        oldCache.writeToParcel(parcel, 0);

        parcel.setDataPosition(0);
        Parcelable.Creator<?> creator = (Parcelable.Creator<?>) oldCache.getClass().getField("CREATOR").get(null);
        //noinspection unchecked
        ParcelableLruCache<WikiSite> newCache = (ParcelableLruCache<WikiSite>) creator.createFromParcel(parcel);

        assertEquals(newCache.maxSize(), oldCache.maxSize());
        assertEquals(newCache.size(), oldCache.size());
        assertEquals(newCache.get("english"), oldCache.get("english"));
        assertEquals(newCache.get("tamil"), oldCache.get("tamil"));
    }

    public void testHistoryEntry() throws Exception {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        PageTitle title = new PageTitle("Talk", "India", wiki);
        HistoryEntry historyEntry = new HistoryEntry(title, HistoryEntry.SOURCE_EXTERNAL_LINK);

        parcelAndTestObjects(historyEntry);
    }

    public void testPageImage() throws Exception {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        PageTitle title = new PageTitle("Talk", "India", wiki);
        PageImage pageImage = new PageImage(title, "Testing image");

        parcelAndTestObjects(pageImage);
    }
}<commit_msg>Hygiene: convert ParcelableTest to JUnit 4<commit_after>package org.wikipedia.test;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.test.filters.SmallTest;


import org.json.JSONObject;
import org.junit.Test;
import org.wikipedia.ParcelableLruCache;
import org.wikipedia.dataclient.WikiSite;
import org.wikipedia.history.HistoryEntry;
import org.wikipedia.page.PageProperties;
import org.wikipedia.page.PageTitle;
import org.wikipedia.pageimages.PageImage;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

@SmallTest
public class ParcelableTest {
    @Test public void testPageTitle() throws Throwable {
        PageTitle title = new PageTitle(null, "Test", WikiSite.forLanguageCode("en"));
        parcelAndTestObjects(title);
    }

    @Test public void testPageTitleTalk() throws Throwable {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        PageTitle origTitle = new PageTitle("Talk", "India", wiki);
        parcelAndTestObjects(origTitle);
    }

    @Test public void testWikiSite() throws Throwable {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        parcelAndTestObjects(wiki);
    }

    @Test public void testPageProperties() throws Throwable {
        PageProperties props = new PageProperties(new JSONObject("{\"protection\":{\"edit\":[\"autoconfirmed\"],\"move\":[\"sysop\"]},\"id\":15580374,\"displaytitle\":\"Something\",\"revision\":615503846,\"lastmodified\":\"\",\"editable\":false,\"mainpage\":false}"));
        parcelAndTestObjects(props);
    }

    @Test public void testLruCache() throws Throwable {
        ParcelableLruCache<WikiSite> oldCache = new ParcelableLruCache<>(2, WikiSite.class);
        oldCache.put("english", WikiSite.forLanguageCode("en"));
        oldCache.put("tamil", WikiSite.forLanguageCode("ta"));

        Parcel parcel = Parcel.obtain();
        oldCache.writeToParcel(parcel, 0);

        parcel.setDataPosition(0);
        Parcelable.Creator<?> creator = (Parcelable.Creator<?>) oldCache.getClass().getField("CREATOR").get(null);
        //noinspection unchecked
        ParcelableLruCache<WikiSite> newCache = (ParcelableLruCache<WikiSite>) creator.createFromParcel(parcel);

        assertThat(newCache.maxSize(), is(oldCache.maxSize()));
        assertThat(newCache.size(), is(oldCache.size()));
        assertThat(newCache.get("english"), is(oldCache.get("english")));
        assertThat(newCache.get("tamil"), is(oldCache.get("tamil")));
    }

    @Test public void testHistoryEntry() throws Throwable {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        PageTitle title = new PageTitle("Talk", "India", wiki);
        HistoryEntry historyEntry = new HistoryEntry(title, HistoryEntry.SOURCE_EXTERNAL_LINK);

        parcelAndTestObjects(historyEntry);
    }

    @Test public void testPageImage() throws Throwable {
        WikiSite wiki = WikiSite.forLanguageCode("en");
        PageTitle title = new PageTitle("Talk", "India", wiki);
        PageImage pageImage = new PageImage(title, "Testing image");

        parcelAndTestObjects(pageImage);
    }

    private void parcelAndTestObjects(Parcelable p) throws Throwable {
        Parcel parcel = Parcel.obtain();
        p.writeToParcel(parcel, 0);

        parcel.setDataPosition(0);
        Parcelable.Creator<?> creator = (Parcelable.Creator<?>) p.getClass().getField("CREATOR").get(null);
        Parcelable newObject = (Parcelable) creator.createFromParcel(parcel);
        assertThat(p, is(newObject));
    }
}
{'fraction_non_alphanumeric': 0.13243126529437166, 'fraction_numerical': 0.006477616237224701, 'mean_word_length': 4.031136857349747, 'pattern_counts': {'":': 18, '<': 19, '<?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': '4892013', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2016, 'n_words': 372}