Sequence { public synchronized int nextValue() { int curValue = value++; if (curValue == Integer.MAX_VALUE) { value = 1; } return curValue; } Sequence(int start); synchronized int nextValue(); synchronized int currentValue();  }
@Test(groups="checkintest") public void testCycle() { Sequence sequence = new Sequence(Integer.MAX_VALUE - 2); assertEquals(sequence.nextValue(), Integer.MAX_VALUE - 2); assertEquals(sequence.nextValue(), Integer.MAX_VALUE - 1); assertEquals(sequence.nextValue(), Integer.MAX_VALUE); assertEquals(sequence.nextValue(), 1); }