nus-yam/ex-repair huggingface dataset:
Program: 146261
Project: 146261
Buggy source:
public Receive generateReceive(){
  if ((allocation == null && spinnerSource.getSelectedItem().toString().contains(getString(R.string.lga_for_receive))) || (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;
}

Fixed version (ground truth):
public Receive generateReceive(){
  if ((allocation == null && spinnerSource.getSelectedItem().toString().contains(getString(R.string.lga_for_receive))) || (allocation != null && allocation.isDummy())) {
    generateDummyAllocation(textViewAllocationId.getText().toString().trim());
  }
  Receive receive=new Receive(getString(FIXED_SOURCES.get(spinnerSource.getSelectedItemPosition())),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: 146262
Project: 146262
Buggy source:
@Test public void shouldGenerateAReceiveFromSelectedReceiveCommodities() throws Exception {
  ReceiveActivity receiveActivity=getReceiveActivity();
  ReceiveCommodityViewModel viewModel=new ReceiveCommodityViewModel(new Commodity(PANADOL),3,6);
  EventBus.getDefault().post(new CommodityToggledEvent(viewModel));
  Receive receive=receiveActivity.generateReceive();
  assertThat(receive.getReceiveItems().size(),is(1));
  assertThat(receive.getReceiveItems().get(0).getCommodity().getName(),is(PANADOL));
  assertThat(receive.getSource(),is(application.getString(R.string.others_for_receive)));
}

Fixed version (ground truth):
@Test public void shouldGenerateAReceiveFromSelectedReceiveCommodities() throws Exception {
  ReceiveActivity receiveActivity=getReceiveActivity();
  ReceiveCommodityViewModel viewModel=new ReceiveCommodityViewModel(new Commodity(PANADOL),3,6);
  EventBus.getDefault().post(new CommodityToggledEvent(viewModel));
  Receive receive=receiveActivity.generateReceive();
  assertThat(receive.getReceiveItems().size(),is(1));
  assertThat(receive.getReceiveItems().get(0).getCommodity().getName(),is(PANADOL));
  assertThat(receive.getSource(),is(application.getString(R.string.others)));
}
Program: 146263
Project: 146263
Buggy source:
@Test public void shouldGenerateReceiveWithSource() throws Exception {
  ReceiveActivity receiveActivity=getReceiveActivity();
  ReceiveCommodityViewModel viewModel=new ReceiveCommodityViewModel(new Commodity(PANADOL),3,6);
  EventBus.getDefault().post(new CommodityToggledEvent(viewModel));
  String applicationString=application.getString(R.string.zonal_store_for_receive);
  setSource(receiveActivity,applicationString);
  Receive receive=receiveActivity.generateReceive();
  assertThat(receive.getSource(),is(applicationString));
}

Fixed version (ground truth):
@Test public void shouldGenerateReceiveWithSource() throws Exception {
  ReceiveActivity receiveActivity=getReceiveActivity();
  ReceiveCommodityViewModel viewModel=new ReceiveCommodityViewModel(new Commodity(PANADOL),3,6);
  EventBus.getDefault().post(new CommodityToggledEvent(viewModel));
  String applicationString=application.getString(R.string.zonal_store_for_receive);
  setSource(receiveActivity,applicationString);
  Receive receive=receiveActivity.generateReceive();
  assertThat(receive.getSource(),is(application.getString(R.string.zonal_store)));
}
Program: 146264
Project: 146264
Buggy source:
private List<UtilizationValue> getOpeningBalances(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int openingStock=stockItemSnapshotService.getLatestStock(commodity,startDate,true);
  int previousDaysOpeningStock=openingStock;
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    Date previousDay=DateUtil.addDayOfMonth(calendar.getTime(),-1);
    StockItemSnapshot openingStockSnapshot=stockItemSnapshotService.getSnapshot(previousDay,stockItemSnapshots);
    int openingBalance=openingStockSnapshot == null ? previousDaysOpeningStock : openingStockSnapshot.getQuantity();
    utilizationValues.add(new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),openingBalance));
    previousDaysOpeningStock=openingBalance;
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return utilizationValues;
}

Fixed version (ground truth):
private List<UtilizationValue> getOpeningBalances(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int openingStock=stockItemSnapshotService.getOpenningBalance(commodity,startDate);
  int previousDaysOpeningStock=openingStock;
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    Date previousDay=DateUtil.addDayOfMonth(calendar.getTime(),-1);
    StockItemSnapshot openingStockSnapshot=stockItemSnapshotService.getSnapshot(previousDay,stockItemSnapshots);
    int openingBalance=openingStockSnapshot == null ? previousDaysOpeningStock : openingStockSnapshot.getQuantity();
    utilizationValues.add(new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),openingBalance));
    previousDaysOpeningStock=openingBalance;
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return utilizationValues;
}
Program: 146265
Project: 146265
Buggy source:
private List<UtilizationValue> getEndingBalance(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int previousDaysClosingStock=stockItemSnapshotService.getLatestStock(commodity,startDate,false);
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    StockItemSnapshot closingStockSnapshot=stockItemSnapshotService.getSnapshot(calendar.getTime(),stockItemSnapshots);
    int closingBalance=closingStockSnapshot == null ? previousDaysClosingStock : closingStockSnapshot.getQuantity();
    UtilizationValue utilizationValue=new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),closingBalance);
    utilizationValues.add(utilizationValue);
    calendar.add(Calendar.DAY_OF_MONTH,1);
    previousDaysClosingStock=closingBalance;
  }
  return utilizationValues;
}

Fixed version (ground truth):
private List<UtilizationValue> getEndingBalance(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int previousDaysClosingStock=stockItemSnapshotService.getClosingBalance(commodity,startDate);
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    StockItemSnapshot closingStockSnapshot=stockItemSnapshotService.getSnapshot(calendar.getTime(),stockItemSnapshots);
    int closingBalance=closingStockSnapshot == null ? previousDaysClosingStock : closingStockSnapshot.getQuantity();
    UtilizationValue utilizationValue=new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),closingBalance);
    utilizationValues.add(utilizationValue);
    calendar.add(Calendar.DAY_OF_MONTH,1);
    previousDaysClosingStock=closingBalance;
  }
  return utilizationValues;
}
Program: 146269
Project: 146269
Buggy source:
public int getStockOutDays(Commodity commodity,Date startingDate,Date endDate) throws Exception {
  int openingStock=getLatestStock(commodity,startingDate,true);
  int numOfStockOutDays=0;
  List<StockItemSnapshot> snapshots=get(commodity,startingDate,endDate);
  Date closingDate=DateUtil.addDayOfMonth(endDate);
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(startingDate);
  while (calendar.getTime().before(closingDate)) {
    StockItemSnapshot stockItemSnapshot=getSnapshot(calendar.getTime(),snapshots);
    if (stockItemSnapshot != null && stockItemSnapshot.isStockOut() || stockItemSnapshot == null && openingStock == 0) {
      numOfStockOutDays++;
    }
    if (stockItemSnapshot != null) {
      openingStock=stockItemSnapshot.getQuantity();
    }
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return numOfStockOutDays;
}

Fixed version (ground truth):
public int getStockOutDays(Commodity commodity,Date startingDate,Date endDate) throws Exception {
  int openingStock=getOpenningBalance(commodity,startingDate);
  int numOfStockOutDays=0;
  List<StockItemSnapshot> snapshots=get(commodity,startingDate,endDate);
  Date closingDate=DateUtil.addDayOfMonth(endDate);
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(startingDate);
  while (calendar.getTime().before(closingDate)) {
    StockItemSnapshot stockItemSnapshot=getSnapshot(calendar.getTime(),snapshots);
    if (stockItemSnapshot != null && stockItemSnapshot.isStockOut() || stockItemSnapshot == null && openingStock == 0) {
      numOfStockOutDays++;
    }
    if (stockItemSnapshot != null) {
      openingStock=stockItemSnapshot.getQuantity();
    }
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return numOfStockOutDays;
}
Program: 146270
Project: 146270
Buggy source:
public int getLatestStock(Commodity commodity,Date date,boolean isOpeningStock,List<StockItemSnapshot> stockItemSnapshots) throws Exception {
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(date);
  if (isOpeningStock) {
    calendar.add(Calendar.DAY_OF_MONTH,-1);
  }
  Date requiredDate=calendar.getTime();
  StockItemSnapshot latestStockItemSnapshot=getLatest(commodity,requiredDate);
  if (latestStockItemSnapshot != null) {
    return latestStockItemSnapshot.getQuantity();
  }
  return 0;
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public int getLatestStock(Commodity commodity,Date date,boolean isOpeningStock,List<StockItemSnapshot> stockItemSnapshots) throws Exception {
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(date);
  if (isOpeningStock) {
    calendar.add(Calendar.DAY_OF_MONTH,-1);
  }
  Date requiredDate=calendar.getTime();
  StockItemSnapshot latestStockItemSnapshot=getLatest(commodity,requiredDate);
  if (latestStockItemSnapshot != null) {
    return latestStockItemSnapshot.getQuantity();
  }
  return 0;
}
Program: 146272
Project: 146272
Buggy source:
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;
}

Fixed version (ground truth):
public Receive generateReceive(){
  if ((allocation == null && spinnerSource.getSelectedItem().toString().contains(getString(R.string.lga_for_receive))) || (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: 146273
Project: 146273
Buggy source:
@Override public boolean allowClick(BaseCommodityViewModel commodityViewModel){
  if (spinnerSource.getSelectedItem().equals(getString(R.string.zonal_store))) {
    return commodityViewModel.getCommodity().isNonLGA();
  }
 else {
    if ("String_Node_Str".equals(commodityViewModel.getCommodity().getCategory().getName())) {
      return false;
    }
 else {
      return !commodityViewModel.getCommodity().isNonLGA();
    }
  }
}

Fixed version (ground truth):
@Override public boolean allowClick(BaseCommodityViewModel commodityViewModel){
  String selectedSource=(String)spinnerSource.getSelectedItem();
  if (selectedSource.equals(getString(R.string.zonal_store_for_receive))) {
    return commodityViewModel.getCommodity().isNonLGA();
  }
 else {
    if (selectedSource.equals(getString(R.string.lga_for_receive))) {
      if (allocation == null) {
        return false;
      }
    }
    if ("String_Node_Str".equals(commodityViewModel.getCommodity().getCategory().getName())) {
      return false;
    }
 else {
      return !commodityViewModel.getCommodity().isNonLGA();
    }
  }
}
Program: 146274
Project: 146274
Buggy source:
@Override public String getEmptyMessage(){
  String currentSource=spinnerSource.getSelectedItem().toString();
  if (!currentSource.equals(getString(R.string.zonal_store))) {
    return "String_Node_Str";
  }
 else {
    return String.format("String_Node_Str",currentSource);
  }
}

Fixed version (ground truth):
@Override public String getEmptyMessage(){
  String currentSource=spinnerSource.getSelectedItem().toString();
  if (currentSource.equals(getString(R.string.zonal_store_for_receive))) {
    return String.format("String_Node_Str",currentSource);
  }
 else   if (currentSource.equals(getString(R.string.others_for_receive))) {
    return "String_Node_Str";
  }
 else {
    return "String_Node_Str";
  }
}
Program: 146275
Project: 146275
Buggy source:
@Override public void onItemSelected(AdapterView<?> adapterView,View view,int position,long l){
  String selected=getReceiveSources().get(position);
  if (selected.contains(getString(R.string.lga))) {
    setAllocation(textViewAllocationId.getText().toString());
    textViewAllocationId.setEnabled(true);
    textViewAllocationId.setVisibility(View.VISIBLE);
    textViewAllocationLabel.setVisibility(View.VISIBLE);
  }
 else {
    allocation=null;
    textViewAllocationId.setError(null);
    textViewAllocationId.setVisibility(View.INVISIBLE);
    textViewAllocationLabel.setVisibility(View.INVISIBLE);
    textViewAllocationId.setEnabled(false);
  }
  List<CommodityToggledEvent> events=new ArrayList<CommodityToggledEvent>();
  if (selected.contains(getString(R.string.zonal_store))) {
    for (    BaseCommodityViewModel model : selectedCommodities) {
      if (!model.getCommodity().isNonLGA()) {
        events.add(new CommodityToggledEvent(model));
      }
    }
  }
 else {
    for (    BaseCommodityViewModel model : selectedCommodities) {
      if (model.getCommodity().isNonLGA()) {
        events.add(new CommodityToggledEvent(model));
      }
    }
  }
  for (  CommodityToggledEvent event : events) {
    onEvent(event);
  }
  ((ReceiveCommoditiesAdapter)arrayAdapter).setQuantityAllocatedDisplay(!selected.contains(getString(R.string.others)) && !selected.contains(getString(R.string.zonal_store)));
  arrayAdapter.notifyDataSetChanged();
}

Fixed version (ground truth):
@Override public void onItemSelected(AdapterView<?> adapterView,View view,int position,long l){
  String selected=getReceiveSources().get(position);
  if (selected.contains(getString(R.string.lga_for_receive))) {
    setAllocation(textViewAllocationId.getText().toString());
    textViewAllocationId.setEnabled(true);
    textViewAllocationId.setVisibility(View.VISIBLE);
    textViewAllocationLabel.setVisibility(View.VISIBLE);
  }
 else {
    allocation=null;
    textViewAllocationId.setError(null);
    textViewAllocationId.setVisibility(View.INVISIBLE);
    textViewAllocationLabel.setVisibility(View.INVISIBLE);
    textViewAllocationId.setEnabled(false);
  }
  List<CommodityToggledEvent> events=new ArrayList<CommodityToggledEvent>();
  if (selected.contains(getString(R.string.zonal_store_for_receive))) {
    for (    BaseCommodityViewModel model : selectedCommodities) {
      if (!model.getCommodity().isNonLGA()) {
        events.add(new CommodityToggledEvent(model));
      }
    }
  }
 else {
    for (    BaseCommodityViewModel model : selectedCommodities) {
      if (model.getCommodity().isNonLGA()) {
        events.add(new CommodityToggledEvent(model));
      }
    }
  }
  for (  CommodityToggledEvent event : events) {
    onEvent(event);
  }
  ((ReceiveCommoditiesAdapter)arrayAdapter).setQuantityAllocatedDisplay(!selected.contains(getString(R.string.others_for_receive)) && !selected.contains(getString(R.string.zonal_store_for_receive)));
  arrayAdapter.notifyDataSetChanged();
}
Program: 146276
Project: 146276
Buggy source:
public List<String> getReceiveSources(){
  return Arrays.asList(getString(R.string.lga),getString(R.string.zonal_store),getString(R.string.others));
}

Fixed version (ground truth):
public List<String> getReceiveSources(){
  return Arrays.asList(getString(R.string.others_for_receive),getString(R.string.zonal_store_for_receive),getString(R.string.lga_for_receive));
}
Program: 146277
Project: 146277
Buggy source:
@Override protected CommodityDisplayStrategy getCheckBoxVisibilityStrategy(){
  return new CommodityDisplayStrategy(){
    @Override public boolean allowClick(    BaseCommodityViewModel commodityViewModel){
      if (spinnerSource.getSelectedItem().equals(getString(R.string.zonal_store))) {
        return commodityViewModel.getCommodity().isNonLGA();
      }
 else {
        if ("String_Node_Str".equals(commodityViewModel.getCommodity().getCategory().getName())) {
          return false;
        }
 else {
          return !commodityViewModel.getCommodity().isNonLGA();
        }
      }
    }
    @Override public String getMessage(){
      return String.format("String_Node_Str",spinnerSource.getSelectedItem().toString());
    }
    @Override public String getEmptyMessage(){
      String currentSource=spinnerSource.getSelectedItem().toString();
      if (!currentSource.equals(getString(R.string.zonal_store))) {
        return "String_Node_Str";
      }
 else {
        return String.format("String_Node_Str",currentSource);
      }
    }
    @Override public boolean hideCommodities(){
      return true;
    }
  }
;
}

Fixed version (ground truth):
@Override protected CommodityDisplayStrategy getCheckBoxVisibilityStrategy(){
  return new CommodityDisplayStrategy(){
    @Override public boolean allowClick(    BaseCommodityViewModel commodityViewModel){
      String selectedSource=(String)spinnerSource.getSelectedItem();
      if (selectedSource.equals(getString(R.string.zonal_store_for_receive))) {
        return commodityViewModel.getCommodity().isNonLGA();
      }
 else {
        if (selectedSource.equals(getString(R.string.lga_for_receive))) {
          if (allocation == null) {
            return false;
          }
        }
        if ("String_Node_Str".equals(commodityViewModel.getCommodity().getCategory().getName())) {
          return false;
        }
 else {
          return !commodityViewModel.getCommodity().isNonLGA();
        }
      }
    }
    @Override public String getMessage(){
      return String.format("String_Node_Str",spinnerSource.getSelectedItem().toString());
    }
    @Override public String getEmptyMessage(){
      String currentSource=spinnerSource.getSelectedItem().toString();
      if (currentSource.equals(getString(R.string.zonal_store_for_receive))) {
        return String.format("String_Node_Str",currentSource);
      }
 else       if (currentSource.equals(getString(R.string.others_for_receive))) {
        return "String_Node_Str";
      }
 else {
        return "String_Node_Str";
      }
    }
    @Override public boolean hideCommodities(){
      return true;
    }
  }
;
}
Program: 146278
Project: 146278
Buggy source:
public void syncSOHWithServer(User user){
  List<CommoditySnapshot> sohSnapshotsToSync=new ArrayList<>();
  for (  Commodity commodity : commodityService.sortedAll()) {
    try {
      List<CommoditySnapshotValue> commoditySnapshotValues=stohService.getLatest(commodity,new Date()).getActivitiesValues();
      for (      CommoditySnapshotValue value : commoditySnapshotValues) {
        sohSnapshotsToSync.add(new CommoditySnapshot(value));
      }
    }
 catch (    Exception e) {
      e.printStackTrace();
      continue;
    }
  }
  if (!isEmpty(sohSnapshotsToSync)) {
    i("String_Node_Str",sohSnapshotsToSync.size() + "String_Node_Str");
    DataValueSet valueSet=toDataValueSet(sohSnapshotsToSync,user.getFacilityCode());
    try {
      DataValueSetPushResponse response=lmisServer.pushDataValueSet(valueSet,user);
    }
 catch (    LmisException ex) {
      e("String_Node_Str",sohSnapshotsToSync.size() + "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
public void syncSOHWithServer(User user){
  List<CommoditySnapshot> sohSnapshotsToSync=new ArrayList<>();
  final Date dateOfYesterday=getDateOfYesterday();
  final Date dateOfToday=new Date();
  for (  Commodity commodity : commodityService.sortedAll()) {
    try {
      int quantityOfYesterday=0, quantityOfToday=0;
      StockItemSnapshot sohOfYesterday=stohService.get(commodity,dateOfYesterday);
      StockItemSnapshot sohOfToday=stohService.get(commodity,dateOfToday);
      if (sohOfYesterday != null) {
        quantityOfYesterday=sohOfYesterday.getQuantity();
      }
      if (sohOfToday != null) {
        sohOfToday.setQuantity(sohOfToday.getQuantity() + quantityOfYesterday);
        quantityOfToday=sohOfToday.getQuantity();
      }
      sohOfToday=stohService.createOrUpdate(commodity,quantityOfToday,dateOfToday);
      if (sohOfToday != null && sohOfToday.getActivitiesValues() != null) {
        for (        CommoditySnapshotValue value : sohOfToday.getActivitiesValues()) {
          sohSnapshotsToSync.add(new CommoditySnapshot(value));
        }
      }
    }
 catch (    Exception e) {
      e.printStackTrace();
      continue;
    }
  }
  if (!isEmpty(sohSnapshotsToSync)) {
    i("String_Node_Str",sohSnapshotsToSync.size() + "String_Node_Str");
    DataValueSet valueSet=toDataValueSet(sohSnapshotsToSync,user.getFacilityCode());
    try {
      DataValueSetPushResponse response=lmisServer.pushDataValueSet(valueSet,user);
    }
 catch (    LmisException ex) {
      e("String_Node_Str",sohSnapshotsToSync.size() + "String_Node_Str");
    }
  }
}
Program: 146279
Project: 146279
Buggy source:
private List<UtilizationValue> getOpeningBalances(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int openingStock=stockItemSnapshotService.getOpenningBalance(commodity,startDate);
  int previousDaysOpeningStock=openingStock;
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    Date previousDay=DateUtil.addDayOfMonth(calendar.getTime(),-1);
    StockItemSnapshot openingStockSnapshot=stockItemSnapshotService.getSnapshot(previousDay,stockItemSnapshots);
    int openingBalance=openingStockSnapshot == null ? previousDaysOpeningStock : openingStockSnapshot.getQuantity();
    utilizationValues.add(new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),openingBalance));
    previousDaysOpeningStock=openingBalance;
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return utilizationValues;
}

Fixed version (ground truth):
private List<UtilizationValue> getOpeningBalances(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int openingStock=stockItemSnapshotService.getLatestStock(commodity,startDate,true);
  int previousDaysOpeningStock=openingStock;
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    Date previousDay=DateUtil.addDayOfMonth(calendar.getTime(),-1);
    StockItemSnapshot openingStockSnapshot=stockItemSnapshotService.getSnapshot(previousDay,stockItemSnapshots);
    int openingBalance=openingStockSnapshot == null ? previousDaysOpeningStock : openingStockSnapshot.getQuantity();
    utilizationValues.add(new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),openingBalance));
    previousDaysOpeningStock=openingBalance;
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return utilizationValues;
}
Program: 146280
Project: 146280
Buggy source:
private List<UtilizationValue> getEndingBalance(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int previousDaysClosingStock=stockItemSnapshotService.getClosingBalance(commodity,startDate);
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    StockItemSnapshot closingStockSnapshot=stockItemSnapshotService.getSnapshot(calendar.getTime(),stockItemSnapshots);
    int closingBalance=closingStockSnapshot == null ? previousDaysClosingStock : closingStockSnapshot.getQuantity();
    UtilizationValue utilizationValue=new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),closingBalance);
    utilizationValues.add(utilizationValue);
    calendar.add(Calendar.DAY_OF_MONTH,1);
    previousDaysClosingStock=closingBalance;
  }
  return utilizationValues;
}

Fixed version (ground truth):
private List<UtilizationValue> getEndingBalance(Commodity commodity,Date startDate,Date endDate) throws Exception {
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,DateUtil.addDayOfMonth(startDate,-1),endDate);
  List<UtilizationValue> utilizationValues=new ArrayList<>();
  int previousDaysClosingStock=stockItemSnapshotService.getLatestStock(commodity,startDate,false);
  Calendar calendar=DateUtil.calendarDate(startDate);
  Date upperLimitDate=DateUtil.addDayOfMonth(endDate,1);
  while (calendar.getTime().before(upperLimitDate)) {
    StockItemSnapshot closingStockSnapshot=stockItemSnapshotService.getSnapshot(calendar.getTime(),stockItemSnapshots);
    int closingBalance=closingStockSnapshot == null ? previousDaysClosingStock : closingStockSnapshot.getQuantity();
    UtilizationValue utilizationValue=new UtilizationValue(DateUtil.dayNumber(calendar.getTime()),closingBalance);
    utilizationValues.add(utilizationValue);
    calendar.add(Calendar.DAY_OF_MONTH,1);
    previousDaysClosingStock=closingBalance;
  }
  return utilizationValues;
}
Program: 146284
Project: 146284
Buggy source:
public int getStockOutDays(Commodity commodity,Date startingDate,Date endDate) throws Exception {
  int openingStock=getOpenningBalance(commodity,startingDate);
  int numOfStockOutDays=0;
  List<StockItemSnapshot> snapshots=get(commodity,startingDate,endDate);
  Date closingDate=DateUtil.addDayOfMonth(endDate);
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(startingDate);
  while (calendar.getTime().before(closingDate)) {
    StockItemSnapshot stockItemSnapshot=getSnapshot(calendar.getTime(),snapshots);
    if (stockItemSnapshot != null && stockItemSnapshot.isStockOut() || stockItemSnapshot == null && openingStock == 0) {
      numOfStockOutDays++;
    }
    if (stockItemSnapshot != null) {
      openingStock=stockItemSnapshot.getQuantity();
    }
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return numOfStockOutDays;
}

Fixed version (ground truth):
public int getStockOutDays(Commodity commodity,Date startingDate,Date endDate) throws Exception {
  int openingStock=getLatestStock(commodity,startingDate,true);
  int numOfStockOutDays=0;
  List<StockItemSnapshot> snapshots=get(commodity,startingDate,endDate);
  Date closingDate=DateUtil.addDayOfMonth(endDate);
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(startingDate);
  while (calendar.getTime().before(closingDate)) {
    StockItemSnapshot stockItemSnapshot=getSnapshot(calendar.getTime(),snapshots);
    if (stockItemSnapshot != null && stockItemSnapshot.isStockOut() || stockItemSnapshot == null && openingStock == 0) {
      numOfStockOutDays++;
    }
    if (stockItemSnapshot != null) {
      openingStock=stockItemSnapshot.getQuantity();
    }
    calendar.add(Calendar.DAY_OF_MONTH,1);
  }
  return numOfStockOutDays;
}
Program: 146285
Project: 146285
Buggy source:
@SuppressWarnings("String_Node_Str") public int getLatestStock(Commodity commodity,Date date,boolean isOpeningStock,List<StockItemSnapshot> stockItemSnapshots) throws Exception {
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(date);
  if (isOpeningStock) {
    calendar.add(Calendar.DAY_OF_MONTH,-1);
  }
  Date requiredDate=calendar.getTime();
  StockItemSnapshot latestStockItemSnapshot=getLatest(commodity,requiredDate);
  if (latestStockItemSnapshot != null) {
    return latestStockItemSnapshot.getQuantity();
  }
  return 0;
}

Fixed version (ground truth):
public int getLatestStock(Commodity commodity,Date date,boolean isOpeningStock,List<StockItemSnapshot> stockItemSnapshots) throws Exception {
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(date);
  if (isOpeningStock) {
    calendar.add(Calendar.DAY_OF_MONTH,-1);
  }
  Date requiredDate=calendar.getTime();
  StockItemSnapshot latestStockItemSnapshot=getLatest(commodity,requiredDate);
  if (latestStockItemSnapshot != null) {
    return latestStockItemSnapshot.getQuantity();
  }
  return 0;
}
Program: 146286
Project: 146286
Buggy source:
@Override public boolean allowClick(BaseCommodityViewModel commodityViewModel){
  if (spinnerSource.getSelectedItem().equals(getString(R.string.zonal_store))) {
    return commodityViewModel.getCommodity().isNonLGA();
  }
 else {
    return !commodityViewModel.getCommodity().isNonLGA();
  }
}

Fixed version (ground truth):
@Override public boolean allowClick(BaseCommodityViewModel commodityViewModel){
  if (spinnerSource.getSelectedItem().equals(getString(R.string.zonal_store))) {
    return commodityViewModel.getCommodity().isNonLGA();
  }
 else {
    if ("String_Node_Str".equals(commodityViewModel.getCommodity().getCategory().getName())) {
      return false;
    }
 else {
      return !commodityViewModel.getCommodity().isNonLGA();
    }
  }
}
Program: 146287
Project: 146287
Buggy source:
@Override public String getEmptyMessage(){
  return String.format("String_Node_Str",spinnerSource.getSelectedItem().toString());
}

Fixed version (ground truth):
@Override public String getEmptyMessage(){
  String currentSource=spinnerSource.getSelectedItem().toString();
  if (!currentSource.equals(getString(R.string.zonal_store))) {
    return "String_Node_Str";
  }
 else {
    return String.format("String_Node_Str",currentSource);
  }
}
Program: 146288
Project: 146288
Buggy source:
@Override protected CommodityDisplayStrategy getCheckBoxVisibilityStrategy(){
  return new CommodityDisplayStrategy(){
    @Override public boolean allowClick(    BaseCommodityViewModel commodityViewModel){
      if (spinnerSource.getSelectedItem().equals(getString(R.string.zonal_store))) {
        return commodityViewModel.getCommodity().isNonLGA();
      }
 else {
        return !commodityViewModel.getCommodity().isNonLGA();
      }
    }
    @Override public String getMessage(){
      return String.format("String_Node_Str",spinnerSource.getSelectedItem().toString());
    }
    @Override public String getEmptyMessage(){
      return String.format("String_Node_Str",spinnerSource.getSelectedItem().toString());
    }
    @Override public boolean hideCommodities(){
      return true;
    }
  }
;
}

Fixed version (ground truth):
@Override protected CommodityDisplayStrategy getCheckBoxVisibilityStrategy(){
  return new CommodityDisplayStrategy(){
    @Override public boolean allowClick(    BaseCommodityViewModel commodityViewModel){
      if (spinnerSource.getSelectedItem().equals(getString(R.string.zonal_store))) {
        return commodityViewModel.getCommodity().isNonLGA();
      }
 else {
        if ("String_Node_Str".equals(commodityViewModel.getCommodity().getCategory().getName())) {
          return false;
        }
 else {
          return !commodityViewModel.getCommodity().isNonLGA();
        }
      }
    }
    @Override public String getMessage(){
      return String.format("String_Node_Str",spinnerSource.getSelectedItem().toString());
    }
    @Override public String getEmptyMessage(){
      String currentSource=spinnerSource.getSelectedItem().toString();
      if (!currentSource.equals(getString(R.string.zonal_store))) {
        return "String_Node_Str";
      }
 else {
        return String.format("String_Node_Str",currentSource);
      }
    }
    @Override public boolean hideCommodities(){
      return true;
    }
  }
;
}
Program: 146289
Project: 146289
Buggy source:
public void save(final List<Adjustment> adjustments){
  dbutil.withDao(Adjustment.class,new DbUtil.Operation<Adjustment,String>(){
    @Override public String operate(    Dao dao) throws SQLException {
      for (      Adjustment adjustment : adjustments) {
        dao.create(adjustment);
        commoditySnapshotService.add(adjustment);
        if (adjustment.isPositive()) {
          stockService.increaseStockLevelFor(adjustment.getCommodity(),adjustment.getQuantity(),adjustment.getCreated());
        }
 else {
          stockService.reduceStockLevelFor(adjustment.getCommodity(),adjustment.getQuantity(),adjustment.getCreated());
        }
      }
      return null;
    }
  }
);
  categoryService.clearCache();
  alertsService.disableAllMonthlyStockCountAlerts();
  alertsService.updateLowStockAlerts();
}

Fixed version (ground truth):
public void save(final List<Adjustment> adjustments){
  dbutil.withDao(Adjustment.class,new DbUtil.Operation<Adjustment,String>(){
    @Override public String operate(    Dao dao) throws SQLException {
      for (      Adjustment adjustment : adjustments) {
        dao.create(adjustment);
        StockItemSnapshot sis;
        if (adjustment.isPositive()) {
          sis=stockService.increaseStockLevelFor(adjustment.getCommodity(),adjustment.getQuantity(),adjustment.getCreated());
        }
 else {
          sis=stockService.reduceStockLevelFor(adjustment.getCommodity(),adjustment.getQuantity(),adjustment.getCreated());
        }
        commoditySnapshotService.add(sis,true);
        commoditySnapshotService.add(adjustment);
      }
      return null;
    }
  }
);
  categoryService.clearCache();
  alertsService.disableAllMonthlyStockCountAlerts();
  alertsService.updateLowStockAlerts();
}
Program: 146290
Project: 146290
Buggy source:
public void add(final Snapshotable snapshotable){
  List<CommoditySnapshotValue> commoditySnapshotValues=null;
  try {
    commoditySnapshotValues=snapshotable.getActivitiesValues();
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  GenericDao<CommoditySnapshot> snapshotDao=new GenericDao<>(CommoditySnapshot.class,context);
  for (  CommoditySnapshotValue value : commoditySnapshotValues) {
    List<CommoditySnapshot> commoditySnapshots=getSnapshotsForCommodityPeriod(value);
    if (commoditySnapshots.isEmpty()) {
      createNewSnapshot(value,snapshotDao);
    }
 else {
      updateSnapshot(value,snapshotDao,commoditySnapshots);
    }
  }
}

Fixed version (ground truth):
public void add(final Snapshotable snapshotable,boolean isReplace){
  List<CommoditySnapshotValue> commoditySnapshotValues=null;
  try {
    commoditySnapshotValues=snapshotable.getActivitiesValues();
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  GenericDao<CommoditySnapshot> snapshotDao=new GenericDao<>(CommoditySnapshot.class,context);
  for (  CommoditySnapshotValue value : commoditySnapshotValues) {
    List<CommoditySnapshot> commoditySnapshots=getSnapshotsForCommodityPeriod(value);
    if (commoditySnapshots.isEmpty()) {
      createNewSnapshot(value,snapshotDao);
    }
 else {
      updateSnapshot(value,snapshotDao,commoditySnapshots,isReplace);
    }
  }
}
Program: 146291
Project: 146291
Buggy source:
private void updateSnapshot(CommoditySnapshotValue commoditySnapshotValue,GenericDao<CommoditySnapshot> snapshotDao,List<CommoditySnapshot> commoditySnapshots){
  CommoditySnapshot commoditySnapshot=commoditySnapshots.get(0);
  commoditySnapshot.incrementValue(commoditySnapshotValue.getValue());
  commoditySnapshot.setSynced(false);
  snapshotDao.update(commoditySnapshot);
}

Fixed version (ground truth):
private void updateSnapshot(CommoditySnapshotValue commoditySnapshotValue,GenericDao<CommoditySnapshot> snapshotDao,List<CommoditySnapshot> commoditySnapshots,boolean isReplace){
  CommoditySnapshot commoditySnapshot=commoditySnapshots.get(0);
  if (isReplace) {
    commoditySnapshot.setValue(commoditySnapshotValue.getValue());
  }
 else {
    commoditySnapshot.incrementValue(commoditySnapshotValue.getValue());
  }
  commoditySnapshot.setSynced(false);
  snapshotDao.update(commoditySnapshot);
}
Program: 146292
Project: 146292
Buggy source:
private void saveDispensingItems(final List<DispensingItem> dispensingItems){
  GenericDao<DispensingItem> dao=new GenericDao<>(DispensingItem.class,context);
  dao.bulkOperation(new DbUtil.Operation<DispensingItem,Object>(){
    @Override public Object operate(    Dao<DispensingItem,String> dao) throws SQLException {
      for (      DispensingItem dispensingItem : dispensingItems) {
        dao.create(dispensingItem);
      }
      return null;
    }
  }
);
  for (  DispensingItem dispensingItem : dispensingItems) {
    adjustStockLevel(dispensingItem);
    commoditySnapshotService.add(dispensingItem);
  }
  commodityService.addMostDispensedCommoditiesCache(dispensingItems.get(0).getCommodity());
}

Fixed version (ground truth):
private void saveDispensingItems(final List<DispensingItem> dispensingItems){
  GenericDao<DispensingItem> dao=new GenericDao<>(DispensingItem.class,context);
  dao.bulkOperation(new DbUtil.Operation<DispensingItem,Object>(){
    @Override public Object operate(    Dao<DispensingItem,String> dao) throws SQLException {
      for (      DispensingItem dispensingItem : dispensingItems) {
        dao.create(dispensingItem);
      }
      return null;
    }
  }
);
  for (  DispensingItem dispensingItem : dispensingItems) {
    commoditySnapshotService.add(adjustStockLevel(dispensingItem),true);
    commoditySnapshotService.add(dispensingItem);
  }
  commodityService.addMostDispensedCommoditiesCache(dispensingItems.get(0).getCommodity());
}
Program: 146293
Project: 146293
Buggy source:
private void adjustStockLevel(DispensingItem dispensing){
  stockService.reduceStockLevelFor(dispensing.getCommodity(),dispensing.getQuantity(),dispensing.created());
}

Fixed version (ground truth):
private StockItemSnapshot adjustStockLevel(DispensingItem dispensing){
  return stockService.reduceStockLevelFor(dispensing.getCommodity(),dispensing.getQuantity(),dispensing.created());
}
Program: 146294
Project: 146294
Buggy source:
private void saveLossItems(List<LossItem> lossItems){
  GenericDao<LossItem> lossItemDao=new GenericDao<>(LossItem.class,context);
  for (  LossItem lossItem : lossItems) {
    lossItemDao.create(lossItem);
    saveLossItemDetails(lossItem.getLossItemDetails());
    adjustStockLevel(lossItem);
    snapshotService.add(lossItem);
  }
}

Fixed version (ground truth):
private void saveLossItems(List<LossItem> lossItems){
  GenericDao<LossItem> lossItemDao=new GenericDao<>(LossItem.class,context);
  for (  LossItem lossItem : lossItems) {
    lossItemDao.create(lossItem);
    saveLossItemDetails(lossItem.getLossItemDetails());
    snapshotService.add(adjustStockLevel(lossItem),true);
    snapshotService.add(lossItem);
  }
}
Program: 146295
Project: 146295
Buggy source:
private void adjustStockLevel(LossItem lossItem){
  stockService.reduceStockLevelFor(lossItem.getCommodity(),lossItem.getTotalLosses(),lossItem.created());
}

Fixed version (ground truth):
private StockItemSnapshot adjustStockLevel(LossItem lossItem){
  return stockService.reduceStockLevelFor(lossItem.getCommodity(),lossItem.getTotalLosses(),lossItem.created());
}
Program: 146296
Project: 146296
Buggy source:
private void saveReceiveItems(List<ReceiveItem> receiveItems){
  GenericDao<ReceiveItem> receiveItemDao=new GenericDao<>(ReceiveItem.class,context);
  for (  ReceiveItem receiveItem : receiveItems) {
    receiveItemDao.create(receiveItem);
    stockService.increaseStockLevelFor(receiveItem.getCommodity(),receiveItem.getQuantityReceived(),receiveItem.created());
    commoditySnapshotService.add(receiveItem);
  }
  alertsService.updateLowStockAlerts();
}

Fixed version (ground truth):
private void saveReceiveItems(List<ReceiveItem> receiveItems){
  GenericDao<ReceiveItem> receiveItemDao=new GenericDao<>(ReceiveItem.class,context);
  for (  ReceiveItem receiveItem : receiveItems) {
    receiveItemDao.create(receiveItem);
    commoditySnapshotService.add(stockService.increaseStockLevelFor(receiveItem.getCommodity(),receiveItem.getQuantityReceived(),receiveItem.created()),true);
    commoditySnapshotService.add(receiveItem);
  }
  alertsService.updateLowStockAlerts();
}
Program: 146297
Project: 146297
Buggy source:
@Override public Void operate(Dao<StockItem,String> dao) throws SQLException {
  dao.update(stockItem);
  stockItemSnapshotService.createOrUpdate(commodity,stockItem.getQuantity(),date);
  return null;
}

Fixed version (ground truth):
@Override public Void operate(Dao<StockItem,String> dao) throws SQLException {
  dao.update(stockItem);
  return null;
}
Program: 146298
Project: 146298
Buggy source:
public void increaseStockLevelFor(Commodity commodity,int quantity,Date date){
  StockItem stockItem=commodity.increaseStockOnHandBy(quantity);
  saveStockLevel(commodity,stockItem,date);
  categoryService.clearCache();
}

Fixed version (ground truth):
public StockItemSnapshot increaseStockLevelFor(Commodity commodity,int quantity,Date date){
  StockItem stockItem=commodity.increaseStockOnHandBy(quantity);
  StockItemSnapshot siss=saveStockLevel(commodity,stockItem,date);
  categoryService.clearCache();
  return siss;
}
Program: 146299
Project: 146299
Buggy source:
public void reduceStockLevelFor(final Commodity commodity,int quantity,Date date){
  StockItem stockItem=commodity.reduceStockOnHandBy(quantity);
  saveStockLevel(commodity,stockItem,date);
  categoryService.clearCache();
}

Fixed version (ground truth):
public StockItemSnapshot reduceStockLevelFor(final Commodity commodity,int quantity,Date date){
  StockItem stockItem=commodity.reduceStockOnHandBy(quantity);
  StockItemSnapshot siss=saveStockLevel(commodity,stockItem,date);
  categoryService.clearCache();
  return siss;
}
Program: 146300
Project: 146300
Buggy source:
private void saveStockLevel(final Commodity commodity,final StockItem stockItem,final Date date){
  dbUtil.withDao(context,StockItem.class,new DbUtil.Operation<StockItem,Void>(){
    @Override public Void operate(    Dao<StockItem,String> dao) throws SQLException {
      dao.update(stockItem);
      stockItemSnapshotService.createOrUpdate(commodity,stockItem.getQuantity(),date);
      return null;
    }
  }
);
}

Fixed version (ground truth):
private StockItemSnapshot saveStockLevel(final Commodity commodity,final StockItem stockItem,final Date date){
  dbUtil.withDao(context,StockItem.class,new DbUtil.Operation<StockItem,Void>(){
    @Override public Void operate(    Dao<StockItem,String> dao) throws SQLException {
      dao.update(stockItem);
      return null;
    }
  }
);
  return stockItemSnapshotService.createOrUpdate(commodity,stockItem.getQuantity(),date);
}
Program: 146301
Project: 146301
Buggy source:
@Test public void shouldReturnReturnedToLGAUtilizationItemWithCorrectUtilizationValue() throws Exception {
  commodityService.initialise(new User("String_Node_Str","String_Node_Str"));
  categoryService.clearCache();
  Commodity commodity=categoryService.all().get(6).getCommodities().get(0);
  Calendar calendar=Calendar.getInstance();
  Date today=calendar.getTime();
  assertNotNull(commodity);
  adjust(commodity,2,false,AdjustmentReason.RETURNED_TO_LGA,adjustmentService);
  adjust(commodity,3,false,AdjustmentReason.RETURNED_TO_LGA,adjustmentService);
  List<UtilizationItem> utilizationItems=commodityService.getMonthlyUtilizationItems(commodity,today);
  int expectedValue=5;
  int utilizationValueIndex=DateUtil.dayNumber(today) - 1;
  assertThat(utilizationItems.get(5).getUtilizationValues().get(utilizationValueIndex).getValue(),is(expectedValue));
}

Fixed version (ground truth):
@Test public void shouldReturnReturnedToLGAUtilizationItemWithCorrectUtilizationValue() throws Exception {
  commodityService.initialise(new User("String_Node_Str","String_Node_Str"));
  categoryService.clearCache();
  Commodity commodity=categoryService.all().get(0).getCommodities().get(0);
  Calendar calendar=Calendar.getInstance();
  Date today=calendar.getTime();
  assertNotNull(commodity);
  adjust(commodity,2,false,AdjustmentReason.RETURNED_TO_LGA,adjustmentService);
  adjust(commodity,3,false,AdjustmentReason.RETURNED_TO_LGA,adjustmentService);
  List<UtilizationItem> utilizationItems=commodityService.getMonthlyUtilizationItems(commodity,today);
  int expectedValue=5;
  int utilizationValueIndex=DateUtil.dayNumber(today) - 1;
  assertThat(utilizationItems.get(5).getUtilizationValues().get(utilizationValueIndex).getValue(),is(expectedValue));
}
Program: 146302
Project: 146302
Buggy source:
@Test public void shouldUpdateSnapShotWhenLossItemIsSaved() throws Exception {
  Commodity commodity=commodityService.all().get(0);
  assertThat(snapshotGenericDao.queryForAll().size(),is(0));
  int stockOnHand=commodity.getStockOnHand();
  int expectedStockOnHand=stockOnHand - 1;
  Loss loss=new Loss();
  loss.addLossItem(new LossItem(commodity,1));
  lossService.saveLoss(loss);
  commodity=commodityService.all().get(0);
  assertThat(commodity.getStockOnHand(),is(expectedStockOnHand));
  assertThat(snapshotGenericDao.queryForAll().size(),is(2));
}

Fixed version (ground truth):
@Test public void shouldUpdateSnapShotWhenLossItemIsSaved() throws Exception {
  Commodity commodity=commodityService.all().get(0);
  assertThat(snapshotGenericDao.queryForAll().size(),is(0));
  int stockOnHand=commodity.getStockOnHand();
  int expectedStockOnHand=stockOnHand - 1;
  Loss loss=new Loss();
  loss.addLossItem(new LossItem(commodity,1));
  lossService.saveLoss(loss);
  commodity=commodityService.all().get(0);
  assertThat(commodity.getStockOnHand(),is(expectedStockOnHand));
}
Program: 146303
Project: 146303
Buggy source:
@Override protected CommodityDisplayStrategy getCheckBoxVisibilityStrategy(){
  return CommodityDisplayStrategy.ALLOW_ONLY_LGA_COMMODITIES;
}

Fixed version (ground truth):
@Override protected CommodityDisplayStrategy getCheckBoxVisibilityStrategy(){
  return new CommodityDisplayStrategy(){
    @Override public boolean allowClick(    BaseCommodityViewModel commodityViewModel){
      return !"String_Node_Str".equals(commodityViewModel.getCommodity().getCategory().getName());
    }
    @Override public String getMessage(){
      return String.format("String_Node_Str");
    }
    @Override public String getEmptyMessage(){
      return String.format("String_Node_Str");
    }
    @Override public boolean hideCommodities(){
      return true;
    }
  }
;
}