@Test public void testNextId_returnsInitialIdAfterReturningMaxInteger() { int expectedId = MAX_VALUE; storeNextIdInSharedPrefs(expectedId); int nextId = mIdGenerator.nextJobSchedulerIdWithRange(INITIAL_ID, MAX_VALUE); assertThat(nextId, is(MAX_VALUE)); nextId = mIdGenerator.nextJobSchedulerIdWithRange(INITIAL_ID, MAX_VALUE); assertThat(nextId, is(INITIAL_ID)); }
public int nextJobSchedulerIdWithRange(int minInclusive, int maxInclusive) { synchronized (IdGenerator.class) { int id = nextId(NEXT_JOB_SCHEDULER_ID_KEY); if (id < minInclusive || id > maxInclusive) { id = minInclusive; update(NEXT_JOB_SCHEDULER_ID_KEY, id + 1); } return id; } }
IdGenerator { public int nextJobSchedulerIdWithRange(int minInclusive, int maxInclusive) { synchronized (IdGenerator.class) { int id = nextId(NEXT_JOB_SCHEDULER_ID_KEY); if (id < minInclusive || id > maxInclusive) { id = minInclusive; update(NEXT_JOB_SCHEDULER_ID_KEY, id + 1); } return id; } } }
IdGenerator { public int nextJobSchedulerIdWithRange(int minInclusive, int maxInclusive) { synchronized (IdGenerator.class) { int id = nextId(NEXT_JOB_SCHEDULER_ID_KEY); if (id < minInclusive || id > maxInclusive) { id = minInclusive; update(NEXT_JOB_SCHEDULER_ID_KEY, id + 1); } return id; } } IdGenerator(Context context); }
IdGenerator { public int nextJobSchedulerIdWithRange(int minInclusive, int maxInclusive) { synchronized (IdGenerator.class) { int id = nextId(NEXT_JOB_SCHEDULER_ID_KEY); if (id < minInclusive || id > maxInclusive) { id = minInclusive; update(NEXT_JOB_SCHEDULER_ID_KEY, id + 1); } return id; } } IdGenerator(Context context); int nextJobSchedulerIdWithRange(int minInclusive, int maxInclusive); int nextFirebaseAlarmId(); int nextAlarmManagerId(); }
IdGenerator { public int nextJobSchedulerIdWithRange(int minInclusive, int maxInclusive) { synchronized (IdGenerator.class) { int id = nextId(NEXT_JOB_SCHEDULER_ID_KEY); if (id < minInclusive || id > maxInclusive) { id = minInclusive; update(NEXT_JOB_SCHEDULER_ID_KEY, id + 1); } return id; } } IdGenerator(Context context); int nextJobSchedulerIdWithRange(int minInclusive, int maxInclusive); int nextFirebaseAlarmId(); int nextAlarmManagerId(); static final int INITIAL_ID; }