### Question:
ReceiveCommoditiesAdapter extends ArrayAdapter<ReceiveCommodityViewModel> { @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(resource, parent, false); holder.textViewCommodityName = (TextView) convertView.findViewById(R.id.textViewCommodityName); holder.imageButtonCancel = (ImageButton) convertView.findViewById(R.id.imageButtonCancel); holder.editTextAllocatedQuantity = (NumberTextView) convertView.findViewById(R.id.editTextAllocatedQuantity); holder.editTextReceivedQuantity = (NumberTextView) convertView.findViewById(R.id.editTextReceivedQuantity); holder.textViewDifferenceQuantity = (TextView) convertView.findViewById(R.id.textViewDifferenceQuantity); holder.textViewAllocatedQuantityLabel = (TextView) convertView.findViewById(R.id.textViewAllocationLabel); holder.textViewDifferenceQuantityLabel = (TextView) convertView.findViewById(R.id.textViewDifferenceQuantityLabel); ReceiveCommodityViewModel viewModel = getItem(position); initialiseQuantities(holder, viewModel); activateCancelButton(holder.imageButtonCancel, viewModel); setupTextWatchers(holder, viewModel); return convertView; } ReceiveCommoditiesAdapter(Context context, int resource, List<ReceiveCommodityViewModel> objects); void setQuantityAllocatedDisplay(boolean quantityAllocatedDisplay); boolean isQuantityAllocatedDisplay(); @Override View getView(int position, View convertView, ViewGroup parent);  }### Answer:
@Test public void shouldShowReceiveCommodityFields() throws Exception { View rowView = adapter.getView(0, null, parent); String commodityName = ((TextView) rowView.findViewById(R.id.textViewCommodityName)).getText().toString(); int difference = getIntFromString(((TextView) rowView.findViewById(R.id.textViewDifferenceQuantity)).getText().toString()); int quantityOrdered = getIntFromString(((EditText) rowView.findViewById(R.id.editTextAllocatedQuantity)).getText().toString()); int quantityReceived = getIntFromString(((EditText) rowView.findViewById(R.id.editTextReceivedQuantity)).getText().toString()); assertThat(commodityName, is(PANADOL)); assertThat(quantityOrdered, is(QUANTITY_ORDERED)); assertThat(quantityReceived, is(QUANTITY_RECEIVED)); assertThat(difference, is(QUANTITY_DIFFERENCE)); }
@Test public void shouldUpdateDifferenceTextViewWhenQuantityOrderedAndQuantityReceivedChanges() { View rowView = adapter.getView(0, null, parent); EditText editTextQuantityOrdered = (EditText) rowView.findViewById(R.id.editTextAllocatedQuantity); EditText editTextQuantityReceived = (EditText) rowView.findViewById(R.id.editTextReceivedQuantity); editTextQuantityOrdered.setText("7"); int difference = getIntFromString(((TextView) rowView.findViewById(R.id.textViewDifferenceQuantity)).getText().toString()); assertThat(difference, is(-4)); editTextQuantityReceived.setText("2"); difference = getIntFromString(((TextView) rowView.findViewById(R.id.textViewDifferenceQuantity)).getText().toString()); assertThat(difference, is(-5)); }
@Test public void shouldUpdateQuantitiesInViewModelWhenReceivedAndOrderedQuantitiesChange() throws Exception { View rowView = adapter.getView(0, null, parent); EditText editTextQuantityAllocated = (EditText) rowView.findViewById(R.id.editTextAllocatedQuantity); EditText editTextQuantityReceived = (EditText) rowView.findViewById(R.id.editTextReceivedQuantity); editTextQuantityAllocated.setText("7"); ReceiveCommodityViewModel viewModel = adapter.getItem(0); assertThat(viewModel.getQuantityAllocated(), is(7)); editTextQuantityReceived.setText("2"); viewModel = adapter.getItem(0); assertThat(viewModel.getQuantityReceived(), is(2)); }