package org.robolectric.util;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

import static org.robolectric.Robolectric.shadowOf;

public class FragmentTestUtil {
  public static void startFragment(Fragment fragment) {
    FragmentActivity activity = createActivity();

    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    fragmentManager.beginTransaction()
        .add(fragment, null)
        .commit();
  }

  private static FragmentActivity createActivity() {
    FragmentActivity activity = new FragmentActivity();
    initActivity(activity);
    return activity;
  }

  private static void initActivity(FragmentActivity activity) {
    shadowOf(activity).callOnCreate(null);
    shadowOf(activity).callOnStart();
    shadowOf(activity).callOnResume();
  }
}

@@ -158,16 +158,52 @@
 Manager;
+%0Aimport org.robolectric.Robolectric;
 %0A%0Aimport
@@ -617,294 +617,176 @@
     
-FragmentActivity activity = new FragmentActivity();%0A    initActivity(activity);%0A    return activity;%0A  %7D%0A%0A  private static void initActivity(FragmentActivity activity) %7B%0A    shadowOf(activity).callOnCreate(null);%0A    shadowOf(activity).callOnStart();%0A    shadowOf(activity).callOnResume
+ActivityController%3CFragmentActivity%3E controller = Robolectric.buildActivity(FragmentActivity.class);%0A    controller.create().start().resume();%0A    return controller.get
 ();%0A

Use ActivityController in FragmentTestUtil. Fixes #563.