### Question:
ItemSelectFragment extends RoboDialogFragment { public static ItemSelectFragment newInstance(CommoditySelectableActivity parent, Category category, ArrayList<?> selectedCommodities, CommodityDisplayStrategy commodityDisplayStrategy, CommoditiesToViewModelsConverter generator, String activityName) { Bundle arguments = new Bundle(); arguments.putSerializable(CATEGORY, category); arguments.putSerializable(SELECTED_COMMODITIES, selectedCommodities); arguments.putSerializable(ACTIVITY_NAME, activityName); ItemSelectFragment fragment = new ItemSelectFragment(); fragment.setArguments(arguments); fragment.parentActivity = parent; fragment.commodityDisplayStrategy = commodityDisplayStrategy; fragment.viewModelsConverter = generator; return fragment; } ItemSelectFragment(); static ItemSelectFragment newInstance(CommoditySelectableActivity parent, Category category, ArrayList<?> selectedCommodities,
                                                 CommodityDisplayStrategy commodityDisplayStrategy,
                                                 CommoditiesToViewModelsConverter generator, String activityName); @Override void onCreate(Bundle savedInstanceState); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); @Override void onResume(); static final String COMMODITY_DISPLAY_STRATEGY; static final String COMMODITIES_TO_VIEW_MODELS_CONVERTER; static final String ACTIVITY_NAME; }### Answer:
@Test public void shouldPreCheckCommoditiesInSelectedCommoditiesListPassedByDispenseActivity() { Category antiMalarials = categoryService.all().get(0); ArrayList<BaseCommodityViewModel> commodities = new ArrayList<>(); Commodity firstCommodity = commodityService.all().get(0); commodities.add(new BaseCommodityViewModel(firstCommodity)); itemSelectFragment = ItemSelectFragment.newInstance(getDispenseActivity(), antiMalarials, commodities, DISALLOW_CLICK_WHEN_OUT_OF_STOCK, getViewModelConverter(), "Activity"); startFragment(itemSelectFragment); Dialog dialog = ShadowDialog.getLatestDialog(); GridView commoditiesLayout = (GridView) dialog.findViewById(R.id.gridViewCommodities); BaseCommodityViewModel loadedCommodity = (BaseCommodityViewModel) commoditiesLayout.getAdapter().getItem(0); assertTrue(loadedCommodity.isSelected()); }
@Test public void testThatCheckboxIsCheckedWhenOrderingCommoditiesWithZeroStock() throws Exception { Category antiMalarials = categoryService.all().get(0); Commodity firstCommodity = commodityService.all().get(0); Commodity spyFirstCommodity = spy(firstCommodity); when(spyFirstCommodity.isOutOfStock()).thenReturn(true); ArrayList<BaseCommodityViewModel> currentlySelectedCommodities = new ArrayList<>(); currentlySelectedCommodities.add(new BaseCommodityViewModel(spyFirstCommodity)); itemSelectFragment = ItemSelectFragment.newInstance(getDispenseActivity(), antiMalarials, currentlySelectedCommodities, ALLOW_CLICK_WHEN_OUT_OF_STOCK, getViewModelConverter(), "Activity"); startFragment(itemSelectFragment); Dialog dialog = ShadowDialog.getLatestDialog(); GridView commoditiesLayout = (GridView) dialog.findViewById(R.id.gridViewCommodities); BaseCommodityViewModel loadedCommodity = (BaseCommodityViewModel) commoditiesLayout.getAdapter().getItem(0); assertTrue(loadedCommodity.isSelected()); }
@Test public void testThatShouldNotShowSomeOfTheCommoditiesIfTheStrategyAllowsHiding() throws Exception { Category vaccines = categoryService.all().get(6); int commodityCount = vaccines.getCommodities().size(); itemSelectFragment = ItemSelectFragment.newInstance(getDispenseActivity(), vaccines, new ArrayList<BaseCommodityViewModel>(), CommodityDisplayStrategy.ALLOW_ONLY_LGA_COMMODITIES, getViewModelConverter(), "Activity"); startFragment(itemSelectFragment); Dialog dialog = ShadowDialog.getLatestDialog(); GridView commoditiesLayout = (GridView) dialog.findViewById(R.id.gridViewCommodities); int expectedCount = commodityCount - 1; assertThat(commoditiesLayout.getAdapter().getCount(), is(expectedCount)); }