This class does not implement Microsoft GUIDs. Instead, it is a convenience class which wraps the creation and comparison of unique identifiers.
1415161718192021
public class GUIDTest { public static class Generating_A_GUID { @Test public void shouldProduceARandomGUIDOfTheRequestedLength() throws Exception { GUID guid = GUID.generateRandom(40); assertEquals(40, guid.length()); }
202122232425262728
assertEquals(40, guid.length()); } @Test public void shouldBeAllHex() throws Exception { GUID guid = GUID.generateRandom(40); assertMatches("^[0-9a-f]+$", guid.toString()); }
29303132333435363738
} public static class Generating_A_GUID_Using_A_Different_Character_Set { @Test public void shouldBeAllHex() throws Exception { GUID guid = GUID.generateRandom(40, CharacterSet.SAFE_LOWERCASE_ALPHANUM); assertMatches("^[bcdfghjklmnpqrstvwxz0123456789]+$", guid.toString()); }
394041424344454647
} public static class Two_Equivalent_GUIDs { @Test public void shouldBeEqual() throws Exception { GUID guid1 = new GUID("yay"); GUID guid2 = new GUID("yay"); assertEquals(guid1, guid2); }
464748495051525354
assertEquals(guid1, guid2); } @Test public void shouldHaveEqualHashCodes() throws Exception { GUID guid1 = new GUID("yay"); GUID guid2 = new GUID("yay"); assertEquals(guid1.hashCode(), guid2.hashCode()); }
555657585960616263
} public static class Two_Different_GUIDs { @Test public void shouldNotBeEqual() throws Exception { GUID guid1 = new GUID("yay"); GUID guid2 = new GUID("boo"); assertFalse(guid1.equals(guid2)); }
626364656667686970
assertFalse(guid1.equals(guid2)); } @Test public void shouldHaveDifferentHashCodes() throws Exception { GUID guid1 = new GUID("yay"); GUID guid2 = new GUID("boo"); assertFalse(guid1.hashCode() == guid2.hashCode()); }
7172737475767778
} public static class A_GUID { @Test public void shouldNotBeEqualToANonGUID() throws Exception { GUID guid1 = new GUID("yay"); assertFalse(guid1.equals("yay")); }
7778798081828384
assertFalse(guid1.equals("yay")); } @Test public void shouldNotBeEqualToNull() throws Exception { GUID guid1 = new GUID("yay"); assertFalse(guid1.equals(null)); }
8384858687888990
assertFalse(guid1.equals(null)); } @Test public void shouldBeEqualToItself() throws Exception { GUID guid1 = new GUID("yay"); assertTrue(guid1.equals(guid1)); }