SyncUpManager { public void syncUpCmms() { try { List<Cmm> unsyncedCmms = cmmRepository.listUnsynced(); if (!unsyncedCmms.isEmpty()) { List<CmmEntry> cmmEntries = FluentIterable .from(unsyncedCmms) .transform(CmmEntry::createFrom) .toList(); lmisRestApi.syncUpCmms(UserInfoMgr.getInstance().getUser().getFacilityId(), cmmEntries); for (Cmm cmm : unsyncedCmms) { cmm.setSynced(true); cmmRepository.save(cmm); } } } catch (LMISException e) { new LMISException(e, "SyncUpManager.syncUpCmms").reportToFabric(); } } 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 shouldSyncUpCmmsAndMarkThemAsSynced() throws Exception { List<Cmm> cmms = createCmmsData(); Cmm cmm = cmms.get(0); when(mockedCmmRepository.listUnsynced()).thenReturn(cmms); assertThat(cmm.isSynced(), is(false)); syncUpManager.syncUpCmms(); verify(mockedLmisRestApi, times(1)).syncUpCmms(eq("123"), anyListOf(CmmEntry.class)); assertThat(cmm.isSynced(), is(true)); verify(mockedCmmRepository).save(cmm); }
@Test public void shouldNotInvokeNetworkWhenNoUnsyncedCmmPresent() throws Exception { List<Cmm> emptyCmmsList = new ArrayList<>(); when(mockedCmmRepository.listUnsynced()).thenReturn(emptyCmmsList); syncUpManager.syncUpCmms(); verify(mockedLmisRestApi, never()).syncUpCmms(anyString(), anyList()); }
@Test public void shouldNotMarkCmmsAsSyncedWhenSyncUpFails() throws Exception { List<Cmm> cmms = createCmmsData(); Cmm cmm = cmms.get(0); when(mockedCmmRepository.listUnsynced()).thenReturn(cmms); when(mockedLmisRestApi.syncUpCmms(any(String.class), anyList())).thenThrow(new LMISException("some error")); assertThat(cmm.isSynced(), is(false)); syncUpManager.syncUpCmms(); verify(mockedLmisRestApi, times(1)).syncUpCmms(eq("123"), anyListOf(CmmEntry.class)); assertThat(cmm.isSynced(), is(false)); verify(mockedCmmRepository, never()).save(cmm); }