FragmentController { public void registerOnRequestListener(@NonNull final OnRequestListener listener) { if (requestListeners == null) this.requestListeners = new ArrayList<>(1); if (!requestListeners.contains(listener)) requestListeners.add(listener); } FragmentController(@NonNull final FragmentActivity parentActivity);  FragmentController(@NonNull final Fragment parentFragment);  FragmentController(@NonNull final FragmentManager fragmentManager);  FragmentController(@Nullable final Context context, @NonNull final FragmentManager fragmentManager); @NonNull FragmentManager getFragmentManager(); void setViewContainerId(@IdRes final int containerId); @IdRes int getViewContainerId(); void setFactory(@Nullable final FragmentFactory factory); boolean hasFactory(); @Nullable FragmentFactory getFactory(); void setRequestInterceptor(@Nullable final FragmentRequestInterceptor interceptor); void registerOnRequestListener(@NonNull final OnRequestListener listener); void unregisterOnRequestListener(@NonNull final OnRequestListener listener); void registerOnBackStackChangeListener(@NonNull final OnBackStackChangeListener listener); void unregisterOnBackStackChangeListener(@NonNull final OnBackStackChangeListener listener); @NonNull final FragmentRequest newRequest(); @NonNull final FragmentRequest newRequest(@NonNull final Fragment fragment); @NonNull final FragmentRequest newRequest(final int fragmentId); @SuppressWarnings("NewApi") @NonNull FragmentTransaction createTransaction(@NonNull final FragmentRequest request); @Nullable Fragment findCurrentFragment(); @Nullable Fragment findFragmentByFactoryId(final int factoryFragmentId); boolean hasBackStackEntries(); @Nullable FragmentManager.BackStackEntry getTopBackStackEntry(); void clearBackStack(); boolean clearBackStackImmediate(); final void destroy(); static final String FRAGMENT_TAG; static final int NO_CONTAINER_ID; }
@Test public void testRegisterOnRequestListener() { final FragmentActivity activity = Robolectric.buildActivity(TestCompatActivity.class).create().start().resume().get(); final FragmentController controller = new FragmentController(activity.getSupportFragmentManager()); final FragmentController.OnRequestListener firstMockListener = mock(FragmentController.OnRequestListener.class); final FragmentController.OnRequestListener secondMockListener = mock(FragmentController.OnRequestListener.class); controller.registerOnRequestListener(firstMockListener); controller.registerOnRequestListener(firstMockListener); controller.registerOnRequestListener(secondMockListener); final FragmentRequest mockRequest = new FragmentRequest(controller, FragmentRequest.NO_ID); controller.notifyRequestExecuted(mockRequest); verify(firstMockListener).onRequestExecuted(mockRequest); verify(secondMockListener).onRequestExecuted(mockRequest); verifyNoMoreInteractions(firstMockListener, secondMockListener); }