<commit_before>package com.xtremelabs.robolectric.tester.android.util;

import android.os.Bundle;
import android.support.v4.app.*;
import android.view.View;
import android.view.ViewGroup;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.shadows.SerializedFragmentState;
import com.xtremelabs.robolectric.shadows.ShadowFragment;
import com.xtremelabs.robolectric.shadows.ShadowFragmentActivity;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import static com.xtremelabs.robolectric.Robolectric.shadowOf;

public class TestFragmentManager extends FragmentManager {
    private Map<Integer, Fragment> fragmentsById = new HashMap<Integer, Fragment>();
    private Map<String, Fragment> fragmentsByTag = new HashMap<String, Fragment>();
    private FragmentActivity activity;

    public TestFragmentManager(FragmentActivity activity) {
        this.activity = activity;
    }

    public FragmentActivity getActivity() {
        return activity;
    }

    @Override
    public FragmentTransaction beginTransaction() {
        return new TestFragmentTransaction(this);
    }

    @Override
    public boolean executePendingTransactions() {
        return false;
    }

    @Override
    public Fragment findFragmentById(int id) {
        return fragmentsById.get(id);
    }

    @Override
    public Fragment findFragmentByTag(String tag) {
        return fragmentsByTag.get(tag);
    }

    @Override
    public void popBackStack() {
    }

    @Override
    public boolean popBackStackImmediate() {
        return false;
    }

    @Override
    public void popBackStack(String name, int flags) {
    }

    @Override
    public boolean popBackStackImmediate(String name, int flags) {
        return false;
    }

    @Override
    public void popBackStack(int id, int flags) {
    }

    @Override
    public boolean popBackStackImmediate(int id, int flags) {
        return false;
    }

    @Override
    public int getBackStackEntryCount() {
        return 0;
    }

    @Override
    public BackStackEntry getBackStackEntryAt(int index) {
        return null;
    }

    @Override
    public void addOnBackStackChangedListener(OnBackStackChangedListener listener) {
    }

    @Override
    public void removeOnBackStackChangedListener(OnBackStackChangedListener listener) {
    }

    @Override
    public void putFragment(Bundle bundle, String key, Fragment fragment) {
    }

    @Override
    public Fragment getFragment(Bundle bundle, String key) {
        Object[] fragments = (Object[]) bundle.getSerializable(ShadowFragmentActivity.FRAGMENTS_TAG);
        for (Object object : fragments) {
            SerializedFragmentState fragment = (SerializedFragmentState) object;
            if (fragment.tag.equals(key)) {
                // TODO deserialize state
                return Robolectric.newInstanceOf(fragment.fragmentClass);
            }
        }
        return null;
    }

    @Override
    public Fragment.SavedState saveFragmentInstanceState(Fragment f) {
        return null;
    }

    @Override
    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    }

    public void addDialogFragment(String tag, DialogFragment fragment) {
        fragmentsByTag.put(tag, fragment);
    }

    public void addFragment(int containerViewId, String tag, Fragment fragment, boolean replace) {
        fragmentsById.put(containerViewId, fragment);
        fragmentsByTag.put(tag, fragment);

        shadowOf(fragment).setTag(tag);
        shadowOf(fragment).setContainerViewId(containerViewId);
        shadowOf(fragment).setShouldReplace(replace);

        shadowOf(fragment).setActivity(activity);
        fragment.onAttach(activity);
        fragment.onCreate(null);
    }

    public void startFragment(Fragment fragment) {
        ViewGroup container = null;
        ShadowFragment shadowFragment = shadowOf(fragment);
        if (shadowOf(activity).getContentView() != null) {
            container = (ViewGroup) activity.findViewById(shadowFragment.getContainerViewId());
        }

        View view = fragment.onCreateView(activity.getLayoutInflater(), container, null);
        shadowFragment.setView(view);

        fragment.onViewCreated(view, null);
        if (container != null) {
            if (shadowFragment.getShouldReplace()) {
                container.removeAllViews();
            }
            container.addView(view);
        }

        fragment.onActivityCreated(shadowFragment.getSavedInstanceState());
        fragment.onStart();
    }

    public HashMap<Integer, Fragment> getFragments() {
        return new HashMap<Integer, Fragment>(fragmentsById);
    }
}<commit_msg>startFragment passes the saved instance state to the fragment's onCreateView() method instead of null<commit_after>package com.xtremelabs.robolectric.tester.android.util;

import android.os.Bundle;
import android.support.v4.app.*;
import android.view.View;
import android.view.ViewGroup;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.shadows.SerializedFragmentState;
import com.xtremelabs.robolectric.shadows.ShadowFragment;
import com.xtremelabs.robolectric.shadows.ShadowFragmentActivity;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import static com.xtremelabs.robolectric.Robolectric.shadowOf;

public class TestFragmentManager extends FragmentManager {
    private Map<Integer, Fragment> fragmentsById = new HashMap<Integer, Fragment>();
    private Map<String, Fragment> fragmentsByTag = new HashMap<String, Fragment>();
    private FragmentActivity activity;

    public TestFragmentManager(FragmentActivity activity) {
        this.activity = activity;
    }

    public FragmentActivity getActivity() {
        return activity;
    }

    @Override
    public FragmentTransaction beginTransaction() {
        return new TestFragmentTransaction(this);
    }

    @Override
    public boolean executePendingTransactions() {
        return false;
    }

    @Override
    public Fragment findFragmentById(int id) {
        return fragmentsById.get(id);
    }

    @Override
    public Fragment findFragmentByTag(String tag) {
        return fragmentsByTag.get(tag);
    }

    @Override
    public void popBackStack() {
    }

    @Override
    public boolean popBackStackImmediate() {
        return false;
    }

    @Override
    public void popBackStack(String name, int flags) {
    }

    @Override
    public boolean popBackStackImmediate(String name, int flags) {
        return false;
    }

    @Override
    public void popBackStack(int id, int flags) {
    }

    @Override
    public boolean popBackStackImmediate(int id, int flags) {
        return false;
    }

    @Override
    public int getBackStackEntryCount() {
        return 0;
    }

    @Override
    public BackStackEntry getBackStackEntryAt(int index) {
        return null;
    }

    @Override
    public void addOnBackStackChangedListener(OnBackStackChangedListener listener) {
    }

    @Override
    public void removeOnBackStackChangedListener(OnBackStackChangedListener listener) {
    }

    @Override
    public void putFragment(Bundle bundle, String key, Fragment fragment) {
    }

    @Override
    public Fragment getFragment(Bundle bundle, String key) {
        Object[] fragments = (Object[]) bundle.getSerializable(ShadowFragmentActivity.FRAGMENTS_TAG);
        for (Object object : fragments) {
            SerializedFragmentState fragment = (SerializedFragmentState) object;
            if (fragment.tag.equals(key)) {
                // TODO deserialize state
                return Robolectric.newInstanceOf(fragment.fragmentClass);
            }
        }
        return null;
    }

    @Override
    public Fragment.SavedState saveFragmentInstanceState(Fragment f) {
        return null;
    }

    @Override
    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    }

    public void addDialogFragment(String tag, DialogFragment fragment) {
        fragmentsByTag.put(tag, fragment);
    }

    public void addFragment(int containerViewId, String tag, Fragment fragment, boolean replace) {
        fragmentsById.put(containerViewId, fragment);
        fragmentsByTag.put(tag, fragment);

        shadowOf(fragment).setTag(tag);
        shadowOf(fragment).setContainerViewId(containerViewId);
        shadowOf(fragment).setShouldReplace(replace);

        shadowOf(fragment).setActivity(activity);
        fragment.onAttach(activity);
        fragment.onCreate(null);
    }

    public void startFragment(Fragment fragment) {
        ViewGroup container = null;
        ShadowFragment shadowFragment = shadowOf(fragment);
        if (shadowOf(activity).getContentView() != null) {
            container = (ViewGroup) activity.findViewById(shadowFragment.getContainerViewId());
        }

        View view = fragment.onCreateView(activity.getLayoutInflater(), container, shadowFragment.getSavedInstanceState());
        shadowFragment.setView(view);

        fragment.onViewCreated(view, null);
        if (container != null) {
            if (shadowFragment.getShouldReplace()) {
                container.removeAllViews();
            }
            container.addView(view);
        }

        fragment.onActivityCreated(shadowFragment.getSavedInstanceState());
        fragment.onStart();
    }

    public HashMap<Integer, Fragment> getFragments() {
        return new HashMap<Integer, Fragment>(fragmentsById);
    }
}
{'fraction_non_alphanumeric': 0.08529228208862076, 'fraction_numerical': 0.00041605991262741833, 'mean_word_length': 3.1107310816588285, 'pattern_counts': {'":': 0, '<': 15, '<?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': '5632545', 'n_tokens_mistral': 2591, 'n_tokens_neox': 2468, 'n_words': 567}