### Question:
AllocationService { public void syncAllocations(User user) { List<CommodityActionValue> commodityActionValues = lmisServer.fetchAllocations(user); List<Allocation> allocations = toAllocations(commodityActionValues); String facilityName = user.getFacilityName() == null ? "" : user.getFacilityName(); String facility2LetterCode = facilityName.length() > 2 ? facilityName.substring(0, 2).toUpperCase() : facilityName.toUpperCase(); boolean changed = false; if (allocations != null) { for (Allocation allocation : allocations) { if(!validateAllocationId(facility2LetterCode ,allocation.getAllocationId())){ Log.e("syncAllocations", "Allocation Id (" + allocation.getAllocationId() + ") is not valid , skiped"); continue; } if (!isExisting(allocation)) { createAllocation(allocation); changed = true; } } } if (changed) { resetCache(); } } AllocationService(DbUtil dbUtil);  AllocationService(); List<String> getYetToBeReceivedAllocationIds(); List<String> getReceivedAllocationIds(); Allocation getAllocationByLmisId(final String allocationID); void update(Allocation allocation); void syncAllocations(User user); void createAllocation(Allocation allocation); List<Allocation> getYetToBeReceivedAllocations(); List<Allocation> all(); static void clearCache();  }### Answer:
@Test public void shouldSyncAndSaveAllocations() throws Exception { User user = setupForAllocations(); setUpSuccessHttpGetRequest(200, "allocations.json"); assertThat(allocationDao.countOf(), is(0l)); allocationService.syncAllocations(user); assertThat(allocationDao.countOf(), is(2l)); List<Allocation> allocations = allocationDao.queryForAll(); Allocation firstAllocation = allocations.get(0); assertThat(firstAllocation.getAllocationId(), is("TW0001")); List<AllocationItem> allocationItems = firstAllocation.getAllocationItems(); assertThat(allocationItems.size(), is(3)); assertThat(allocationItems.get(0).getCommodity().getName(), is("Cotrimoxazole_suspension")); assertThat(allocationItems.get(0).getQuantity(), is(123)); }
@Test public void shouldNotSyncAndSaveDuplicateAllocations() throws Exception { User user = setupForAllocations(); assertThat(allocationDao.countOf(), is(0l)); setUpSuccessHttpGetRequest(200, "allocations.json"); allocationService.syncAllocations(user); assertThat(allocationDao.countOf(), is(2l)); setUpSuccessHttpGetRequest(200, "allocations.json"); allocationService.syncAllocations(user); assertThat(allocationDao.countOf(), is(2l)); }