nus-yam/ex-repair huggingface dataset:
Program: 146352
Project: 146352
Buggy source:
protected void setupEndMonthSpinner(){
  int selectedIndex=spinnerStartingMonth.getSelectedItemPosition();
  ArrayAdapter<String> endMonthAdapter=new ArrayAdapter<>(getApplicationContext(),R.layout.spinner_item_black,getMonths(selectedIndex,endingYearIsCurrent() ? DateUtil.monthNumber() + 1 : 12));
  spinnerEndingMonth.setAdapter(endMonthAdapter);
}

Fixed version (ground truth):
protected void setupEndMonthSpinner(){
  if (getStartingYear().compareTo(getEndingYear()) < 0) {
    return;
  }
  int selectedIndex=spinnerStartingMonth.getSelectedItemPosition();
  ArrayAdapter<String> endMonthAdapter=new ArrayAdapter<>(getApplicationContext(),R.layout.spinner_item_black,getMonths(selectedIndex,endingYearIsCurrent() ? DateUtil.monthNumber() + 1 : 12));
  spinnerEndingMonth.setAdapter(endMonthAdapter);
}
Program: 146353
Project: 146353
Buggy source:
private void setupUnexpectedReasonsSpinner(final Spinner spinnerUnexpectedReasons,final OrderCommodityViewModel orderCommodityViewModel){
  spinnerUnexpectedReasons.setOnItemSelectedListener(new LmisOnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      orderCommodityViewModel.setUnexpectedReasonPosition(position);
      if (position != 0) {
        orderCommodityViewModel.setReasonForUnexpectedOrderQuantity((OrderReason)spinnerUnexpectedReasons.getAdapter().getItem(position));
      }
    }
  }
);
  setupSpinnerData(spinnerUnexpectedReasons,unexpectedOrderReasons,orderCommodityViewModel.getUnexpectedReasonPosition());
}

Fixed version (ground truth):
private void setupUnexpectedReasonsSpinner(final Spinner spinnerUnexpectedReasons,final OrderCommodityViewModel orderCommodityViewModel){
  spinnerUnexpectedReasons.setOnItemSelectedListener(new LmisOnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      orderCommodityViewModel.setUnexpectedReasonPosition(position);
      if (position != 0) {
        orderCommodityViewModel.setReasonForUnexpectedOrderQuantity((OrderReason)spinnerUnexpectedReasons.getAdapter().getItem(position));
      }
 else {
        orderCommodityViewModel.setReasonForUnexpectedOrderQuantity(null);
      }
    }
  }
);
  setupSpinnerData(spinnerUnexpectedReasons,unexpectedOrderReasons,orderCommodityViewModel.getUnexpectedReasonPosition());
}
Program: 146354
Project: 146354
Buggy source:
@Override public void onClick(View v){
  if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
    return;
  }
  if (!quantitiesAreValid()) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
    return;
  }
  ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
  receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
}

Fixed version (ground truth):
@Override public void onClick(View v){
  if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
    return;
  }
  if (!quantitiesAreValid()) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
    return;
  }
  if (completedAllocationIds.contains(textViewAllocationId.getText().toString())) {
    Toast.makeText(getApplicationContext(),getString(R.string.error_allocation_received),Toast.LENGTH_SHORT).show();
    return;
  }
  ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
  receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
}
Program: 146355
Project: 146355
Buggy source:
private void setupAllocationIdTextView(){
  final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,allocationService.getYetToBeReceivedAllocationIds());
  textViewAllocationId.setAdapter(adapter);
  textViewAllocationId.addTextChangedListener(new LmisTextWatcher(){
    @Override public void afterTextChanged(    Editable s){
      String text=s.toString();
      if (text.trim().length() > 6) {
        setAllocation(text);
      }
    }
  }
);
  textViewAllocationId.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    @Override public void onItemClick(    AdapterView<?> parent,    View view,    int position,    long id){
      String text=adapter.getItem(position);
      setAllocation(text);
    }
  }
);
}

Fixed version (ground truth):
private void setupAllocationIdTextView(){
  final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,allocationService.getYetToBeReceivedAllocationIds());
  textViewAllocationId.setAdapter(adapter);
  textViewAllocationId.addTextChangedListener(new LmisTextWatcher(){
    @Override public void afterTextChanged(    Editable s){
      String text=s.toString();
      if (text.trim().length() >= 6) {
        setAllocation(text);
      }
    }
  }
);
  textViewAllocationId.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    @Override public void onItemClick(    AdapterView<?> parent,    View view,    int position,    long id){
      String text=adapter.getItem(position);
      setAllocation(text);
    }
  }
);
}
Program: 146356
Project: 146356
Buggy source:
public Receive generateReceive(){
  Receive receive=new Receive(spinnerSource.getSelectedItem().toString(),allocation);
  for (int i=0; i < arrayAdapter.getCount(); i++) {
    ReceiveCommodityViewModel viewModel=(ReceiveCommodityViewModel)arrayAdapter.getItem(i);
    ReceiveItem receiveItem=viewModel.getReceiveItem();
    receive.addReceiveItem(receiveItem);
  }
  return receive;
}

Fixed version (ground truth):
public Receive generateReceive(){
  if ((allocation == null && spinnerSource.getSelectedItem().toString().contains(getString(R.string.lga))) || (allocation != null && allocation.isDummy())) {
    generateDummyAllocation(textViewAllocationId.getText().toString().trim());
  }
  Receive receive=new Receive(spinnerSource.getSelectedItem().toString(),allocation);
  for (int i=0; i < arrayAdapter.getCount(); i++) {
    ReceiveCommodityViewModel viewModel=(ReceiveCommodityViewModel)arrayAdapter.getItem(i);
    ReceiveItem receiveItem=viewModel.getReceiveItem();
    receive.addReceiveItem(receiveItem);
  }
  return receive;
}
Program: 146357
Project: 146357
Buggy source:
private void setupReceiveButton(){
  buttonSubmitReceive.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
        return;
      }
      if (!quantitiesAreValid()) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
        return;
      }
      ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
      receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
    }
  }
);
}

Fixed version (ground truth):
private void setupReceiveButton(){
  buttonSubmitReceive.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
        return;
      }
      if (!quantitiesAreValid()) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
        return;
      }
      if (completedAllocationIds.contains(textViewAllocationId.getText().toString())) {
        Toast.makeText(getApplicationContext(),getString(R.string.error_allocation_received),Toast.LENGTH_SHORT).show();
        return;
      }
      ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
      receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
    }
  }
);
}
Program: 146358
Project: 146358
Buggy source:
@Override public void afterTextChanged(Editable s){
  String text=s.toString();
  if (text.trim().length() > 6) {
    setAllocation(text);
  }
}

Fixed version (ground truth):
@Override public void afterTextChanged(Editable s){
  String text=s.toString();
  if (text.trim().length() >= 6) {
    setAllocation(text);
  }
}
Program: 146359
Project: 146359
Buggy source:
@Override protected void afterCreate(Bundle savedInstanceState){
  completedAllocationIds=allocationService.getReceivedAllocationIds();
  setupAllocationIdTextView();
  setupReceiveButton();
  if (presetAllocationId != null) {
    textViewAllocationId.setText(presetAllocationId);
  }
}

Fixed version (ground truth):
@Override protected void afterCreate(Bundle savedInstanceState){
  completedAllocationIds=new ArrayList<>(allocationService.getReceivedAllocationIds());
  setupAllocationIdTextView();
  setupReceiveButton();
  if (presetAllocationId != null) {
    textViewAllocationId.setText(presetAllocationId);
  }
}
Program: 146360
Project: 146360
Buggy source:
@Override protected void onPostExecute(Boolean success){
  super.onPostExecute(success);
  if (success) {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_successful),Toast.LENGTH_LONG).show();
    fragment.dismiss();
    FragmentActivity activity=getActivity();
    if (activity != null) {
      activity.finish();
      startActivity(activity.getIntent());
    }
  }
 else {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_failed),Toast.LENGTH_LONG).show();
  }
  this.dialog.dismiss();
}

Fixed version (ground truth):
@Override protected void onPostExecute(Boolean success){
  super.onPostExecute(success);
  if (success) {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_successful),Toast.LENGTH_LONG).show();
    fragment.dismiss();
    FragmentActivity activity=getActivity();
    if (activity instanceof ReceiveActivity) {
      ReceiveActivity receiveActivity=(ReceiveActivity)activity;
      receiveActivity.clearInput();
    }
  }
 else {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_failed),Toast.LENGTH_LONG).show();
  }
  this.dialog.dismiss();
}
Program: 146361
Project: 146361
Buggy source:
public void saveReceive(Receive receive){
  try {
    GenericDao<Receive> receiveDao=new GenericDao<>(Receive.class,context);
    receiveDao.create(receive);
    saveReceiveItems(receive.getReceiveItems());
    if (receive.getAllocation() != null) {
      Allocation allocation=receive.getAllocation();
      allocation.setReceived(true);
      if (!receive.getAllocation().isDummy()) {
        allocationService.update(allocation);
        alertsService.deleteAllocationAlert(allocation);
      }
 else {
        allocationService.createAllocation(receive.getAllocation());
      }
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str",e.getMessage());
    e.printStackTrace();
  }
}

Fixed version (ground truth):
public void saveReceive(Receive receive){
  try {
    GenericDao<Receive> receiveDao=new GenericDao<>(Receive.class,context);
    receiveDao.create(receive);
    saveReceiveItems(receive.getReceiveItems());
    if (receive.getAllocation() != null) {
      Allocation allocation=receive.getAllocation();
      allocation.setReceived(true);
      if (!receive.getAllocation().isDummy()) {
        allocationService.update(allocation);
        alertsService.deleteAllocationAlert(allocation);
      }
 else {
        allocationService.createAllocation(receive.getAllocation());
        EventBus.getDefault().post(new AllocationCreateEvent(receive.getAllocation()));
      }
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str",e.getMessage());
    e.printStackTrace();
  }
}
Program: 146362
Project: 146362
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  getSupportActionBar().setDisplayUseLogoEnabled(true);
  getSupportActionBar().setHomeAsUpIndicator(R.drawable.transparent);
  commodities=commodityService.all();
  setUpAdapters();
  populateCommoditiesSpinner();
  setUpCommoditySearch();
  buttonLoadReport.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      textViewReloadBinCard.setVisibility(View.GONE);
      linearLayoutBinCardItems.setVisibility(View.VISIBLE);
      hideKeyboard();
      populateBinCard((Commodity)spinnerCommodities.getItemAtPosition(currentPosition));
    }
  }
);
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  getSupportActionBar().setDisplayUseLogoEnabled(true);
  getSupportActionBar().setHomeAsUpIndicator(R.drawable.transparent);
  commodities=commodityService.sortedAll();
  setUpAdapters();
  populateCommoditiesSpinner();
  setUpCommoditySearch();
  buttonLoadReport.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      textViewReloadBinCard.setVisibility(View.GONE);
      linearLayoutBinCardItems.setVisibility(View.VISIBLE);
      hideKeyboard();
      populateBinCard((Commodity)spinnerCommodities.getItemAtPosition(currentPosition));
    }
  }
);
}
Program: 146363
Project: 146363
Buggy source:
private List<Commodity> getCommoditiesThatCanBeSelected(){
  return from(commodityService.all()).filter(new Predicate<Commodity>(){
    @Override public boolean apply(    Commodity input){
      return !commodityHasBeenSelected(input) && getCheckBoxVisibilityStrategy().allowClick(new BaseCommodityViewModel(input));
    }
  }
).toList();
}

Fixed version (ground truth):
private List<Commodity> getCommoditiesThatCanBeSelected(){
  return from(commodityService.sortedAll()).filter(new Predicate<Commodity>(){
    @Override public boolean apply(    Commodity input){
      return !commodityHasBeenSelected(input) && getCheckBoxVisibilityStrategy().allowClick(new BaseCommodityViewModel(input));
    }
  }
).toList();
}
Program: 146364
Project: 146364
Buggy source:
@Override public View getView(int position,View convertView,ViewGroup parent){
  LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view=inflater.inflate(resource,parent,false);
  Map<Integer,String> integerStringMap=new HashMap<>();
  FacilityConsumptionReportRH2Item item=getItem(position);
  integerStringMap.put(R.id.textViewCommodityName,item.getCommodityName());
  integerStringMap.put(R.id.textViewOpeningBalance,String.valueOf(item.getOpeningStock()));
  integerStringMap.put(R.id.textViewQuantityReceived,String.valueOf(item.getCommoditiesReceived()));
  integerStringMap.put(R.id.textViewQuantityDispensedToClients,String.valueOf(item.getCommoditiesDispensedToClients()));
  integerStringMap.put(R.id.textViewQuantityDispensedToFacilities,String.valueOf(item.getCommoditiesDispensedToFacilities()));
  integerStringMap.put(R.id.textViewTotalDispensed,String.valueOf(item.totalDispensed()));
  integerStringMap.put(R.id.textViewQuantityLost,String.valueOf(item.getCommoditiesLost()));
  integerStringMap.put(R.id.textViewClosingStock,String.valueOf(item.getClosingStock()));
  for (  Integer key : integerStringMap.keySet()) {
    TextView textView=(TextView)view.findViewById(key);
    textView.setText(integerStringMap.get(key));
  }
  if (isGrey) {
    view.setBackgroundColor(getContext().getResources().getColor(R.color.m_grey));
  }
  isGrey=!isGrey;
  return view;
}

Fixed version (ground truth):
@Override public View getView(int position,View convertView,ViewGroup parent){
  LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view=inflater.inflate(resource,parent,false);
  Map<Integer,String> integerStringMap=new HashMap<>();
  FacilityConsumptionReportRH2Item item=getItem(position);
  integerStringMap.put(R.id.textViewCommodityName,item.getCommodityName());
  integerStringMap.put(R.id.textViewOpeningBalance,String.valueOf(item.getOpeningStock()));
  integerStringMap.put(R.id.textViewQuantityReceived,String.valueOf(item.getCommoditiesReceived()));
  integerStringMap.put(R.id.textViewQuantityAdjusted,String.valueOf(item.getCommoditiesAdjusted()));
  integerStringMap.put(R.id.textViewQuantityDispensedToFacilities,String.valueOf(item.getCommoditiesDispensedToFacilities()));
  integerStringMap.put(R.id.textViewTotalDispensed,String.valueOf(item.totalDispensed()));
  integerStringMap.put(R.id.textViewQuantityLost,String.valueOf(item.getCommoditiesLost()));
  integerStringMap.put(R.id.textViewClosingStock,String.valueOf(item.getClosingStock()));
  for (  Integer key : integerStringMap.keySet()) {
    TextView textView=(TextView)view.findViewById(key);
    textView.setText(integerStringMap.get(key));
  }
  if (isGrey) {
    view.setBackgroundColor(getContext().getResources().getColor(R.color.m_grey));
  }
  isGrey=!isGrey;
  return view;
}
Program: 146365
Project: 146365
Buggy source:
public FacilityConsumptionReportRH2Item(String commodityName,int openingStock,int commoditiesReceived,int commoditiesDispensedToClients,int commoditiesDispensedToFacilities,int commoditiesLost,int closingStock){
  this.commodityName=commodityName;
  this.openingStock=openingStock;
  this.commoditiesReceived=commoditiesReceived;
  this.commoditiesDispensedToClients=commoditiesDispensedToClients;
  this.commoditiesDispensedToFacilities=commoditiesDispensedToFacilities;
  this.commoditiesLost=commoditiesLost;
  this.closingStock=closingStock;
}

Fixed version (ground truth):
public FacilityConsumptionReportRH2Item(String commodityName,int openingStock,int commoditiesReceived,int commoditiesDispensedToClients,int commoditiesAdjusted,int commoditiesDispensedToFacilities,int commoditiesLost,int closingStock){
  this.commodityName=commodityName;
  this.openingStock=openingStock;
  this.commoditiesReceived=commoditiesReceived;
  this.commoditiesDispensedToClients=commoditiesDispensedToClients;
  this.commoditiesAdjusted=commoditiesAdjusted;
  this.commoditiesDispensedToFacilities=commoditiesDispensedToFacilities;
  this.commoditiesLost=commoditiesLost;
  this.closingStock=closingStock;
}
Program: 146367
Project: 146367
Buggy source:
Dispensing getDispensing(){
  final Dispensing dispensing=new Dispensing();
  dispensing.setPrescriptionId(textViewPrescriptionId.getText().toString());
  onEachSelectedCommodity(new SelectedCommodityHandler(){
    @Override public void operate(    View view,    BaseCommodityViewModel commodityViewModel){
      EditText editTextQuantity=(EditText)view.findViewById(R.id.editTextQuantity);
      int quantity=getIntFromString(editTextQuantity.getText().toString());
      dispensing.addItem(new DispensingItem(commodityViewModel.getCommodity(),quantity));
    }
  }
);
  return dispensing;
}

Fixed version (ground truth):
Dispensing getDispensing(){
  final Dispensing dispensing=new Dispensing();
  dispensing.setPrescriptionId(textViewPrescriptionId.getText().toString());
  for (int i=0; i < arrayAdapter.getCount(); i++) {
    BaseCommodityViewModel commodityViewMode=(BaseCommodityViewModel)arrayAdapter.getItem(i);
    dispensing.addItem(new DispensingItem(commodityViewMode.getCommodity(),commodityViewMode.getQuantityEntered()));
  }
  return dispensing;
}
Program: 146368
Project: 146368
Buggy source:
@Test public void getDispensingShouldGetItemsInTheListView() throws Exception {
  String commodityName="String_Node_Str";
  DispenseActivity dispenseActivity=getDispenseActivity();
  GridView mockGridView=mock(GridView.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 BaseCommodityViewModel(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(mockGridView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockGridView.getChildCount()).thenReturn(1);
  when(mockGridView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
  dispenseActivity.gridViewSelectedCommodities=mockGridView;
  Dispensing dispensing=dispenseActivity.getDispensing();
  assertThat(dispensing.getDispensingItems().size(),is(1));
  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();
  BaseCommodityViewModel commodityViewModel=new BaseCommodityViewModel(new Commodity(commodityName));
  commodityViewModel.setQuantityEntered(12);
  CommodityToggledEvent commodityToggledEvent=new CommodityToggledEvent(commodityViewModel);
  EventBus.getDefault().post(commodityToggledEvent);
  Dispensing dispensing=dispenseActivity.getDispensing();
  assertThat(dispensing.getDispensingItems().size(),is(1));
  assertThat(dispensing.getDispensingItems().get(0).getQuantity(),is(12));
  assertThat(dispensing.getDispensingItems().get(0).getCommodity().getName(),is(commodityName));
}
Program: 146369
Project: 146369
Buggy source:
Dispensing getDispensing(){
  final Dispensing dispensing=new Dispensing();
  dispensing.setPrescriptionId(textViewPrescriptionId.getText().toString());
  onEachSelectedCommodity(new SelectedCommodityHandler(){
    @Override public void operate(    View view,    BaseCommodityViewModel commodityViewModel){
      EditText editTextQuantity=(EditText)view.findViewById(R.id.editTextQuantity);
      int quantity=getIntFromString(editTextQuantity.getText().toString());
      dispensing.addItem(new DispensingItem(commodityViewModel.getCommodity(),quantity));
    }
  }
);
  return dispensing;
}

Fixed version (ground truth):
Dispensing getDispensing(){
  final Dispensing dispensing=new Dispensing();
  dispensing.setPrescriptionId(textViewPrescriptionId.getText().toString());
  for (int i=0; i < arrayAdapter.getCount(); i++) {
    BaseCommodityViewModel commodityViewMode=(BaseCommodityViewModel)arrayAdapter.getItem(i);
    dispensing.addItem(new DispensingItem(commodityViewMode.getCommodity(),commodityViewMode.getQuantityEntered()));
  }
  return dispensing;
}
Program: 146370
Project: 146370
Buggy source:
@Test public void getDispensingShouldGetItemsInTheListView() throws Exception {
  String commodityName="String_Node_Str";
  DispenseActivity dispenseActivity=getDispenseActivity();
  GridView mockGridView=mock(GridView.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 BaseCommodityViewModel(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(mockGridView.getChildAt(anyInt())).thenReturn(mockListItemView);
  when(mockGridView.getChildCount()).thenReturn(1);
  when(mockGridView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
  dispenseActivity.gridViewSelectedCommodities=mockGridView;
  Dispensing dispensing=dispenseActivity.getDispensing();
  assertThat(dispensing.getDispensingItems().size(),is(1));
  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();
  BaseCommodityViewModel commodityViewModel=new BaseCommodityViewModel(new Commodity(commodityName));
  commodityViewModel.setQuantityEntered(12);
  CommodityToggledEvent commodityToggledEvent=new CommodityToggledEvent(commodityViewModel);
  EventBus.getDefault().post(commodityToggledEvent);
  Dispensing dispensing=dispenseActivity.getDispensing();
  assertThat(dispensing.getDispensingItems().size(),is(1));
  assertThat(dispensing.getDispensingItems().get(0).getQuantity(),is(12));
  assertThat(dispensing.getDispensingItems().get(0).getCommodity().getName(),is(commodityName));
}
Program: 146371
Project: 146371
Buggy source:
public void onCommodityToggledEventCompleted(){
  searchCommodityAdapter=new SearchCommodityAdapter(this,R.layout.search_commodity_item,newArrayList(getCommoditiesThatCanBeSelected()));
  autoCompleteTextViewCommodities.setAdapter(searchCommodityAdapter);
}

Fixed version (ground truth):
public void onCommodityToggledEventCompleted(){
  searchCommodityAdapter.notifyDataSetChanged();
}
Program: 146372
Project: 146372
Buggy source:
@Override public void onClick(View v){
  if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
    return;
  }
  if (!quantitiesAreValid()) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
    return;
  }
  ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
  receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
}

Fixed version (ground truth):
@Override public void onClick(View v){
  if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
    return;
  }
  if (!quantitiesAreValid()) {
    Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
    return;
  }
  if (completedAllocationIds.contains(textViewAllocationId.getText().toString())) {
    Toast.makeText(getApplicationContext(),getString(R.string.error_allocation_received),Toast.LENGTH_SHORT).show();
    return;
  }
  ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
  receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
}
Program: 146373
Project: 146373
Buggy source:
private void setupAllocationIdTextView(){
  final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,allocationService.getYetToBeReceivedAllocationIds());
  textViewAllocationId.setAdapter(adapter);
  textViewAllocationId.addTextChangedListener(new LmisTextWatcher(){
    @Override public void afterTextChanged(    Editable s){
      String text=s.toString();
      if (text.trim().length() > 6) {
        setAllocation(text);
      }
    }
  }
);
  textViewAllocationId.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    @Override public void onItemClick(    AdapterView<?> parent,    View view,    int position,    long id){
      String text=adapter.getItem(position);
      setAllocation(text);
    }
  }
);
}

Fixed version (ground truth):
private void setupAllocationIdTextView(){
  final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,allocationService.getYetToBeReceivedAllocationIds());
  textViewAllocationId.setAdapter(adapter);
  textViewAllocationId.addTextChangedListener(new LmisTextWatcher(){
    @Override public void afterTextChanged(    Editable s){
      String text=s.toString();
      if (text.trim().length() >= 6) {
        setAllocation(text);
      }
    }
  }
);
  textViewAllocationId.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    @Override public void onItemClick(    AdapterView<?> parent,    View view,    int position,    long id){
      String text=adapter.getItem(position);
      setAllocation(text);
    }
  }
);
}
Program: 146374
Project: 146374
Buggy source:
public Receive generateReceive(){
  Receive receive=new Receive(spinnerSource.getSelectedItem().toString(),allocation);
  for (int i=0; i < arrayAdapter.getCount(); i++) {
    ReceiveCommodityViewModel viewModel=(ReceiveCommodityViewModel)arrayAdapter.getItem(i);
    ReceiveItem receiveItem=viewModel.getReceiveItem();
    receive.addReceiveItem(receiveItem);
  }
  return receive;
}

Fixed version (ground truth):
public Receive generateReceive(){
  if ((allocation == null && spinnerSource.getSelectedItem().toString().contains(getString(R.string.lga))) || (allocation != null && allocation.isDummy())) {
    generateDummyAllocation(textViewAllocationId.getText().toString().trim());
  }
  Receive receive=new Receive(spinnerSource.getSelectedItem().toString(),allocation);
  for (int i=0; i < arrayAdapter.getCount(); i++) {
    ReceiveCommodityViewModel viewModel=(ReceiveCommodityViewModel)arrayAdapter.getItem(i);
    ReceiveItem receiveItem=viewModel.getReceiveItem();
    receive.addReceiveItem(receiveItem);
  }
  return receive;
}
Program: 146375
Project: 146375
Buggy source:
private void setupReceiveButton(){
  buttonSubmitReceive.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
        return;
      }
      if (!quantitiesAreValid()) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
        return;
      }
      ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
      receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
    }
  }
);
}

Fixed version (ground truth):
private void setupReceiveButton(){
  buttonSubmitReceive.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (!allocationIdIsValid(textViewAllocationId.getText().toString())) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_submit_validation_message_allocation_id),Toast.LENGTH_SHORT).show();
        return;
      }
      if (!quantitiesAreValid()) {
        Toast.makeText(getApplicationContext(),getString(R.string.receive_quantities_validation_error_message),Toast.LENGTH_SHORT).show();
        return;
      }
      if (completedAllocationIds.contains(textViewAllocationId.getText().toString())) {
        Toast.makeText(getApplicationContext(),getString(R.string.error_allocation_received),Toast.LENGTH_SHORT).show();
        return;
      }
      ReceiveConfirmFragment receiveConfirmFragment=ReceiveConfirmFragment.newInstance(generateReceive());
      receiveConfirmFragment.show(getSupportFragmentManager(),"String_Node_Str");
    }
  }
);
}
Program: 146376
Project: 146376
Buggy source:
@Override public void afterTextChanged(Editable s){
  String text=s.toString();
  if (text.trim().length() > 6) {
    setAllocation(text);
  }
}

Fixed version (ground truth):
@Override public void afterTextChanged(Editable s){
  String text=s.toString();
  if (text.trim().length() >= 6) {
    setAllocation(text);
  }
}
Program: 146377
Project: 146377
Buggy source:
@Override protected void afterCreate(Bundle savedInstanceState){
  completedAllocationIds=allocationService.getReceivedAllocationIds();
  setupAllocationIdTextView();
  setupReceiveButton();
  if (presetAllocationId != null) {
    textViewAllocationId.setText(presetAllocationId);
  }
}

Fixed version (ground truth):
@Override protected void afterCreate(Bundle savedInstanceState){
  completedAllocationIds=new ArrayList<>(allocationService.getReceivedAllocationIds());
  setupAllocationIdTextView();
  setupReceiveButton();
  if (presetAllocationId != null) {
    textViewAllocationId.setText(presetAllocationId);
  }
}
Program: 146378
Project: 146378
Buggy source:
@Override protected void onPostExecute(Boolean success){
  super.onPostExecute(success);
  if (success) {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_successful),Toast.LENGTH_LONG).show();
    fragment.dismiss();
    FragmentActivity activity=getActivity();
    if (activity != null) {
      activity.finish();
      startActivity(activity.getIntent());
    }
  }
 else {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_failed),Toast.LENGTH_LONG).show();
  }
  this.dialog.dismiss();
}

Fixed version (ground truth):
@Override protected void onPostExecute(Boolean success){
  super.onPostExecute(success);
  if (success) {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_successful),Toast.LENGTH_LONG).show();
    fragment.dismiss();
    FragmentActivity activity=getActivity();
    if (activity instanceof ReceiveActivity) {
      ReceiveActivity receiveActivity=(ReceiveActivity)activity;
      receiveActivity.clearInput();
    }
  }
 else {
    Toast.makeText(fragment.getActivity().getApplicationContext(),getString(R.string.receive_failed),Toast.LENGTH_LONG).show();
  }
  this.dialog.dismiss();
}
Program: 146379
Project: 146379
Buggy source:
public void saveReceive(Receive receive){
  try {
    GenericDao<Receive> receiveDao=new GenericDao<>(Receive.class,context);
    receiveDao.create(receive);
    saveReceiveItems(receive.getReceiveItems());
    if (receive.getAllocation() != null) {
      Allocation allocation=receive.getAllocation();
      allocation.setReceived(true);
      if (!receive.getAllocation().isDummy()) {
        allocationService.update(allocation);
        alertsService.deleteAllocationAlert(allocation);
      }
 else {
        allocationService.createAllocation(receive.getAllocation());
      }
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str",e.getMessage());
    e.printStackTrace();
  }
}

Fixed version (ground truth):
public void saveReceive(Receive receive){
  try {
    GenericDao<Receive> receiveDao=new GenericDao<>(Receive.class,context);
    receiveDao.create(receive);
    saveReceiveItems(receive.getReceiveItems());
    if (receive.getAllocation() != null) {
      Allocation allocation=receive.getAllocation();
      allocation.setReceived(true);
      if (!receive.getAllocation().isDummy()) {
        allocationService.update(allocation);
        alertsService.deleteAllocationAlert(allocation);
      }
 else {
        allocationService.createAllocation(receive.getAllocation());
        EventBus.getDefault().post(new AllocationCreateEvent(receive.getAllocation()));
      }
    }
  }
 catch (  Exception e) {
    Log.e("String_Node_Str",e.getMessage());
    e.printStackTrace();
  }
}
Program: 146380
Project: 146380
Buggy source:
@Override public Adjustment apply(BaseCommodityViewModel input){
  AdjustmentsViewModel model=(AdjustmentsViewModel)input;
  return new Adjustment(model.getCommodity(),model.getQuantityEntered(),model.getQuantityAllocated(),model.isPositive(),model.getAdjustmentReason().getName());
}

Fixed version (ground truth):
@Override public Adjustment apply(BaseCommodityViewModel input){
  AdjustmentsViewModel model=(AdjustmentsViewModel)input;
  int quantity=abs(model.getAdjustmentReason().equals(AdjustmentReason.PHYSICAL_COUNT) ? model.getPhysicalStockCountDifference() : model.getQuantityEntered());
  return new Adjustment(model.getCommodity(),quantity,model.getQuantityAllocated(),model.isPositive(),model.getAdjustmentReason().getName());
}
Program: 146381
Project: 146381
Buggy source:
private List<Adjustment> getAdjustments(){
  return FluentIterable.from(selectedCommodities).transform(new Function<BaseCommodityViewModel,Adjustment>(){
    @Override public Adjustment apply(    BaseCommodityViewModel input){
      AdjustmentsViewModel model=(AdjustmentsViewModel)input;
      return new Adjustment(model.getCommodity(),model.getQuantityEntered(),model.getQuantityAllocated(),model.isPositive(),model.getAdjustmentReason().getName());
    }
  }
).toList();
}

Fixed version (ground truth):
private List<Adjustment> getAdjustments(){
  return FluentIterable.from(selectedCommodities).transform(new Function<BaseCommodityViewModel,Adjustment>(){
    @Override public Adjustment apply(    BaseCommodityViewModel input){
      AdjustmentsViewModel model=(AdjustmentsViewModel)input;
      int quantity=abs(model.getAdjustmentReason().equals(AdjustmentReason.PHYSICAL_COUNT) ? model.getPhysicalStockCountDifference() : model.getQuantityEntered());
      return new Adjustment(model.getCommodity(),quantity,model.getQuantityAllocated(),model.isPositive(),model.getAdjustmentReason().getName());
    }
  }
).toList();
}
Program: 146382
Project: 146382
Buggy source:
@Test public void shouldReturnTwoReportsForCategoryFamilyPlaning() throws Exception {
  List<ReportType> reportTypesForCategory=ReportType.getReportTypesForCategory("String_Node_Str");
  assertThat(reportTypesForCategory.size(),is(4));
  assertThat(reportTypesForCategory,containsInAnyOrder(ReportType.FacilityRequsitionIssueReportForm,ReportType.FacilityConsumptionReportRH2,ReportType.FacilityStockReport,ReportType.FacilityConsumptionReportRH1));
}

Fixed version (ground truth):
@Test public void shouldReturnTwoReportsForCategoryFamilyPlaning() throws Exception {
  List<ReportType> reportTypesForCategory=ReportType.getReportTypesForCategory("String_Node_Str");
  assertThat(reportTypesForCategory.size(),is(4));
  assertThat(reportTypesForCategory,containsInAnyOrder(ReportType.FacilityRequisitionIssueReportForm,ReportType.FacilityConsumptionReportRH2,ReportType.FacilityStockReport,ReportType.FacilityConsumptionReportRH1));
}
Program: 146384
Project: 146384
Buggy source:
@Override protected Boolean doInBackground(Void... params){
  User user;
  try {
    user=userService.register(username,password);
    commodityService.initialise(user);
    orderService.syncOrderReasons();
    orderService.syncOrderTypes();
    smsSyncService.syncGatewayNumber();
  }
 catch (  Exception e) {
    this.failureCause=e;
    Log.e("String_Node_Str",e.getLocalizedMessage());
    e.printStackTrace();
    return false;
  }
  return true;
}

Fixed version (ground truth):
@Override protected Boolean doInBackground(Void... params){
  User user;
  try {
    user=userService.register(username,password);
    Log.i("String_Node_Str","String_Node_Str");
    commodityService.initialise(user);
    Log.i("String_Node_Str","String_Node_Str");
    orderService.syncOrderReasons();
    Log.i("String_Node_Str","String_Node_Str");
    orderService.syncOrderTypes();
    smsSyncService.syncGatewayNumber();
    Log.i("String_Node_Str","String_Node_Str");
    commodityActionService.syncCommodityActionValues(user,commodityService.all());
  }
 catch (  Exception e) {
    this.failureCause=e;
    Log.e("String_Node_Str",e.getLocalizedMessage());
    e.printStackTrace();
    return false;
  }
  return true;
}
Program: 146385
Project: 146385
Buggy source:
public float getMonthsOfStock(){
  return (float)getStockOnHand() / commodity.getAMC();
}

Fixed version (ground truth):
public float getMonthsOfStock(){
  int AMC=commodity.getAMC();
  return AMC == 0 ? 1 : (float)commodity.getStockOnHand() / AMC;
}
Program: 146386
Project: 146386
Buggy source:
@Override public List<CommodityActionValue> fetchCommodityActionValues(List<Commodity> commodities,User user){
  Dhis2Endpoint service=dhis2EndPointFactory.create(user);
  DataValueSet valueSet=new DataValueSet();
  try {
    String dataSet2=getDataSetId(commodities,DataElementType.AMC.getActivity());
    String dataSetId=getDataSetId(commodities,DataElementType.STOCK_ON_HAND.getActivity());
    valueSet=service.fetchDataValuesEx(dataSetId,user.getFacilityCode(),twoMonthsAgo(),today(),dataSet2);
  }
 catch (  LmisException exception) {
    e(SYNC,"String_Node_Str");
  }
  return convertDataValuesToCommodityActions(valueSet.getDataValues());
}

Fixed version (ground truth):
@Override public List<CommodityActionValue> fetchCommodityActionValues(List<Commodity> commodities,User user){
  Dhis2Endpoint service=dhis2EndPointFactory.create(user);
  DataValueSet valueSet=new DataValueSet();
  try {
    String dataSet2=getDataSetId(commodities,DataElementType.AMC.getActivity());
    String dataSetId=getDataSetId(commodities,DataElementType.STOCK_ON_HAND.getActivity());
    valueSet=service.fetchDataValuesEx(dataSetId,user.getFacilityCode(),threeMonthsAgo(),today(),dataSet2);
  }
 catch (  LmisException exception) {
    e(SYNC,"String_Node_Str");
  }
  return convertDataValuesToCommodityActions(valueSet.getDataValues());
}
Program: 146387
Project: 146387
Buggy source:
@Override public List<CommodityActionValue> fetchAllocations(final List<Commodity> commodities,User user){
  Dhis2Endpoint service=dhis2EndPointFactory.create(user);
  DataValueSet valueSet=new DataValueSet();
  try {
    String dataSetId=getDataSetId(commodities,DataElementType.ALLOCATED.getActivity());
    valueSet=service.fetchDataValues(dataSetId,user.getFacilityCode(),twoMonthsAgo(),today());
  }
 catch (  LmisException exception) {
    e(SYNC,"String_Node_Str");
  }
  List<CommodityActionValue> commodityActionValues=convertDataValuesToCommodityActions(valueSet.getDataValues());
  return from(commodityActionValues).filter(new Predicate<CommodityActionValue>(){
    @Override public boolean apply(    CommodityActionValue input){
      return input.getCommodityAction().getActivityType().equals(DataElementType.ALLOCATED.getActivity());
    }
  }
).toList();
}

Fixed version (ground truth):
@Override public List<CommodityActionValue> fetchAllocations(final List<Commodity> commodities,User user){
  Dhis2Endpoint service=dhis2EndPointFactory.create(user);
  DataValueSet valueSet=new DataValueSet();
  try {
    String dataSetId=getDataSetId(commodities,DataElementType.ALLOCATED.getActivity());
    valueSet=service.fetchDataValues(dataSetId,user.getFacilityCode(),threeMonthsAgo(),today());
  }
 catch (  LmisException exception) {
    e(SYNC,"String_Node_Str");
  }
  List<CommodityActionValue> commodityActionValues=convertDataValuesToCommodityActions(valueSet.getDataValues());
  return from(commodityActionValues).filter(new Predicate<CommodityActionValue>(){
    @Override public boolean apply(    CommodityActionValue input){
      return input.getCommodityAction().getActivityType().equals(DataElementType.ALLOCATED.getActivity());
    }
  }
).toList();
}
Program: 146388
Project: 146388
Buggy source:
void populateWithAllocation(Allocation allocation){
  if (allocation != null) {
    selectedCommodities.clear();
    arrayAdapter.clear();
    for (    AllocationItem item : allocation.getAllocationItems()) {
      CommodityToggledEvent event=new CommodityToggledEvent(new ReceiveCommodityViewModel(item));
      onEvent(event);
    }
  }
}

Fixed version (ground truth):
private void populateWithAllocation(Allocation allocation){
  if (allocation != null) {
    selectedCommodities.clear();
    arrayAdapter.clear();
    for (    AllocationItem item : allocation.getAllocationItems()) {
      CommodityToggledEvent event=new CommodityToggledEvent(new ReceiveCommodityViewModel(item));
      onEvent(event);
    }
  }
}
Program: 146389
Project: 146389
Buggy source:
public void syncAllocations(){
  GenericDao<Allocation> allocationGenericDao=new GenericDao<>(Allocation.class,context);
  GenericDao<AllocationItem> allocationItemGenericDao=new GenericDao<>(AllocationItem.class,context);
  GenericDao<Commodity> commodityDao=new GenericDao<>(Commodity.class,context);
  Allocation allocation=new Allocation();
  allocation.setReceived(false);
  allocation.setAllocationId("String_Node_Str");
  allocationGenericDao.create(allocation);
  AllocationItem item=new AllocationItem();
  item.setCommodity(commodityDao.queryForAll().get(0));
  item.setQuantity(10);
  item.setAllocation(allocation);
  allocationItemGenericDao.create(item);
}

Fixed version (ground truth):
public void syncAllocations(){
  createAllocation("String_Node_Str",9);
  createAllocation("String_Node_Str",10);
}
Program: 146390
Project: 146390
Buggy source:
protected void beforeArrayAdapterCreate(Bundle savedInstanceState){
}

Fixed version (ground truth):
abstract protected void beforeArrayAdapterCreate(Bundle savedInstanceState);
Program: 146391
Project: 146391
Buggy source:
@Override public void onClick(View v){
  dismiss();
}

Fixed version (ground truth):
@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());
  }
}