### Question:
CSNGenerator { public CSN newCSN() { long curTime = TimeThread.getTime(); int mySeqnum; long myTime; synchronized(this) { if (curTime > lastTime) { lastTime = curTime; } if (++seqnum <= 0) { seqnum = 0; lastTime++; } mySeqnum = seqnum; myTime = lastTime; } return new CSN(myTime, mySeqnum, serverId); } CSNGenerator(int serverId, long timestamp);  CSNGenerator(int serverId, ServerState state); CSN newCSN(); void adjust(CSN number); void adjust(ServerState state);  }### Answer:
@Test public void adjustRollingSeqnum() { ServerState state = new ServerState(); CSN csn1 = new CSN(TimeThread.getTime(), Integer.MAX_VALUE, 5); state.update(csn1); CSNGenerator generator = new CSNGenerator(5, state); CSN csn2 = generator.newCSN(); assertEquals(csn2.getSeqnum(), 0); assertTrue(csn2.getTime() > csn1.getTime()); }
@Test public void newCSN() { CSNGenerator generator = new CSNGenerator(5, TimeThread.getTime()); CSN[] csns = new CSN[] { generator.newCSN(), generator.newCSN(), generator.newCSN(), generator.newCSN(), generator.newCSN() }; assertNotNull(csns); for (int i = 0; i + 1 < csns.length; i++) { assertEquals(csns[i + 1].getTime(), csns[i].getTime()); assertEquals(csns[i + 1].getSeqnum(), csns[i].getSeqnum() + 1); assertEquals(csns[i + 1].getServerId(), csns[i].getServerId()); assertTrue(csns[i + 1].compareTo(csns[0]) > 0); } }