VClock { public void set(String pid, long ticks) { if (ticks <= 0) { ticks = 1; } if (this.vc.containsKey(pid)) this.vc.put(pid, ticks); else this.vc.put(pid, ticks); } VClock(); void tick(String pid); void set(String pid, long ticks); VClock copy(); long findTicks(String pid); long lastUpdate(); void merge(VClock other); String returnVCString(); void printVC(); TreeMap<String, Long> getClockMap();  }
@Test public void set() throws Exception { testClock.set("Proc1", 1); TreeMap clockMap = testClock.getClockMap(); assertEquals("Key value does not match the expected value!", 1L, clockMap.get("Proc1")); assertEquals("Process ID does not conform to the expected key!", "Proc1", clockMap.firstEntry().getKey()); testClock.set("Proc1", 10); assertEquals("Key value after second tick does not match the expected value!", 10L, clockMap.get("Proc1")); assertEquals("Process ID after second tick does not conform to the expected key!", "Proc1", clockMap.firstEntry().getKey()); testClock.set("Proc2", 2); assertEquals("Key value for Proc1 does not match the expected value!", 10L, clockMap.get("Proc1")); assertEquals("Key value for Proc2 does not match the expected value!", 2L, clockMap.get("Proc2")); assertEquals("Process ID does not conform to the expected key!", "Proc1", clockMap.firstKey()); assertEquals("Process ID does not conform to the expected key!", "Proc2", clockMap.lastKey()); testClock.set("Proc1", Long.MAX_VALUE); assertEquals("Key value for Proc1 does not match the expected value!", Long.MAX_VALUE, clockMap.get("Proc1")); testClock.set("Proc1", 0); assertEquals("Key value for Proc1 does not match the expected value!", 1L, clockMap.get("Proc1")); testClock.set("Proc1", Long.MIN_VALUE); assertEquals("Key value for Proc1 does not match the expected value!", 1L, clockMap.get("Proc1")); }
@Test(expected = NullPointerException.class) public void setNullPointerException() { testClock.set(null, 0); }