SyncUpManager { public boolean syncDeleteMovement() { int unitCount = 6; String facilityId = UserInfoMgr.getInstance().getUser().getFacilityId(); List<DirtyDataItemInfo> itemInfos = dirtyDataRepository.listunSyced(); List<String> errorProducts = new ArrayList<>(); if (!CollectionUtils.isEmpty(itemInfos)) { List<DirtyDataItemEntry> entries = FluentIterable.from(itemInfos).transform(new Function<DirtyDataItemInfo, DirtyDataItemEntry>() { @Nullable @Override public DirtyDataItemEntry apply(@Nullable DirtyDataItemInfo dirtyDataItemInfo) { return new DirtyDataItemEntry(dirtyDataItemInfo.getProductCode(), dirtyDataItemInfo.getJsonData()); } }).toList(); for (int start = 0; start < entries.size(); ) { int end = (start + unitCount) >= entries.size() ? entries.size() : start + unitCount; List<DirtyDataItemEntry> sub = entries.subList(start, end); try { SyncUpDeletedMovementResponse response = lmisRestApi.syncUpDeletedData(Long.parseLong(facilityId), sub); errorProducts.addAll(response.getErrorCodes()); } catch (LMISException e) { e.printStackTrace(); } start += unitCount; } List<String> shouldMarkedToSynced = FluentIterable.from(itemInfos).transform(new Function<DirtyDataItemInfo, String>() { @Nullable @Override public String apply(@Nullable DirtyDataItemInfo dirtyDataItemInfo) { return dirtyDataItemInfo.getProductCode(); } }).filter(s -> !errorProducts.contains(s)).toList(); for (DirtyDataItemInfo item : itemInfos) { if (shouldMarkedToSynced.contains(item.getProductCode())) { item.setSynced(true); dirtyDataRepository.save(item); } } return errorProducts.size() == 0; } else { return true; } } SyncUpManager(); boolean syncRnr(); boolean fakeSyncRnr(); boolean syncStockCards(); boolean fakeSyncStockCards(); void syncUpUnSyncedStockCardCodes(); void fakeSyncUpUnSyncedStockCardCodes(); void syncAppVersion(); void syncArchivedProducts(); void syncUpCmms(); void fakeSyncUpCmms(); boolean syncDeleteMovement(); void syncRapidTestForms(); void fakeSyncRapidTestForms();  }
@Test public void shouldSyncDeletedProductToWeb() throws Exception { String unSyncedProductCode = "08N04Z"; SyncUpDeletedMovementResponse response = new SyncUpDeletedMovementResponse(); response.setErrorCodes(newArrayList(unSyncedProductCode)); String unSyncedProductCode1 = "08N04Z"; SyncUpDeletedMovementResponse response1 = new SyncUpDeletedMovementResponse(); response1.setErrorCodes(newArrayList(unSyncedProductCode1)); List<DirtyDataItemInfo> dirtyDataItems = createDirtyDateItem(); DirtyDataItemInfo item = dirtyDataItems.get(0); when(mockedDirtyDataRepository.listunSyced()).thenReturn(dirtyDataItems); when(mockedLmisRestApi.syncUpDeletedData(any(Long.class), anyList())).thenReturn(response); assertThat(item.isSynced(), is(false)); syncUpManager.syncDeleteMovement(); for (int i = 0; i < dirtyDataItems.size(); i++) { if (unSyncedProductCode.equals(dirtyDataItems.get(i).getProductCode())) { assertThat(dirtyDataItems.get(i).isSynced(), is(false)); } else { assertThat(dirtyDataItems.get(i).isSynced(), is(true)); } } assertEquals(response, response1); }