Loading src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java +35 −35 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ import com.google.android.material.tabs.TabLayoutMediator; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; /** * Base fragment class for profile settings. Loading Loading @@ -295,8 +296,7 @@ public abstract class ProfileSelectFragment extends DashboardFragment { personalFragmentConstructor, workFragmentConstructor, privateFragmentConstructor, new PrivateSpaceInfoProvider() {}, new ManagedProfileInfoProvider() {}); new PrivateSpaceInfoProvider() {}); } /** Loading @@ -309,36 +309,35 @@ public abstract class ProfileSelectFragment extends DashboardFragment { FragmentConstructor personalFragmentConstructor, FragmentConstructor workFragmentConstructor, FragmentConstructor privateFragmentConstructor, PrivateSpaceInfoProvider privateSpaceInfoProvider, ManagedProfileInfoProvider managedProfileInfoProvider) { PrivateSpaceInfoProvider privateSpaceInfoProvider) { Fragment[] result = new Fragment[0]; ArrayList<Fragment> fragments = new ArrayList<>(); try { final Bundle personalOnly = bundle != null ? bundle : new Bundle(); personalOnly.putInt(EXTRA_PROFILE, ProfileType.PERSONAL); final Fragment personalFragment = personalFragmentConstructor.constructAndGetFragment(); personalFragment.setArguments(personalOnly); fragments.add(personalFragment); if (managedProfileInfoProvider.isManagedProfilePresent(context)) { final Bundle workOnly = bundle != null ? bundle.deepCopy() : new Bundle(); workOnly.putInt(EXTRA_PROFILE, ProfileType.WORK); final Fragment workFragment = workFragmentConstructor.constructAndGetFragment(); workFragment.setArguments(workOnly); fragments.add(workFragment); } if (Flags.allowPrivateProfile() && !privateSpaceInfoProvider.isPrivateSpaceLocked(context)) { final Bundle privateOnly = bundle != null ? bundle.deepCopy() : new Bundle(); privateOnly.putInt(EXTRA_PROFILE, ProfileType.PRIVATE); final Fragment privateFragment = privateFragmentConstructor.constructAndGetFragment(); privateFragment.setArguments(privateOnly); fragments.add(privateFragment); UserManager userManager = context.getSystemService(UserManager.class); List<UserInfo> userInfos = userManager.getProfiles(UserHandle.myUserId()); for (UserInfo userInfo : userInfos) { if (userInfo.getUserHandle().isSystem()) { fragments.add(createAndGetFragment( ProfileType.PERSONAL, bundle != null ? bundle : new Bundle(), personalFragmentConstructor)); } else if (userInfo.isManagedProfile()) { fragments.add(createAndGetFragment( ProfileType.WORK, bundle != null ? bundle.deepCopy() : new Bundle(), workFragmentConstructor)); } else if (Flags.allowPrivateProfile() && userInfo.isPrivateProfile()) { if (!privateSpaceInfoProvider.isPrivateSpaceLocked(context)) { fragments.add(createAndGetFragment( ProfileType.PRIVATE, bundle != null ? bundle.deepCopy() : new Bundle(), privateFragmentConstructor)); } } else { Log.d(TAG, "Not showing tab for unsupported user"); } } result = new Fragment[fragments.size()]; Loading @@ -350,6 +349,14 @@ public abstract class ProfileSelectFragment extends DashboardFragment { return result; } private static Fragment createAndGetFragment( @ProfileType int profileType, Bundle bundle, FragmentConstructor fragmentConstructor) { bundle.putInt(EXTRA_PROFILE, profileType); final Fragment fragment = fragmentConstructor.constructAndGetFragment(); fragment.setArguments(bundle); return fragment; } interface FragmentConstructor { Fragment constructAndGetFragment(); } Loading @@ -360,13 +367,6 @@ public abstract class ProfileSelectFragment extends DashboardFragment { } } interface ManagedProfileInfoProvider { default boolean isManagedProfilePresent(Context context) { return Utils.doesProfileOfTypeExists( context.getSystemService(UserManager.class), ProfileType.WORK); } } static class ViewPagerAdapter extends FragmentStateAdapter { private final Fragment[] mChildFragments; Loading tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectFragmentTest.java +49 −36 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ package com.android.settings.dashboard.profileselector; import static android.content.Intent.EXTRA_USER_ID; import static android.os.UserManager.USER_TYPE_FULL_SYSTEM; import static android.os.UserManager.USER_TYPE_PROFILE_MANAGED; import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE; import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.EXTRA_PROFILE; import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.PERSONAL_TAB; Loading @@ -30,9 +33,11 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.Flags; import android.platform.test.flag.junit.SetFlagsRule; import android.util.ArraySet; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; Loading @@ -51,7 +56,9 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @RunWith(RobolectricTestRunner.class) Loading @@ -60,6 +67,9 @@ import java.util.Set; com.android.settings.testutils.shadow.ShadowFragment.class, }) public class ProfileSelectFragmentTest { private static final String PRIMARY_USER_NAME = "primary"; private static final String MANAGED_USER_NAME = "managed"; private static final String PRIVATE_USER_NAME = "private"; private Context mContext; private TestProfileSelectFragment mFragment; Loading Loading @@ -151,6 +161,8 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenOnlyPersonal_returnsOneFragment() { mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -162,6 +174,10 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenPrivateDisabled_returnsOneFragment() { mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -173,12 +189,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return true; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return false; } }); assertThat(fragments).hasLength(1); } Loading @@ -186,6 +196,10 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenPrivateEnabled_returnsTwoFragments() { mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -197,12 +211,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return false; } }); assertThat(fragments).hasLength(2); } Loading @@ -210,6 +218,10 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenManagedProfile_returnsTwoFragments() { mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -221,12 +233,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return true; } }); assertThat(fragments).hasLength(2); } Loading @@ -234,6 +240,12 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenAllProfiles_returnsThreeFragments() { mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -245,12 +257,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return true; } }); assertThat(fragments).hasLength(3); } Loading @@ -258,6 +264,12 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenAvailableBundle_returnsFragmentsWithCorrectBundles() { mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Bundle bundle = new Bundle(); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, Loading @@ -270,20 +282,21 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return true; } }); assertThat(fragments).hasLength(3); assertThat(fragments[0].getArguments().getInt(EXTRA_PROFILE)) .isEqualTo(ProfileSelectFragment.ProfileType.PERSONAL); assertThat(fragments[1].getArguments().getInt(EXTRA_PROFILE)) .isEqualTo(ProfileSelectFragment.ProfileType.WORK); assertThat(fragments[2].getArguments().getInt(EXTRA_PROFILE)) .isEqualTo(ProfileSelectFragment.ProfileType.PRIVATE); List<Integer> foundProfileTypesList = new ArrayList<>(); for (Fragment fragment : fragments) { foundProfileTypesList.add(fragment.getArguments().getInt(EXTRA_PROFILE)); } assertThat(foundProfileTypesList).hasSize(3); Set<Integer> foundProfileTypes = new ArraySet<>(foundProfileTypesList); assertThat(foundProfileTypes).containsExactly( ProfileSelectFragment.ProfileType.PERSONAL, ProfileSelectFragment.ProfileType.WORK, ProfileSelectFragment.ProfileType.PRIVATE); } public static class TestProfileSelectFragment extends ProfileSelectFragment { Loading Loading
src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java +35 −35 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ import com.google.android.material.tabs.TabLayoutMediator; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; /** * Base fragment class for profile settings. Loading Loading @@ -295,8 +296,7 @@ public abstract class ProfileSelectFragment extends DashboardFragment { personalFragmentConstructor, workFragmentConstructor, privateFragmentConstructor, new PrivateSpaceInfoProvider() {}, new ManagedProfileInfoProvider() {}); new PrivateSpaceInfoProvider() {}); } /** Loading @@ -309,36 +309,35 @@ public abstract class ProfileSelectFragment extends DashboardFragment { FragmentConstructor personalFragmentConstructor, FragmentConstructor workFragmentConstructor, FragmentConstructor privateFragmentConstructor, PrivateSpaceInfoProvider privateSpaceInfoProvider, ManagedProfileInfoProvider managedProfileInfoProvider) { PrivateSpaceInfoProvider privateSpaceInfoProvider) { Fragment[] result = new Fragment[0]; ArrayList<Fragment> fragments = new ArrayList<>(); try { final Bundle personalOnly = bundle != null ? bundle : new Bundle(); personalOnly.putInt(EXTRA_PROFILE, ProfileType.PERSONAL); final Fragment personalFragment = personalFragmentConstructor.constructAndGetFragment(); personalFragment.setArguments(personalOnly); fragments.add(personalFragment); if (managedProfileInfoProvider.isManagedProfilePresent(context)) { final Bundle workOnly = bundle != null ? bundle.deepCopy() : new Bundle(); workOnly.putInt(EXTRA_PROFILE, ProfileType.WORK); final Fragment workFragment = workFragmentConstructor.constructAndGetFragment(); workFragment.setArguments(workOnly); fragments.add(workFragment); } if (Flags.allowPrivateProfile() && !privateSpaceInfoProvider.isPrivateSpaceLocked(context)) { final Bundle privateOnly = bundle != null ? bundle.deepCopy() : new Bundle(); privateOnly.putInt(EXTRA_PROFILE, ProfileType.PRIVATE); final Fragment privateFragment = privateFragmentConstructor.constructAndGetFragment(); privateFragment.setArguments(privateOnly); fragments.add(privateFragment); UserManager userManager = context.getSystemService(UserManager.class); List<UserInfo> userInfos = userManager.getProfiles(UserHandle.myUserId()); for (UserInfo userInfo : userInfos) { if (userInfo.getUserHandle().isSystem()) { fragments.add(createAndGetFragment( ProfileType.PERSONAL, bundle != null ? bundle : new Bundle(), personalFragmentConstructor)); } else if (userInfo.isManagedProfile()) { fragments.add(createAndGetFragment( ProfileType.WORK, bundle != null ? bundle.deepCopy() : new Bundle(), workFragmentConstructor)); } else if (Flags.allowPrivateProfile() && userInfo.isPrivateProfile()) { if (!privateSpaceInfoProvider.isPrivateSpaceLocked(context)) { fragments.add(createAndGetFragment( ProfileType.PRIVATE, bundle != null ? bundle.deepCopy() : new Bundle(), privateFragmentConstructor)); } } else { Log.d(TAG, "Not showing tab for unsupported user"); } } result = new Fragment[fragments.size()]; Loading @@ -350,6 +349,14 @@ public abstract class ProfileSelectFragment extends DashboardFragment { return result; } private static Fragment createAndGetFragment( @ProfileType int profileType, Bundle bundle, FragmentConstructor fragmentConstructor) { bundle.putInt(EXTRA_PROFILE, profileType); final Fragment fragment = fragmentConstructor.constructAndGetFragment(); fragment.setArguments(bundle); return fragment; } interface FragmentConstructor { Fragment constructAndGetFragment(); } Loading @@ -360,13 +367,6 @@ public abstract class ProfileSelectFragment extends DashboardFragment { } } interface ManagedProfileInfoProvider { default boolean isManagedProfilePresent(Context context) { return Utils.doesProfileOfTypeExists( context.getSystemService(UserManager.class), ProfileType.WORK); } } static class ViewPagerAdapter extends FragmentStateAdapter { private final Fragment[] mChildFragments; Loading
tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectFragmentTest.java +49 −36 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ package com.android.settings.dashboard.profileselector; import static android.content.Intent.EXTRA_USER_ID; import static android.os.UserManager.USER_TYPE_FULL_SYSTEM; import static android.os.UserManager.USER_TYPE_PROFILE_MANAGED; import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE; import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.EXTRA_PROFILE; import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.PERSONAL_TAB; Loading @@ -30,9 +33,11 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.Flags; import android.platform.test.flag.junit.SetFlagsRule; import android.util.ArraySet; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; Loading @@ -51,7 +56,9 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @RunWith(RobolectricTestRunner.class) Loading @@ -60,6 +67,9 @@ import java.util.Set; com.android.settings.testutils.shadow.ShadowFragment.class, }) public class ProfileSelectFragmentTest { private static final String PRIMARY_USER_NAME = "primary"; private static final String MANAGED_USER_NAME = "managed"; private static final String PRIVATE_USER_NAME = "private"; private Context mContext; private TestProfileSelectFragment mFragment; Loading Loading @@ -151,6 +161,8 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenOnlyPersonal_returnsOneFragment() { mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -162,6 +174,10 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenPrivateDisabled_returnsOneFragment() { mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -173,12 +189,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return true; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return false; } }); assertThat(fragments).hasLength(1); } Loading @@ -186,6 +196,10 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenPrivateEnabled_returnsTwoFragments() { mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -197,12 +211,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return false; } }); assertThat(fragments).hasLength(2); } Loading @@ -210,6 +218,10 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenManagedProfile_returnsTwoFragments() { mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -221,12 +233,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return true; } }); assertThat(fragments).hasLength(2); } Loading @@ -234,6 +240,12 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenAllProfiles_returnsThreeFragments() { mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, null /* bundle */, Loading @@ -245,12 +257,6 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return true; } }); assertThat(fragments).hasLength(3); } Loading @@ -258,6 +264,12 @@ public class ProfileSelectFragmentTest { @Test public void testGetFragments_whenAvailableBundle_returnsFragmentsWithCorrectBundles() { mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); mUserManager.addProfile( new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM)); mUserManager.addProfile( new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED)); mUserManager.addProfile( new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE)); Bundle bundle = new Bundle(); Fragment[] fragments = ProfileSelectFragment.getFragments( mContext, Loading @@ -270,20 +282,21 @@ public class ProfileSelectFragmentTest { public boolean isPrivateSpaceLocked(Context context) { return false; } }, new ProfileSelectFragment.ManagedProfileInfoProvider() { @Override public boolean isManagedProfilePresent(Context context) { return true; } }); assertThat(fragments).hasLength(3); assertThat(fragments[0].getArguments().getInt(EXTRA_PROFILE)) .isEqualTo(ProfileSelectFragment.ProfileType.PERSONAL); assertThat(fragments[1].getArguments().getInt(EXTRA_PROFILE)) .isEqualTo(ProfileSelectFragment.ProfileType.WORK); assertThat(fragments[2].getArguments().getInt(EXTRA_PROFILE)) .isEqualTo(ProfileSelectFragment.ProfileType.PRIVATE); List<Integer> foundProfileTypesList = new ArrayList<>(); for (Fragment fragment : fragments) { foundProfileTypesList.add(fragment.getArguments().getInt(EXTRA_PROFILE)); } assertThat(foundProfileTypesList).hasSize(3); Set<Integer> foundProfileTypes = new ArraySet<>(foundProfileTypesList); assertThat(foundProfileTypes).containsExactly( ProfileSelectFragment.ProfileType.PERSONAL, ProfileSelectFragment.ProfileType.WORK, ProfileSelectFragment.ProfileType.PRIVATE); } public static class TestProfileSelectFragment extends ProfileSelectFragment { Loading