### Question:
RpSyncService { public static boolean shouldSync(Rp rp) { if (rp == null || !rp.isSyncClientFromOp()) return false; if (rp.getLastSynced() == null) return true; if ((Utils.addTimeToDate(rp.getLastSynced(), rp.getSyncClientPeriodInSeconds(), Calendar.SECOND).getTime() < new Date().getTime())) return true; return false; } @Inject  RpSyncService(RpService rpService, PersistenceService persistenceService); static boolean shouldSync(Rp rp); Rp getRp(String oxdId); Rp getRpTest(String oxdId); RegisterResponse readClientFromRp(String clientRegistrationClientUri, String clientRegistrationAccessToken);  }### Answer:
@Test public void afterSyncClientPeriodfromLastSynced_shouldSync() { Rp rp = new Rp(); rp.setSyncClientFromOp(true); rp.setLastSynced(Utils.addTimeToDate(new Date(), -10, Calendar.MINUTE)); rp.setSyncClientPeriodInSeconds(5 * 60); assertTrue(rpSyncService.shouldSync(rp)); }
@Test public void beforeSyncClientPeriodfromLastSynced_shouldNotSync() { Rp rp = new Rp(); rp.setSyncClientFromOp(true); rp.setLastSynced(Utils.addTimeToDate(new Date(), -10, Calendar.MINUTE)); rp.setSyncClientPeriodInSeconds(15 * 60); assertFalse(rpSyncService.shouldSync(rp)); }
@Test public void forNullRp_shouldNotSync() { assertFalse(rpSyncService.shouldSync(null)); rpService.removeAllRps(); }
@Test public void forNotNullRp_shouldSync() { Rp rp = new Rp(); rp.setSyncClientFromOp(true); rp.setLastSynced(Utils.addTimeToDate(new Date(), -10, Calendar.MINUTE)); rp.setSyncClientPeriodInSeconds(5 * 60); assertTrue(rpSyncService.shouldSync(rp)); }
@Test public void forSyncAllowed_shouldSync() { Rp rp = new Rp(); rp.setSyncClientFromOp(true); rp.setLastSynced(Utils.addTimeToDate(new Date(), -10, Calendar.MINUTE)); rp.setSyncClientPeriodInSeconds(5 * 60); assertTrue(rpSyncService.shouldSync(rp)); }
@Test public void forSyncNotAllowed_shouldNotSync() { Rp rp = new Rp(); rp.setSyncClientFromOp(false); rp.setLastSynced(Utils.addTimeToDate(new Date(), -10, Calendar.MINUTE)); rp.setSyncClientPeriodInSeconds(5 * 60); assertFalse(rpSyncService.shouldSync(rp)); }
@Test public void forNoLastSyncedDate_shouldSync() { Rp rp = new Rp(); rp.setSyncClientFromOp(true); rp.setSyncClientPeriodInSeconds(5 * 60); assertTrue(rpSyncService.shouldSync(rp)); }
@Test public void forLastSyncedDatePresent_shouldSync() { Rp rp = new Rp(); rp.setSyncClientFromOp(true); rp.setLastSynced(Utils.addTimeToDate(new Date(), -10, Calendar.MINUTE)); rp.setSyncClientPeriodInSeconds(5 * 60); assertTrue(rpSyncService.shouldSync(rp)); }