fragment/src/androidTest/java/androidx/fragment/app/FragmentViewTests.java
@Test
    public void doubleAdd() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.simple_container);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final StrictViewFragment fragment1 = new StrictViewFragment();
        fm.beginTransaction().add(R.id.fragmentContainer, fragment1).commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);

        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                try {
                    fm.beginTransaction()
                            .add(R.id.fragmentContainer, fragment1)
                            .addToBackStack(null)
                            .commit();
                    fm.executePendingTransactions();
                    fail("Adding a fragment that is already added should be an error");
                } catch (IllegalStateException e) {
                    // expected
                }
            }
        });
    }
// When you add a fragment that's has already been added, it should throw.
When you add a fragment that's has already been added, it should throw.
When you add a fragment that ' s has already been added it should throw .
@Test
    public void doubleAdd() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.simple_container);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final StrictViewFragment fragment1 = new StrictViewFragment();
        fm.beginTransaction().add(R.id.fragmentContainer, fragment1).commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                try {
                    fm.beginTransaction()
                            .add(R.id.fragmentContainer, fragment1)
                            .addToBackStack(null)
                            .commit();
                    fm.executePendingTransactions();
                    fail("Adding a fragment that is already added should be an error");
                } catch (IllegalStateException e) {
                }
            }
        });
    }
@ Test public void doubleAdd ( ) throws Throwable { FragmentTestUtil . setContentView ( mActivityRule , R . layout . simple_container ) ; final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final StrictViewFragment fragment1 = new StrictViewFragment ( ) ; fm . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 ) . commit ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; mInstrumentation . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { try { fm . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 ) . addToBackStack ( null ) . commit ( ) ; fm . executePendingTransactions ( ) ; fail ( "Adding a fragment that is already added should be an error" ) ; } catch ( IllegalStateException e ) { } } } ) ; }
When you add a fragment that's has already been added, it should throw.
When you add a fragment that ' s has already been added it should throw .
// expected