@@ -0,0 +1,2289 @@
+/*%0D%0A * Licensed to the Apache Software Foundation (ASF) under one%0D%0A * or more contributor license agreements.  See the NOTICE file%0D%0A * distributed with this work for additional information%0D%0A * regarding copyright ownership.  The ASF licenses this file%0D%0A * to you under the Apache License, Version 2.0 (the%0D%0A * %22License%22); you may not use this file except in compliance%0D%0A * with the License.  You may obtain a copy of the License at%0D%0A * %0D%0A *   http://www.apache.org/licenses/LICENSE-2.0%0D%0A * %0D%0A * Unless required by applicable law or agreed to in writing,%0D%0A * software distributed under the License is distributed on an%0D%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0D%0A * KIND, either express or implied.  See the License for the%0D%0A * specific language governing permissions and limitations%0D%0A * under the License.%0D%0A */%0D%0Apackage org.yuanheng.cookjson;%0D%0A%0D%0Aimport java.io.File;%0D%0Aimport java.io.FileInputStream;%0D%0Aimport java.io.IOException;%0D%0Aimport java.io.StringWriter;%0D%0A%0D%0Aimport javax.json.spi.JsonProvider;%0D%0Aimport javax.json.stream.JsonGenerator;%0D%0Aimport javax.json.stream.JsonParser;%0D%0A%0D%0Aimport org.junit.Assert;%0D%0Aimport org.junit.Test;%0D%0A%0D%0A/**%0D%0A * @author%09Heng Yuan%0D%0A */%0D%0Apublic class BsonParserTest%0D%0A%7B%0D%0A%09void testFile (String f1, String f2) throws IOException%0D%0A%09%7B%0D%0A%09%09File file1 = new File (f1.replace ('/', File.separatorChar));%0D%0A%09%09File file2 = new File (f2.replace ('/', File.separatorChar));%0D%0A%0D%0A%09%09StringWriter out1 = new StringWriter ();%0D%0A%09%09JsonParser p1 = new BsonParser (new FileInputStream (file1));%0D%0A%09%09TextJsonGenerator g1 = new TextJsonGenerator (out1);%0D%0A%09%09Utils.convert (p1, g1);%0D%0A%09%09p1.close ();%0D%0A%09%09g1.close ();%0D%0A%0D%0A%09%09StringWriter out2 = new StringWriter ();%0D%0A%09%09JsonProvider provider = new org.glassfish.json.JsonProviderImpl ();%0D%0A%09%09JsonParser p2 = provider.createParser (new FileInputStream (file2));%0D%0A%09%09JsonGenerator g2 = new TextJsonGenerator (out2);%0D%0A%09%09Utils.convert (p2, g2);%0D%0A%09%09p2.close ();%0D%0A%09%09g2.close ();%0D%0A%0D%0A%09%09Assert.assertEquals (out1.toString (), out2.toString ());%0D%0A%09%7D%0D%0A%0D%0A%09@Test%0D%0A%09public void test () throws IOException%0D%0A%09%7B%0D%0A%09%09// data1.bson has 0 in Document / Array length%0D%0A%09%09testFile (%22../tests/data/data1.bson%22, %22../tests/data/data3.json%22);%0D%0A%09%09// data2.bson has the correct length%0D%0A%09%09testFile (%22../tests/data/data2.bson%22, %22../tests/data/data3.json%22);%0D%0A%09%7D%0D%0A%7D%0D%0A

Add a simple BSON unit test.