コード例 #1
0
        //-------------------------------------------------------------------------
        public virtual void test_equalsHashCodeToString()
        {
            ByteSource source = ByteSource.wrap(SAMPLE.GetBytes(Encoding.UTF8));
            XmlFile    test   = XmlFile.of(source);
            XmlFile    test2  = XmlFile.of(source);

            assertFalse(test.Equals(null));
            assertFalse(test.Equals(ANOTHER_TYPE));
            assertEquals(test, test);
            assertEquals(test, test2);
            assertEquals(test.GetHashCode(), test2.GetHashCode());
            assertEquals(test.ToString(), test2.ToString());
        }
コード例 #2
0
        //-------------------------------------------------------------------------
        public virtual void test_of_ByteSource()
        {
            ByteSource source = ByteSource.wrap(SAMPLE.GetBytes(Encoding.UTF8));
            XmlFile    test   = XmlFile.of(source);
            XmlElement root   = test.Root;

            assertEquals(root.Name, "base");
            assertEquals(root.Attributes, ATTR_MAP_EMPTY);
            assertEquals(root.Content, "");
            assertEquals(root.Children.size(), 1);
            XmlElement child = root.getChild(0);

            assertEquals(child, XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_MULTI));
            assertEquals(test.References, ImmutableMap.of());
        }
コード例 #3
0
        public virtual void test_of_ByteSource_namespace()
        {
            ByteSource source = ByteSource.wrap(SAMPLE_NAMESPACE.GetBytes(Encoding.UTF8));
            XmlFile    test   = XmlFile.of(source);
            XmlElement root   = test.Root;

            assertEquals(root.Name, "base");
            assertEquals(root.Attributes, ImmutableMap.of());
            assertEquals(root.Content, "");
            assertEquals(root.Children.size(), 2);
            XmlElement child1 = root.getChild(0);

            assertEquals(child1.Name, "p");
            assertEquals(child1.Content, "Some text");
            assertEquals(child1.Attributes, ImmutableMap.of());
            XmlElement child2 = root.getChild(1);

            assertEquals(child2.Name, "leaf1");
            assertEquals(child2.Content, "leaf");
            assertEquals(child2.Attributes, ImmutableMap.of("foo", "bla", "og", "strata"));
            assertEquals(test.References, ImmutableMap.of());
        }
コード例 #4
0
        public virtual void test_of_ByteSource_parsedReferences_ioException()
        {
            ByteSource source = Files.asByteSource(new File("/oh-dear-no-such-file"));

            assertThrows(() => XmlFile.of(source, "key"), typeof(UncheckedIOException));
        }
コード例 #5
0
        public virtual void test_of_ByteSource_badEnd()
        {
            ByteSource source = ByteSource.wrap(SAMPLE_BAD_END.GetBytes(Encoding.UTF8));

            assertThrowsIllegalArg(() => XmlFile.of(source));
        }
コード例 #6
0
        public virtual void test_of_ByteSource_mismatchedTags()
        {
            ByteSource source = ByteSource.wrap(SAMPLE_MISMATCHED_TAGS.GetBytes(Encoding.UTF8));

            assertThrowsIllegalArg(() => XmlFile.of(source));
        }