preference/src/androidTest/java/androidx/preference/tests/PreferenceParentGroupTest.java
@Test
    @UiThreadTest
    public void parentAddRemoveTest() {
        PreferenceManager manager = new PreferenceManager(mContext);

        PreferenceScreen screen = manager.createPreferenceScreen(mContext);
        assertNull(screen.getParent());

        PreferenceCategory category = new PreferenceCategory(mContext);
        assertNull(category.getParent());

        CheckBoxPreference pref = new CheckBoxPreference(mContext);
        assertNull(pref.getParent());

        screen.addPreference(category);
        assertEquals(screen, category.getParent());

        category.addPreference(pref);
        assertEquals(category, pref.getParent());

        screen.removePreference(category);
        assertNull(category.getParent());

        category.removePreference(pref);
        assertNull(pref.getParent());
    }
/**
     * Tests that parent PreferenceGroup is correctly assigned and removed when creating preferences
     * from code.
     */
Tests that parent PreferenceGroup is correctly assigned and removed when creating preferences
from code.
Tests that parent PreferenceGroup is correctly assigned and removed when creating preferences from code .
@Test
    @UiThreadTest
    public void parentAddRemoveTest() {
        PreferenceManager manager = new PreferenceManager(mContext);
        PreferenceScreen screen = manager.createPreferenceScreen(mContext);
        assertNull(screen.getParent());
        PreferenceCategory category = new PreferenceCategory(mContext);
        assertNull(category.getParent());
        CheckBoxPreference pref = new CheckBoxPreference(mContext);
        assertNull(pref.getParent());
        screen.addPreference(category);
        assertEquals(screen, category.getParent());
        category.addPreference(pref);
        assertEquals(category, pref.getParent());
        screen.removePreference(category);
        assertNull(category.getParent());
        category.removePreference(pref);
        assertNull(pref.getParent());
    }
@ Test @ UiThreadTest public void parentAddRemoveTest ( ) { PreferenceManager manager = new PreferenceManager ( mContext ) ; PreferenceScreen screen = manager . createPreferenceScreen ( mContext ) ; assertNull ( screen . getParent ( ) ) ; PreferenceCategory category = new PreferenceCategory ( mContext ) ; assertNull ( category . getParent ( ) ) ; CheckBoxPreference pref = new CheckBoxPreference ( mContext ) ; assertNull ( pref . getParent ( ) ) ; screen . addPreference ( category ) ; assertEquals ( screen , category . getParent ( ) ) ; category . addPreference ( pref ) ; assertEquals ( category , pref . getParent ( ) ) ; screen . removePreference ( category ) ; assertNull ( category . getParent ( ) ) ; category . removePreference ( pref ) ; assertNull ( pref . getParent ( ) ) ; }
Tests that parent PreferenceGroup is correctly assigned and removed when creating preferences
 from code.
Tests that parent PreferenceGroup is correctly assigned and removed when creating preferences from code .