コード例 #1
0
        public void testEquals()
        {
            // test passing null to Equals returns false
            // (as specified in the JDK docs for Object)
            TagURI x = new TagURI(AUTHORITIES[1], IDS[2], null);
            assertFalse("Equals(null) didn't return false",
                    x.Equals((Object)null));

            // test that passing an object which is not a TagURI returns false
            assertFalse("x.Equals(non_TagURI_object) didn't return false",
                        x.Equals(new Object()));

            // test a case where two TagURIs are definitly not equal
            TagURI w = new TagURI(AUTHORITIES[2], IDS[0], DateTime.Now);
            assertFalse("x == w didn't return false",
                        x == w);
            assertFalse("x.Equals(w) didn't return false",
                        x.Equals(w));

            // test refelexivity
            assertTrue("x.Equals(x) didn't return true",
                        x.Equals(x));

            // test symmetry
            TagURI y = new TagURI(AUTHORITIES[1], IDS[2], null);
            assertFalse("x == y didn't return false",
                        x == y);
            assertTrue("y.Equals(x) didn't return true",
                        y.Equals(x));
            assertTrue("x.Equals(y) didn't return true",
                        x.Equals(y));

            // now we'll test transitivity
            TagURI z = new TagURI(AUTHORITIES[1], IDS[2], null);
            assertFalse("x == y didn't return false",
                        x == y);
            assertFalse("x == y didn't return false",
                        y == z);
            assertFalse("x == y didn't return false",
                        x == z);
            assertTrue("x.Equals(y) didn't return true",
                        x.Equals(y));
            assertTrue("y.Equals(z) didn't return true",
                        y.Equals(z));
            assertTrue("x.Equals(z) didn't return true",
                        x.Equals(z));

            // test consistancy (this test is just calling Equals multiple times)
            assertFalse("x == y didn't return false",
                        x == y);
            assertTrue("x.Equals(y) didn't return true",
                        x.Equals(y));
            assertTrue("x.Equals(y) didn't return true",
                        x.Equals(y));
            assertTrue("x.Equals(y) didn't return true",
                        x.Equals(y));
        }
コード例 #2
0
 /**
  * Method for generating UUIDs using tag URIs. A hash is calculated from
  * the given tag URI using the specified hashing algorith,.
  * The resulting UUIDs are reproducible, ie. given the same tag URI and
  * hash algorithm, same UUID will always result, much like with the
  * default name-based generation method.
  *
  * Note that this a non-standard way of generating UUIDs; it will create
  * UUIDs that appear to be name-based (and which are, but not using the
  * method specified in UUID specs).
  *
  * @param name tag URI to base UUID on.
  * @param hasher Hashing algorithm to use. Note that the caller has to
  *  make sure that it's thread-safe to use 'hasher', either by never
  *  calling this method from multiple threads, or by explicitly sync'ing
  *  the calls.
  */
 public UUID GenerateTagURIBasedUUID(TagURI name, MD5 hasher)
 {
     return GenerateNameBasedUUID(null, name.ToString(), hasher);
 }
コード例 #3
0
 /**
  * Method for generating UUIDs using tag URIs. A hash is calculated from
  * the given tag URI (default being MD5 hash). The resulting UUIDs
  * are reproducible, ie. given the same tag URI, same UUID will always
  * result, much like with the default name-based generation method.
  *
  * Note that this a non-standard way of generating UUIDs; it will create
  * UUIDs that appear to be name-based (and which are, but not using the
  * method specified in UUID specs).
  *
  * @param name tag URI to base UUID on.
  */
 public UUID GenerateTagURIBasedUUID(TagURI name)
 {
     return GenerateNameBasedUUID(null, name.ToString());
 }
コード例 #4
0
 /**
  * Method for generating UUIDs using tag URIs. A hash is calculated from
  * the given tag URI using the specified hashing algorith,.
  * The resulting UUIDs are reproducible, ie. given the same tag URI and
  * hash algorithm, same UUID will always result, much like with the
  * default name-based generation method.
  *
  * Note that this a non-standard way of generating UUIDs; it will create
  * UUIDs that appear to be name-based (and which are, but not using the
  * method specified in UUID specs).
  *
  * @param name tag URI to base UUID on.
  * @param hasher Hashing algorithm to use. Note that the caller has to
  *  make sure that it's thread-safe to use 'hasher', either by never
  *  calling this method from multiple threads, or by explicitly sync'ing
  *  the calls.
  */
 public UUID GenerateTagURIBasedUUID(TagURI name, MD5 hasher)
 {
     return(GenerateNameBasedUUID(null, name.ToString(), hasher));
 }
コード例 #5
0
 /**
  * Method for generating UUIDs using tag URIs. A hash is calculated from
  * the given tag URI (default being MD5 hash). The resulting UUIDs
  * are reproducible, ie. given the same tag URI, same UUID will always
  * result, much like with the default name-based generation method.
  *
  * Note that this a non-standard way of generating UUIDs; it will create
  * UUIDs that appear to be name-based (and which are, but not using the
  * method specified in UUID specs).
  *
  * @param name tag URI to base UUID on.
  */
 public UUID GenerateTagURIBasedUUID(TagURI name)
 {
     return(GenerateNameBasedUUID(null, name.ToString()));
 }
コード例 #6
0
        public void testToString()
        {
            DateTime CALENDAR = DateTime.Now;

            // we'll test that a few expected constructed TagURI's create the
            // expected strings

            // first, some tests with a null calendar
            for (int i = 0; i < 4; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    TagURI tag_uri = new TagURI(AUTHORITIES[i], IDS[j], null);
                    String expected = "tag:" + AUTHORITIES[i] + ":" + IDS[j];
                    Assert.AreEqual(
                        expected,
                        tag_uri.ToString(), "Expected string did not match generated ToString()");
                }
            }

            // now some cases with date
            for (int i = 0; i < 4; ++i)
            {
                CALENDAR = new DateTime(2006, 6, 4);

                for (int j = 0; j < 4; ++j)
                {
                    TagURI tag_uri = new TagURI(AUTHORITIES[i], IDS[j], CALENDAR);
                    String expected = "tag:" + AUTHORITIES[i] + "," +
                        CALENDAR.Year + "-" +
                        CALENDAR.Month + "-" +
                        CALENDAR.Day + ":" + IDS[j];
                    Assert.AreEqual(
                        expected,
                        tag_uri.ToString(),
                        "Expected string did not match generated ToString()"
                        );
                }
            }

            // now some cases with date such that day is left out
            // (first of the month)
            for (int i = 0; i < 4; ++i)
            {
                CALENDAR = new DateTime(2006, 6, 1);

                for (int j = 0; j < 4; ++j)
                {
                    TagURI tag_uri = new TagURI(AUTHORITIES[i], IDS[j], CALENDAR);
                    String expected = "tag:" + AUTHORITIES[i] + "," +
                        CALENDAR.Year + "-" +
                        CALENDAR.Month + ":" + IDS[j];
                    Assert.AreEqual(
                        expected,
                        tag_uri.ToString(),
                        "Expected string did not match generated ToString()"
                        );
                }
            }

            // now some cases with date such that day and month are left out
            // (jan-1)
            for (int i = 0; i < 4; ++i)
            {
                CALENDAR = new DateTime(2006, 1, 1);

                for (int j = 0; j < 4; ++j)
                {
                    TagURI tag_uri = new TagURI(AUTHORITIES[i], IDS[j], CALENDAR);
                    String expected = "tag:" + AUTHORITIES[i] + "," +
                        CALENDAR.Year + ":" + IDS[j];
                    Assert.AreEqual(
                        expected,
                        tag_uri.ToString(),
                        "Expected string did not match generated ToString()"
                        );
                }
            }
        }