001    /*
002     * (c) Copyright 2010 University of Bristol
003     * All rights reserved.
004     * [See end of file]
005     */
006    package net.rootdev.javardfa.output;
007    
008    import java.io.StringWriter;
009    import org.junit.Before;
010    import org.junit.Test;
011    import static org.junit.Assert.*;
012    
013    /**
014     *
015     * @author pldms
016     */
017    public class NTripleSinkTest {
018        private StringWriter out;
019        private NTripleSink sink;
020    
021        public NTripleSinkTest() {
022        }
023    
024        @Before
025        public void setUp() {
026            this.out = new StringWriter();
027            this.sink = new NTripleSink(out);
028        }
029    
030        /**
031         * Test of end method, of class NTripleSink.
032         */
033        @Test
034        public void testEnd() {}
035    
036        /**
037         * Test of addObject method, of class NTripleSink.
038         */
039        @Test
040        public void testAddObject() {}
041    
042        /**
043         * Test of addLiteral method, of class NTripleSink.
044         */
045        @Test
046        public void testAddLiteral() {}
047    
048        /**
049         * Test of addPrefix method, of class NTripleSink.
050         */
051        @Test
052        public void testAddPrefix() {}
053    
054        /**
055         * Test of toNode method, of class NTripleSink.
056         */
057        @Test
058        public void testToNode() {
059            assertEquals("Convert bnode", "_:a ", sink.toNode("_:a"));
060            assertEquals("Convert var", "?a ", sink.toNode("?a"));
061            assertEquals("Convert uri", "<http://www.example.com/> ", sink.toNode("http://www.example.com/"));
062        }
063    
064        /**
065         * Test of toLiteral method, of class NTripleSink.
066         */
067        @Test
068        public void testToLiteral() {
069            assertEquals("Convert plain", "\"a\" ", sink.toLiteral("a", null, null));
070            assertEquals("Convert lang", "\"a\"@en ", sink.toLiteral("a", "en", null));
071            assertEquals("Convert no lang", "\"a\" ", sink.toLiteral("a", "", null));
072            assertEquals("Convert dt", "\"a\"^^<http://www.example.com/> ", sink.toLiteral("a", null, "http://www.example.com/"));
073        }
074    
075        /**
076         * Test of quote method, of class NTripleSink.
077         */
078        @Test
079        public void testQuote() {
080            assertEquals("Quote me", "\"a\\\"b\"", sink.quote("a\"b"));
081            assertEquals("Quote tab", "\"a\\tb\"", sink.quote("a\tb"));
082            assertEquals("Quote newline", "\"a\\nb\"", sink.quote("a\nb"));
083            assertEquals("Quote non-ascii", "\"a\\ufeffb\"", sink.quote("a\ufeffb"));
084        }
085    
086    }
087    
088    /*
089     * (c) Copyright 2010 University of Bristol
090     * All rights reserved.
091     *
092     * Redistribution and use in source and binary forms, with or without
093     * modification, are permitted provided that the following conditions
094     * are met:
095     * 1. Redistributions of source code must retain the above copyright
096     *    notice, this list of conditions and the following disclaimer.
097     * 2. Redistributions in binary form must reproduce the above copyright
098     *    notice, this list of conditions and the following disclaimer in the
099     *    documentation and/or other materials provided with the distribution.
100     * 3. The name of the author may not be used to endorse or promote products
101     *    derived from this software without specific prior written permission.
102     *
103     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
104     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
105     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
106     * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
107     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
108     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
109     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
110     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
111     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
112     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
113     */