nus-yam/ex-repair huggingface dataset:
Program: 146392
Project: 146392
Buggy source:
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  View view=inflater.inflate(R.layout.fragment_order_confirmation,container,false);
  Button buttonOrderConfirm=(Button)view.findViewById(R.id.buttonOrderConfirm);
  Button buttonOrderGoBack=(Button)view.findViewById(R.id.buttonOrderGoBack);
  TextView textViewSRVNumber=(TextView)view.findViewById(R.id.textViewSRVNumber);
  ListView listViewOrderItems=(ListView)view.findViewById(R.id.listViewConfirmOrderItems);
  getDialog().setCanceledOnTouchOutside(false);
  getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  buttonOrderConfirm.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      orderService.saveOrder(order);
      showToastMessage(getString(R.string.order_successful));
      dismiss();
      FragmentActivity activity=getActivity();
      if (activity != null) {
        activity.finish();
        startActivity(activity.getIntent());
      }
    }
  }
);
  textViewSRVNumber.setText(order.getSrvNumber());
  buttonOrderGoBack.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      dismiss();
    }
  }
);
  listViewOrderItems.addHeaderView(inflater.inflate(R.layout.confirm_header_order,container));
  ConfirmOrderAdapter adapter=new ConfirmOrderAdapter(getActivity(),R.layout.confirm_order_list_item,order.getItems());
  listViewOrderItems.setAdapter(adapter);
  return view;
}

Fixed version (ground truth):
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  View view=inflater.inflate(R.layout.fragment_order_confirmation,container,false);
  Button buttonOrderConfirm=(Button)view.findViewById(R.id.buttonOrderConfirm);
  Button buttonOrderGoBack=(Button)view.findViewById(R.id.buttonOrderGoBack);
  TextView textViewSRVNumber=(TextView)view.findViewById(R.id.textViewSRVNumber);
  ListView listViewOrderItems=(ListView)view.findViewById(R.id.listViewConfirmOrderItems);
  getDialog().setCanceledOnTouchOutside(false);
  getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  setupConfirmButton(buttonOrderConfirm);
  textViewSRVNumber.setText(order.getSrvNumber());
  buttonOrderGoBack.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      dismiss();
    }
  }
);
  setupList(inflater,container,listViewOrderItems);
  return view;
}
Program: 146393
Project: 146393
Buggy source:
@Override public Throwable handleError(RetrofitError cause){
  if (cause.getResponse() == null) {
    return new LmisException(cause);
  }
  e("String_Node_Str",cause.getResponse().getReason());
  e("String_Node_Str",cause.getResponse().getUrl());
  for (  Header header : cause.getResponse().getHeaders()) {
    e("String_Node_Str",String.format("String_Node_Str",header.getName(),header.getValue()));
  }
  if (cause.isNetworkError()) {
    i("String_Node_Str",cause.getMessage());
    return new LmisException(messageNetworkError);
  }
  int statusCode=cause.getResponse().getStatus();
  if (statusCode == SC_NOT_FOUND) {
    i("String_Node_Str","String_Node_Str" + statusCode);
    return new LmisException(urlNotFound);
  }
  if (statusCode == SC_INTERNAL_SERVER_ERROR) {
    i("String_Node_Str","String_Node_Str" + statusCode);
    return new LmisException(internalServerError);
  }
  if (statusCode != SC_OK) {
    i("String_Node_Str","String_Node_Str" + statusCode);
    return new LmisException(messageInvalidLoginCredential);
  }
  return new LmisException(cause.getMessage());
}

Fixed version (ground truth):
@Override public Throwable handleError(RetrofitError cause){
  if (cause.getResponse() == null) {
    return new LmisException(cause);
  }
  printHeaders(cause);
  if (cause.isNetworkError()) {
    i("String_Node_Str",cause.getMessage());
    return new LmisException(messageNetworkError);
  }
  LmisException exception=checkForHTTPErrors(cause.getResponse().getStatus());
  if (exception != null) {
    return exception;
  }
 else {
    return new LmisException(cause.getMessage());
  }
}
Program: 146394
Project: 146394
Buggy source:
public ArrayList<OrderType> syncOrderTypes(){
  final ArrayList<OrderType> orderTypes=new ArrayList<>();
  final List<String> reasons=lmisServer.fetchOrderTypes(userService.getRegisteredUser());
  dbUtil.withDao(OrderType.class,new DbUtil.Operation<OrderType,Void>(){
    @Override public Void operate(    Dao<OrderType,String> dao) throws SQLException {
      dao.delete(dao.queryForAll());
      for (      String reason : reasons) {
        OrderType data=new OrderType(reason);
        dao.create(data);
        orderTypes.add(data);
      }
      return null;
    }
  }
);
  return orderTypes;
}

Fixed version (ground truth):
public ArrayList<OrderType> syncOrderTypes(){
  final ArrayList<OrderType> orderTypes=new ArrayList<>();
  final List<String> reasons=lmisServer.fetchOrderTypes(userService.getRegisteredUser());
  dbUtil.withDao(OrderType.class,new DbUtil.Operation<OrderType,Void>(){
    @Override public Void operate(    Dao<OrderType,String> dao) throws SQLException {
      saveOrderTypes(dao,reasons,orderTypes);
      return null;
    }
  }
);
  return orderTypes;
}
Program: 146395
Project: 146395
Buggy source:
@Override public Void operate(Dao<OrderType,String> dao) throws SQLException {
  dao.delete(dao.queryForAll());
  for (  String reason : reasons) {
    OrderType data=new OrderType(reason);
    dao.create(data);
    orderTypes.add(data);
  }
  return null;
}

Fixed version (ground truth):
@Override public Void operate(Dao<OrderType,String> dao) throws SQLException {
  saveOrderTypes(dao,reasons,orderTypes);
  return null;
}
Program: 146396
Project: 146396
Buggy source:
public List<OrderReason> syncOrderReasons(){
  final ArrayList<OrderReason> savedReasons=new ArrayList<>();
  final List<String> reasons=lmisServer.fetchOrderReasons(userService.getRegisteredUser());
  dbUtil.withDao(OrderReason.class,new DbUtil.Operation<OrderReason,Void>(){
    @Override public Void operate(    Dao<OrderReason,String> dao) throws SQLException {
      dao.delete(dao.queryForAll());
      for (      String reason : reasons) {
        OrderReason data=new OrderReason(reason);
        dao.create(data);
        savedReasons.add(data);
      }
      return null;
    }
  }
);
  return savedReasons;
}

Fixed version (ground truth):
public List<OrderReason> syncOrderReasons(){
  final ArrayList<OrderReason> savedReasons=new ArrayList<>();
  final List<String> reasons=lmisServer.fetchOrderReasons(userService.getRegisteredUser());
  dbUtil.withDao(OrderReason.class,new DbUtil.Operation<OrderReason,Void>(){
    @Override public Void operate(    Dao<OrderReason,String> dao) throws SQLException {
      saveReasons(dao,reasons,savedReasons);
      return null;
    }
  }
);
  return savedReasons;
}
Program: 146397
Project: 146397
Buggy source:
private String getErrorMessage(String commodityName){
  String formatString=adapter.getContext().getString(R.string.unexpected_order_quantity_error);
  return String.format(formatString,orderCommodityViewModel.getExpectedOrderQuantity(),commodityName);
}

Fixed version (ground truth):
private String getErrorMessage(String commodityName){
  String formatString=adapter.getContext().getString(R.string.unexpected_order_quantity_error);
  return String.format(formatString,commodityName,orderCommodityViewModel.getQuantityEntered());
}
Program: 146398
Project: 146398
Buggy source:
private boolean allocationIdIsValid(){
  return textViewAllocationId.getError() == null;
}

Fixed version (ground truth):
private boolean allocationIdIsValid(){
  return textViewAllocationId.getError() == null && !isBlank(textViewAllocationId.getText().toString());
}
Program: 146399
Project: 146399
Buggy source:
private void createAggregation(final Commodity commodity){
  dbUtil.withDao(Aggregation.class,new Operation<Aggregation,Void>(){
    @Override public Void operate(    Dao<Aggregation,String> dao) throws SQLException {
      Aggregation aggregation=commodity.getAggregation();
      dao.create(aggregation);
      saveAllAggregationFields(aggregation);
      return null;
    }
  }
);
}

Fixed version (ground truth):
private void createAggregation(final Commodity commodity){
  dbUtil.withDao(Aggregation.class,new Operation<Aggregation,Void>(){
    @Override public Void operate(    Dao<Aggregation,String> dao) throws SQLException {
      Aggregation aggregation=commodity.getAggregation();
      dao.createOrUpdate(aggregation);
      saveAllAggregationFields(aggregation);
      return null;
    }
  }
);
}
Program: 146400
Project: 146400
Buggy source:
@Test public void shouldSaveCommodityAggregations(){
  List<Category> categories=new ArrayList<>();
  Category category=new Category("String_Node_Str");
  Commodity commodity=new Commodity("String_Node_Str");
  Aggregation aggregation=new Aggregation();
  aggregation.setId("String_Node_Str");
  aggregation.setName("String_Node_Str");
  AggregationField field=new AggregationField();
  field.setId("String_Node_Str");
  field.setName("String_Node_Str");
  aggregation.setAggregationFields(Arrays.asList(field));
  commodity.setAggregation(aggregation);
  category.addCommodity(commodity);
  categories.add(category);
  commodityService.saveToDatabase(categories);
  Long numberOfAggregations=dbUtil.withDao(Aggregation.class,new DbUtil.Operation<Aggregation,Long>(){
    @Override public Long operate(    Dao<Aggregation,String> dao) throws SQLException {
      return dao.countOf();
    }
  }
);
  Long numberOfFields=dbUtil.withDao(AggregationField.class,new DbUtil.Operation<AggregationField,Long>(){
    @Override public Long operate(    Dao<AggregationField,String> dao) throws SQLException {
      return dao.countOf();
    }
  }
);
  assertThat(numberOfAggregations,is(1L));
  assertThat(numberOfFields,is(1L));
}

Fixed version (ground truth):
@Test public void shouldSaveCommodityAggregations(){
  List<Category> categories=getTestCategories();
  commodityService.saveToDatabase(categories);
  Long numberOfAggregations=dbUtil.withDao(Aggregation.class,new DbUtil.Operation<Aggregation,Long>(){
    @Override public Long operate(    Dao<Aggregation,String> dao) throws SQLException {
      return dao.countOf();
    }
  }
);
  Long numberOfFields=dbUtil.withDao(AggregationField.class,new DbUtil.Operation<AggregationField,Long>(){
    @Override public Long operate(    Dao<AggregationField,String> dao) throws SQLException {
      return dao.countOf();
    }
  }
);
  assertThat(numberOfAggregations,is(1L));
  assertThat(numberOfFields,is(1L));
}
Program: 146401
Project: 146401
Buggy source:
private Date lastDayOfThisMonth(){
  Calendar cal=Calendar.getInstance();
  cal.set(Calendar.DAY_OF_MONTH,Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH));
  return cal.getTime();
}

Fixed version (ground truth):
private Date lastDayOfThisMonth(){
  Calendar cal=Calendar.getInstance();
  cal.set(Calendar.DAY_OF_MONTH,Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH));
  cal.set(Calendar.HOUR_OF_DAY,Calendar.getInstance().getActualMaximum(Calendar.HOUR_OF_DAY));
  cal.set(Calendar.MINUTE,Calendar.getInstance().getActualMaximum(Calendar.MINUTE));
  return cal.getTime();
}
Program: 146402
Project: 146402
Buggy source:
private Date firstDayOfThisMonth(){
  Calendar cal=Calendar.getInstance();
  cal.set(Calendar.DAY_OF_MONTH,Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH));
  return cal.getTime();
}

Fixed version (ground truth):
private Date firstDayOfThisMonth(){
  Calendar cal=Calendar.getInstance();
  cal.set(Calendar.DAY_OF_MONTH,Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH));
  cal.set(Calendar.HOUR_OF_DAY,Calendar.getInstance().getActualMinimum(Calendar.HOUR_OF_DAY));
  cal.set(Calendar.MINUTE,Calendar.getInstance().getActualMinimum(Calendar.MINUTE));
  return cal.getTime();
}
Program: 146403
Project: 146403
Buggy source:
private void setupOrderReasonsSpinner(final Spinner spinnerOrderReasons,final TextView textViewStartDate,final CommodityViewModel orderCommodityViewModel,final TextView textViewEndDate){
  spinnerOrderReasons.setOnItemSelectedListener(new LmisOnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      orderCommodityViewModel.setOrderReasonPosition(position);
      OrderReason orderReason=getReason(spinnerOrderReasons.getAdapter().getItem(position).toString());
      orderCommodityViewModel.setReasonForOrder(orderReason);
      doUpdateEndDate(spinnerOrderReasons,orderCommodityViewModel,textViewStartDate,textViewEndDate);
    }
  }
);
  setupSpinnerData(spinnerOrderReasons,orderReasons,orderCommodityViewModel.getOrderReasonPosition());
}

Fixed version (ground truth):
private void setupOrderReasonsSpinner(final Spinner spinnerOrderReasons,final TextView textViewStartDate,final CommodityViewModel orderCommodityViewModel,final TextView textViewEndDate){
  spinnerOrderReasons.setOnItemSelectedListener(new LmisOnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      orderCommodityViewModel.setOrderReasonPosition(position);
      OrderReason orderReason=getReason(((OrderReason)spinnerOrderReasons.getSelectedItem()).getReason());
      orderCommodityViewModel.setReasonForOrder(orderReason);
      doUpdateEndDate(spinnerOrderReasons,orderCommodityViewModel,textViewStartDate,textViewEndDate);
    }
  }
);
  setupSpinnerData(spinnerOrderReasons,orderReasons,orderCommodityViewModel.getOrderReasonPosition());
}
Program: 146404
Project: 146404
Buggy source:
private void doUpdateEndDate(Spinner spinner,CommodityViewModel orderCommodityViewModel,TextView textViewStartDate,TextView textViewEndDate){
  Integer orderReasonPosition=orderCommodityViewModel.getOrderReasonPosition();
  String item=spinner.getItemAtPosition(orderReasonPosition).toString();
  if (item.equalsIgnoreCase(ROUTINE)) {
    String startDate=textViewStartDate.getText().toString();
    populateEndDate(startDate,30,textViewEndDate);
    textViewEndDate.setEnabled(false);
  }
 else {
    textViewEndDate.setEnabled(true);
  }
}

Fixed version (ground truth):
private void doUpdateEndDate(Spinner spinner,CommodityViewModel orderCommodityViewModel,TextView textViewStartDate,TextView textViewEndDate){
  Integer orderReasonPosition=orderCommodityViewModel.getOrderReasonPosition();
  String item=((OrderReason)spinner.getItemAtPosition(orderReasonPosition)).getReason();
  if (item.equalsIgnoreCase(ROUTINE)) {
    String startDate=textViewStartDate.getText().toString();
    populateEndDate(startDate,30,textViewEndDate);
    textViewEndDate.setEnabled(false);
  }
 else {
    textViewEndDate.setEnabled(true);
  }
}
Program: 146405
Project: 146405
Buggy source:
@Before public void setUp(){
  setUpInjection(this);
  Commodity commodity=mock(Commodity.class);
  when(commodity.getName()).thenReturn("String_Node_Str");
  when(commodity.getOrderDuration()).thenReturn(30);
  when(commodity.getStockItem()).thenReturn(new StockItem(commodity,20));
  commodities=new ArrayList<>();
  commodityViewModel=mock(CommodityViewModel.class);
  when(commodityViewModel.getCommodity()).thenReturn(commodity);
  when(commodityViewModel.getOrderReasonPosition()).thenReturn(0);
  commodities.add(commodityViewModel);
  orderReasons.add(routine);
  orderReasons.add(emergency);
  adapter=new SelectedOrderCommoditiesAdapter(Robolectric.application,list_item_layout,commodities,orderReasons);
}

Fixed version (ground truth):
@Before public void setUp(){
  setUpInjection(this);
  Commodity commodity=mock(Commodity.class);
  when(commodity.getName()).thenReturn("String_Node_Str");
  when(commodity.getOrderDuration()).thenReturn(30);
  when(commodity.getStockItem()).thenReturn(new StockItem(commodity,20));
  commodities=new ArrayList<>();
  commodityViewModel=mock(CommodityViewModel.class);
  when(commodityViewModel.getCommodity()).thenReturn(commodity);
  when(commodityViewModel.getOrderReasonPosition()).thenReturn(0);
  commodities.add(commodityViewModel);
  orderReasons.add(emergency);
  orderReasons.add(routine);
  adapter=new SelectedOrderCommoditiesAdapter(Robolectric.application,list_item_layout,commodities,orderReasons);
}
Program: 146406
Project: 146406
Buggy source:
@Test public void shouldPutOrderReasonsIntoOrderReasonsSpinnerAdapter(){
  Spinner spinner=(Spinner)getViewFromListRow(adapter,list_item_layout,R.id.spinnerOrderReasons);
  String reasonName=((OrderReason)spinner.getAdapter().getItem(0)).getReason();
  assertThat(reasonName,is(routine.getReason()));
}

Fixed version (ground truth):
@Test public void shouldPutOrderReasonsIntoOrderReasonsSpinnerAdapter(){
  Spinner spinner=(Spinner)getViewFromListRow(adapter,list_item_layout,R.id.spinnerOrderReasons);
  String reasonName=((OrderReason)spinner.getAdapter().getItem(0)).getReason();
  assertThat(reasonName,is(emergency.getReason()));
}
Program: 146407
Project: 146407
Buggy source:
protected void onEachSelectedCommodity(SelectedCommodityHandler handler){
  for (int i=0; i < listViewSelectedCommodities.getChildCount(); i++) {
    View view=listViewSelectedCommodities.getChildAt(i);
    CommodityViewModel commodityViewModel=(CommodityViewModel)listViewSelectedCommodities.getAdapter().getItem(i);
    handler.operate(view,commodityViewModel);
  }
}

Fixed version (ground truth):
protected void onEachSelectedCommodity(SelectedCommodityHandler handler){
  for (int i=0; i < listViewSelectedCommodities.getAdapter().getCount(); i++) {
    View view=listViewSelectedCommodities.getAdapter().getView(i,null,listViewSelectedCommodities);
    CommodityViewModel commodityViewModel=(CommodityViewModel)listViewSelectedCommodities.getAdapter().getItem(i);
    handler.operate(view,commodityViewModel);
  }
}
Program: 146408
Project: 146408
Buggy source:
private List<View> wrap(ListView listView){
  List<View> result=newArrayList();
  for (int i=0; i < listView.getChildCount(); i++) {
    result.add(listView.getChildAt(i));
  }
  return result;
}

Fixed version (ground truth):
private List<View> wrap(ListView listView){
  List<View> result=newArrayList();
  for (int i=0; i < listView.getAdapter().getCount(); i++) {
    result.add(listView.getAdapter().getView(i,null,listView));
  }
  return result;
}
Program: 146409
Project: 146409
Buggy source:
@Override public void afterTextChanged(Editable editable){
  String value=editable.toString();
  if (!value.isEmpty()) {
    int quantity=Integer.parseInt(value);
    int stock_level=stockService.getStockLevelFor(commodityViewModel.getCommodity());
    commodityViewModel.setQuantityEntered(quantity);
    if (quantity > stock_level) {
      editTextQuantity.setError(String.format("String_Node_Str",stock_level));
    }
  }
}

Fixed version (ground truth):
@Override public void afterTextChanged(Editable editable){
  String value=editable.toString();
  if (!value.isEmpty()) {
    int quantity=Integer.parseInt(value);
    int stock_level=stockService.getStockLevelFor(commodityViewModel.getCommodity());
    commodityViewModel.setQuantityEntered(quantity);
    if (quantity > stock_level) {
      editTextQuantity.setError(String.format("String_Node_Str",stock_level));
    }
  }
 else {
    commodityViewModel.setQuantityEntered(0);
  }
}
Program: 146410
Project: 146410
Buggy source:
@Test public void testThatIfAllDispensingItemsHaveZeroQuantitiesAToastIsMade() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  dispenseActivity.findViewById(R.id.buttonSubmitDispense).callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(ShadowToast.getTextOfLatestToast(),equalTo(application.getString(R.string.dispense_submit_validation_message_zero)));
}

Fixed version (ground truth):
@Test public void testThatIfAllDispensingItemsHaveZeroQuantitiesAToastIsMade() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter=mock(SelectedCommoditiesAdapter.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
  when(mockListView.getChildCount()).thenReturn(1);
  when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new CommodityViewModel(new Commodity("String_Node_Str")));
  when(mockSelectedCommoditiesAdapter.getCount()).thenReturn(1);
  when(mockSelectedCommoditiesAdapter.getView(anyInt(),org.mockito.Matchers.any(View.class),org.mockito.Matchers.any(ViewGroup.class))).thenReturn(mockListItemView);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  dispenseActivity.findViewById(R.id.buttonSubmitDispense).callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(ShadowToast.getTextOfLatestToast(),equalTo(application.getString(R.string.dispense_submit_validation_message_zero)));
}
Program: 146411
Project: 146411
Buggy source:
@Test public void testThatIfAllDispensingItemsHaveNoQuantitiesAToastIsMade() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  dispenseActivity.findViewById(R.id.buttonSubmitDispense).callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(ShadowToast.getTextOfLatestToast(),equalTo(application.getString(R.string.dispense_submit_validation_message_filled)));
}

Fixed version (ground truth):
@Test public void testThatIfAllDispensingItemsHaveNoQuantitiesAToastIsMade() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter=mock(SelectedCommoditiesAdapter.class);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
  when(mockListView.getChildCount()).thenReturn(1);
  when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new CommodityViewModel(new Commodity("String_Node_Str")));
  when(mockSelectedCommoditiesAdapter.getCount()).thenReturn(1);
  when(mockSelectedCommoditiesAdapter.getView(anyInt(),org.mockito.Matchers.any(View.class),org.mockito.Matchers.any(ViewGroup.class))).thenReturn(mockListItemView);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  dispenseActivity.findViewById(R.id.buttonSubmitDispense).callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(ShadowToast.getTextOfLatestToast(),equalTo(application.getString(R.string.dispense_submit_validation_message_filled)));
}
Program: 146412
Project: 146412
Buggy source:
@Test public void testThatIfAnyOfTheDispensingItemsHaveErrorsAToastIsMade() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  mockEditText.setError("String_Node_Str");
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  dispenseActivity.findViewById(R.id.buttonSubmitDispense).callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(ShadowToast.getTextOfLatestToast(),equalTo(application.getString(R.string.dispense_submit_validation_message_errors)));
}

Fixed version (ground truth):
@Test public void testThatIfAnyOfTheDispensingItemsHaveErrorsAToastIsMade() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  mockEditText.setError("String_Node_Str");
  SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter=mock(SelectedCommoditiesAdapter.class);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
  when(mockListView.getChildCount()).thenReturn(1);
  when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new CommodityViewModel(new Commodity("String_Node_Str")));
  when(mockSelectedCommoditiesAdapter.getCount()).thenReturn(1);
  when(mockSelectedCommoditiesAdapter.getView(anyInt(),org.mockito.Matchers.any(View.class),org.mockito.Matchers.any(ViewGroup.class))).thenReturn(mockListItemView);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  dispenseActivity.findViewById(R.id.buttonSubmitDispense).callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(ShadowToast.getTextOfLatestToast(),equalTo(application.getString(R.string.dispense_submit_validation_message_errors)));
}
Program: 146413
Project: 146413
Buggy source:
@Test public void getDispensingShouldGetItemsInTheListView() throws Exception {
  String commodityName="String_Node_Str";
  DispenseActivity dispenseActivity=getDispenseActivity();
  dispenseActivity.checkboxCommoditySelected.setChecked(true);
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter=mock(SelectedCommoditiesAdapter.class);
  mockEditText.setText("String_Node_Str");
  Commodity commodity=new Commodity(commodityName);
  when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new CommodityViewModel(commodity));
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  when(mockListView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  Dispensing dispensing=dispenseActivity.getDispensing();
  assertThat(dispensing.getDispensingItems().size(),is(1));
  assertThat(dispensing.isDispenseToFacility(),is(true));
  assertThat(dispensing.getDispensingItems().get(0).getQuantity(),is(12));
  assertThat(dispensing.getDispensingItems().get(0).getCommodity().getName(),is(commodityName));
}

Fixed version (ground truth):
@Test public void getDispensingShouldGetItemsInTheListView() throws Exception {
  String commodityName="String_Node_Str";
  DispenseActivity dispenseActivity=getDispenseActivity();
  dispenseActivity.checkboxCommoditySelected.setChecked(true);
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter=mock(SelectedCommoditiesAdapter.class);
  mockEditText.setText("String_Node_Str");
  Commodity commodity=new Commodity(commodityName);
  when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new CommodityViewModel(commodity));
  when(mockSelectedCommoditiesAdapter.getCount()).thenReturn(1);
  when(mockSelectedCommoditiesAdapter.getView(anyInt(),org.mockito.Matchers.any(View.class),org.mockito.Matchers.any(ViewGroup.class))).thenReturn(mockListItemView);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  Dispensing dispensing=dispenseActivity.getDispensing();
  assertThat(dispensing.getDispensingItems().size(),is(1));
  assertThat(dispensing.isDispenseToFacility(),is(true));
  assertThat(dispensing.getDispensingItems().get(0).getQuantity(),is(12));
  assertThat(dispensing.getDispensingItems().get(0).getCommodity().getName(),is(commodityName));
}
Program: 146414
Project: 146414
Buggy source:
@Override public View getView(int position,View convertView,ViewGroup parent){
  LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
  View rowView=inflater.inflate(R.layout.commodity_list_item,parent,false);
  CheckBox checkboxCommoditySelected=(CheckBox)rowView.findViewById(R.id.checkboxCommoditySelected);
  CommodityViewModel commodityViewModel=getItem(position);
  checkboxCommoditySelected.setChecked(commodityViewModel.getSelected());
  TextView textViewCommodityName=(TextView)rowView.findViewById(R.id.textViewCommodityName);
  textViewCommodityName.setText(commodityViewModel.getName());
  if (commodityViewModel.stockIsFinished()) {
    rowView.setBackgroundColor(getContext().getResources().getColor(R.color.disabled));
    checkboxCommoditySelected.setVisibility(View.INVISIBLE);
  }
  return rowView;
}

Fixed version (ground truth):
@Override public View getView(int position,View convertView,ViewGroup parent){
  LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
  View rowView=inflater.inflate(R.layout.commodity_list_item,parent,false);
  CheckBox checkboxCommoditySelected=(CheckBox)rowView.findViewById(R.id.checkboxCommoditySelected);
  CommodityViewModel commodityViewModel=getItem(position);
  checkboxCommoditySelected.setChecked(commodityViewModel.isSelected());
  TextView textViewCommodityName=(TextView)rowView.findViewById(R.id.textViewCommodityName);
  textViewCommodityName.setText(commodityViewModel.getName());
  if (commodityViewModel.stockIsFinished()) {
    rowView.setBackgroundColor(getContext().getResources().getColor(R.color.disabled));
    checkboxCommoditySelected.setVisibility(View.INVISIBLE);
  }
  return rowView;
}
Program: 146415
Project: 146415
Buggy source:
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  setupDialog();
  final View overlayView=inflater.inflate(R.layout.fragment_item_select,container,false);
  categoriesLayout=(LinearLayout)overlayView.findViewById(R.id.itemSelectOverlayCategories);
  setupCloseButton(overlayView);
  listViewCommodities=(ListView)overlayView.findViewById(R.id.listViewCommodities);
  List<Category> categoryList=categoryService.all();
  adapterHashMap=new LinkedHashMap<>();
  for (  final Category category : categoryList) {
    Button button=new CategoryButton(getActivity(),category);
    button.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        showCommodities(category);
      }
    }
);
    for (    Commodity commodity : category.getCommodities()) {
      CommodityViewModel commodityViewModel=new CommodityViewModel(commodity);
      if (selectedCommodities.contains(commodityViewModel)) {
        commodityViewModel.toggleSelected();
      }
    }
    List<CommodityViewModel> commodities=convertToViewModelsList(category.getCommodities());
    adapterHashMap.put(category,new CommoditiesAdapter(getActivity(),R.layout.commodity_list_item,commodities));
    categoriesLayout.addView(button);
  }
  showCommodities(category);
  return overlayView;
}

Fixed version (ground truth):
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  setupDialog();
  final View overlayView=inflater.inflate(R.layout.fragment_item_select,container,false);
  categoriesLayout=(LinearLayout)overlayView.findViewById(R.id.itemSelectOverlayCategories);
  setupCloseButton(overlayView);
  listViewCommodities=(ListView)overlayView.findViewById(R.id.listViewCommodities);
  List<Category> categoryList=categoryService.all();
  adapterHashMap=new LinkedHashMap<>();
  for (  final Category category : categoryList) {
    Button button=new CategoryButton(getActivity(),category);
    button.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        showCommodities(category);
      }
    }
);
    List<CommodityViewModel> commodities=convertToViewModelsList(category.getCommodities());
    for (    CommodityViewModel commodityViewModel : commodities) {
      if (selectedCommodities.contains(commodityViewModel)) {
        commodityViewModel.toggleSelected();
      }
    }
    adapterHashMap.put(category,new CommoditiesAdapter(getActivity(),R.layout.commodity_list_item,commodities));
    categoriesLayout.addView(button);
  }
  showCommodities(category);
  return overlayView;
}
Program: 146416
Project: 146416
Buggy source:
@Test public void testThatSubmitButtonExists() throws Exception {
  DispenseActivity activity=getActivity();
  assertThat(activity.buttonSubmitDispense,is(notNullValue()));
}

Fixed version (ground truth):
@Test public void testThatSubmitButtonExists() throws Exception {
  DispenseActivity activity=getDispenseActivity();
  assertThat(activity.buttonSubmitDispense,is(notNullValue()));
}
Program: 146417
Project: 146417
Buggy source:
@Test public void shouldToggleSubmitButtonVisibility() throws Exception {
  DispenseActivity dispenseActivity=getActivity();
  assertFalse(dispenseActivity.buttonSubmitDispense.getVisibility() == View.VISIBLE);
  CommodityViewModel commodityViewModel=new CommodityViewModel(new Commodity("String_Node_Str"));
  CommodityToggledEvent commodityToggledEvent=new CommodityToggledEvent(commodityViewModel);
  EventBus.getDefault().post(commodityToggledEvent);
  assertTrue(dispenseActivity.buttonSubmitDispense.getVisibility() == View.VISIBLE);
}

Fixed version (ground truth):
@Test public void shouldToggleSubmitButtonVisibility() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  assertFalse(dispenseActivity.buttonSubmitDispense.getVisibility() == View.VISIBLE);
  CommodityViewModel commodityViewModel=new CommodityViewModel(new Commodity("String_Node_Str"));
  CommodityToggledEvent commodityToggledEvent=new CommodityToggledEvent(commodityViewModel);
  EventBus.getDefault().post(commodityToggledEvent);
  assertTrue(dispenseActivity.buttonSubmitDispense.getVisibility() == View.VISIBLE);
}
Program: 146418
Project: 146418
Buggy source:
@Test public void testThatDispenseToFacilityExists() throws Exception {
  DispenseActivity activity=getActivity();
  assertThat(activity.checkboxCommoditySelected,is(notNullValue()));
}

Fixed version (ground truth):
@Test public void testThatDispenseToFacilityExists() throws Exception {
  DispenseActivity activity=getDispenseActivity();
  assertThat(activity.checkboxCommoditySelected,is(notNullValue()));
}
Program: 146419
Project: 146419
Buggy source:
@Test public void testSubmitButtonLogicWhenDispensingIsInValid() throws Exception {
  DispenseActivity dispenseActivity=getActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertFalse(dispenseActivity.dispensingIsValid());
  dispenseActivity.buttonSubmitDispense.callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(getTextOfLatestToast(),equalTo("String_Node_Str"));
}

Fixed version (ground truth):
@Test public void testSubmitButtonLogicWhenDispensingIsInValid() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertFalse(dispenseActivity.dispensingIsValid());
  dispenseActivity.buttonSubmitDispense.callOnClick();
  ShadowHandler.idleMainLooper();
  assertThat(getTextOfLatestToast(),equalTo("String_Node_Str"));
}
Program: 146420
Project: 146420
Buggy source:
private CommodityToggledEventDetails fireCommodityToggledEvent(){
  DispenseActivity dispenseActivity=getActivity();
  CommodityViewModel commodityViewModel=new CommodityViewModel(new Commodity("String_Node_Str"));
  CommodityToggledEvent commodityToggledEvent=new CommodityToggledEvent(commodityViewModel);
  refire(commodityToggledEvent);
  return new CommodityToggledEventDetails(dispenseActivity,commodityToggledEvent);
}

Fixed version (ground truth):
public static CommodityToggledEventDetails fireCommodityToggledEvent(DispenseActivity dispenseActivity){
  CommodityViewModel commodityViewModel=new CommodityViewModel(new Commodity("String_Node_Str"));
  CommodityToggledEvent commodityToggledEvent=new CommodityToggledEvent(commodityViewModel);
  refire(commodityToggledEvent);
  return new CommodityToggledEventDetails(dispenseActivity,commodityToggledEvent);
}
Program: 146421
Project: 146421
Buggy source:
@Test public void testShouldDisplayAllCategoriesAsButtons() throws Exception {
  DispenseActivity dispenseActivity=getActivity();
  LinearLayout categoryLayout=(LinearLayout)dispenseActivity.findViewById(R.id.layoutCategories);
  int buttonAmount=categoryLayout.getChildCount();
  assertThat(buttonAmount,is(7));
  for (int i=1; i < buttonAmount; i++) {
    View childView=categoryLayout.getChildAt(i);
    assertThat(childView,instanceOf(Button.class));
  }
}

Fixed version (ground truth):
@Test public void testShouldDisplayAllCategoriesAsButtons() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  LinearLayout categoryLayout=(LinearLayout)dispenseActivity.findViewById(R.id.layoutCategories);
  int buttonAmount=categoryLayout.getChildCount();
  assertThat(buttonAmount,is(7));
  for (int i=1; i < buttonAmount; i++) {
    View childView=categoryLayout.getChildAt(i);
    assertThat(childView,instanceOf(Button.class));
  }
}
Program: 146422
Project: 146422
Buggy source:
@Test public void testThatDispensingIsInvalidIfAnyFieldHasAnError() throws Exception {
  DispenseActivity dispenseActivity=getActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  mockEditText.setError("String_Node_Str");
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertFalse(dispenseActivity.dispensingIsValid());
}

Fixed version (ground truth):
@Test public void testThatDispensingIsInvalidIfAnyFieldHasAnError() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  mockEditText.setError("String_Node_Str");
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertFalse(dispenseActivity.dispensingIsValid());
}
Program: 146423
Project: 146423
Buggy source:
@Test public void testThatDispensingIsValidIfQuantitiesAreSet() throws Exception {
  DispenseActivity dispenseActivity=getActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertTrue(dispenseActivity.dispensingIsValid());
}

Fixed version (ground truth):
@Test public void testThatDispensingIsValidIfQuantitiesAreSet() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  mockEditText.setText("String_Node_Str");
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertTrue(dispenseActivity.dispensingIsValid());
}
Program: 146424
Project: 146424
Buggy source:
private void refire(CommodityToggledEvent commodityToggledEvent){
  EventBus.getDefault().post(commodityToggledEvent);
}

Fixed version (ground truth):
public static void refire(CommodityToggledEvent commodityToggledEvent){
  EventBus.getDefault().post(commodityToggledEvent);
}
Program: 146425
Project: 146425
Buggy source:
@Test public void listViewShouldToggleCommodityWhenToggleEventIsTriggered() throws Exception {
  CommodityToggledEventDetails eventDetails=fireCommodityToggledEvent();
  CommodityViewModel commodityInList=(CommodityViewModel)eventDetails.dispenseActivity.listViewSelectedCommodities.getAdapter().getItem(0);
  assertThat(commodityInList,is(eventDetails.commodityViewModel()));
  refire(eventDetails.commodityToggledEvent);
  assertThat(eventDetails.dispenseActivity.listViewSelectedCommodities.getAdapter().getCount(),is(0));
}

Fixed version (ground truth):
@Test public void listViewShouldToggleCommodityWhenToggleEventIsTriggered() throws Exception {
  CommodityToggledEventDetails eventDetails=fireCommodityToggledEvent(getDispenseActivity());
  CommodityViewModel commodityInList=(CommodityViewModel)eventDetails.dispenseActivity.listViewSelectedCommodities.getAdapter().getItem(0);
  assertThat(commodityInList,is(eventDetails.commodityViewModel()));
  refire(eventDetails.commodityToggledEvent);
  assertThat(eventDetails.dispenseActivity.listViewSelectedCommodities.getAdapter().getCount(),is(0));
}
Program: 146426
Project: 146426
Buggy source:
@Test public void testThatDispensingIsInvalidIfNoQuantitiesAreSet() throws Exception {
  DispenseActivity dispenseActivity=getActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertFalse(dispenseActivity.dispensingIsValid());
}

Fixed version (ground truth):
@Test public void testThatDispensingIsInvalidIfNoQuantitiesAreSet() throws Exception {
  DispenseActivity dispenseActivity=getDispenseActivity();
  ListView mockListView=mock(ListView.class);
  View mockListItemView=mock(View.class);
  EditText mockEditText=new EditText(application);
  when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
  when(mockListView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockListView.getChildCount()).thenReturn(1);
  dispenseActivity.listViewSelectedCommodities=mockListView;
  assertFalse(dispenseActivity.dispensingIsValid());
}
Program: 146427
Project: 146427
Buggy source:
@Test public void shouldToggleSelectedItemsWhenToggleEventIsTriggered() throws Exception {
  CommodityToggledEventDetails eventDetails=fireCommodityToggledEvent();
  assertThat(eventDetails.dispenseActivity.selectedCommodities,contains(eventDetails.commodityViewModel()));
  refire(eventDetails.commodityToggledEvent);
  assertThat(eventDetails.dispenseActivity.selectedCommodities,not(contains(eventDetails.commodityViewModel())));
}

Fixed version (ground truth):
@Test public void shouldToggleSelectedItemsWhenToggleEventIsTriggered() throws Exception {
  CommodityToggledEventDetails eventDetails=fireCommodityToggledEvent(getDispenseActivity());
  assertThat(eventDetails.dispenseActivity.selectedCommodities,contains(eventDetails.commodityViewModel()));
  refire(eventDetails.commodityToggledEvent);
  assertThat(eventDetails.dispenseActivity.selectedCommodities,not(contains(eventDetails.commodityViewModel())));
}
Program: 146428
Project: 146428
Buggy source:
@Test public void testBuildActivity() throws Exception {
  DispenseActivity activity=getActivity();
  assertThat(activity,not(nullValue()));
  TextView textViewAppName=(TextView)activity.getActionBar().getCustomView().findViewById(R.id.textAppName);
  assertThat(textViewAppName,is(notNullValue()));
  assertThat(textViewAppName.getText().toString(),is(activity.getResources().getString(R.string.app_name)));
}

Fixed version (ground truth):
@Test public void testBuildActivity() throws Exception {
  DispenseActivity activity=getDispenseActivity();
  assertThat(activity,not(nullValue()));
  TextView textViewAppName=(TextView)activity.getActionBar().getCustomView().findViewById(R.id.textAppName);
  assertThat(textViewAppName,is(notNullValue()));
  assertThat(textViewAppName.getText().toString(),is(activity.getResources().getString(R.string.app_name)));
}