Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 16th, 2011  |  syntax: Java  |  size: 5.87 KB  |  views: 65  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  *  Copyright 2011 jmarsden.
  3.  *
  4.  *  Licensed under the Apache License, Version 2.0 (the "License");
  5.  *  you may not use this file except in compliance with the License.
  6.  *  You may obtain a copy of the License at
  7.  *
  8.  *       http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  *  Unless required by applicable law or agreed to in writing, software
  11.  *  distributed under the License is distributed on an "AS IS" BASIS,
  12.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  *  See the License for the specific language governing permissions and
  14.  *  limitations under the License.
  15.  *  under the License.
  16.  */
  17.  
  18. package jsonij.json;
  19.  
  20.  
  21. import java.io.IOException;
  22. import jsonij.parser.ParserException;
  23. import org.junit.After;
  24. import org.junit.AfterClass;
  25. import org.junit.Before;
  26. import org.junit.BeforeClass;
  27. import org.junit.Test;
  28. import static org.junit.Assert.*;
  29.  
  30. public class SJTest {
  31.  
  32.     public SJTest() {
  33.     }
  34.  
  35.     @BeforeClass
  36.     public static void setUpClass() throws Exception {
  37.     }
  38.  
  39.     @AfterClass
  40.     public static void tearDownClass() throws Exception {
  41.     }
  42.  
  43.     @Before
  44.     public void setUp() {
  45.     }
  46.  
  47.     @After
  48.     public void tearDown() {
  49.     }
  50.  
  51.     @Test
  52.     public void testSupportEmptyObject() throws ParserException, IOException {
  53.         System.out.println("Support Empty Object");
  54.         String testInput = "{}";
  55.         String testSoultion = "{}";
  56.         JSON json = JSON.parse(testInput);
  57.         String testOutput = json.toJSON();
  58.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  59.         assertEquals(testOutput, testSoultion);
  60.         testInput = "{   \t\t   }";
  61.         json = JSON.parse(testInput);
  62.         testOutput = json.toJSON();
  63.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  64.         assertEquals(testOutput, testSoultion);
  65.     }
  66.  
  67.     @Test
  68.     public void testSupportSimpleObjectFloatValue() throws ParserException, IOException {
  69.         System.out.println("Support simple Object float value");
  70.         String testInput = "{ \"PI\":3.141E-10}";
  71.         String testSoultion = "{\"PI\":3.141E-10}";
  72.         JSON json = JSON.parse(testInput);
  73.         String testOutput = json.toJSON();
  74.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  75.         assertEquals(testSoultion, testOutput);
  76.         testInput = "{  \t     \"PI\"   \t   :\t   \t3.141E-10       }";
  77.         json = JSON.parse(testInput);
  78.         testOutput = json.toJSON();
  79.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  80.         assertEquals(testSoultion, testOutput);
  81.     }
  82.  
  83.     @Test
  84.     public void testSupportLowercaseFloatValue() throws ParserException, IOException {
  85.         System.out.println("Support lowcase float value");
  86.         String testInput = "{ \"PI\":3.141e-10}";
  87.         String testSoultion = "{\"PI\":3.141E-10}";
  88.         JSON json = JSON.parse(testInput);
  89.         String testOutput = json.toJSON();
  90.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  91.         assertEquals(testSoultion, testOutput);
  92.         testInput = "{  \t     \"PI\" :\t   \t3.141e-10    }";
  93.         json = JSON.parse(testInput);
  94.         testOutput = json.toJSON();
  95.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  96.         assertEquals(testSoultion, testOutput);
  97.     }
  98.  
  99.     @Test
  100.     public void testSupportBigintNumberSupport() throws ParserException, IOException {
  101.         System.out.println("Bigint number support");
  102.         String testInput = "{ \"v\":123456789123456789123456789}";
  103.         String testSoultion = "{\"v\":123456789123456789123456789}";
  104.         JSON json = JSON.parse(testInput);
  105.         String testOutput = json.toJSON();
  106.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  107.         assertEquals(testSoultion, testOutput);
  108.         testInput = "{ \t\t  \"v\"  :   123456789123456789123456789    \t }";
  109.         json = JSON.parse(testInput);
  110.         testOutput = json.toJSON();
  111.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  112.         assertEquals(testSoultion, testOutput);
  113.     }
  114.  
  115.     @Test
  116.     public void testSupportArrayOfEmptyObject() throws ParserException, IOException {
  117.         System.out.println("Array of empty Object");
  118.         String testInput = "[ { }, { },[]]";
  119.         String testSoultion = "[{},{},[]]";
  120.         JSON json = JSON.parse(testInput);
  121.         String testOutput = json.toJSON();
  122.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  123.         assertEquals(testSoultion, testOutput);
  124.         testInput = "[   \t { }  \t, { }\t,[  ]]";
  125.         json = JSON.parse(testInput);
  126.         testOutput = json.toJSON();
  127.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  128.         assertEquals(testSoultion, testOutput);
  129.     }
  130.  
  131.     @Test
  132.     public void testSupportDoublePrecisionFloatingPoint() throws ParserException, IOException {
  133.         System.out.println("Double precision floating point");
  134.         String testInput = "{ \"v\":1.7976931348623157E308}";
  135.         String testSoultion = "{\"v\":1.7976931348623157E308}";
  136.         JSON json = JSON.parse(testInput);
  137.         String testOutput = json.toJSON();
  138.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  139.         assertEquals(testSoultion, testOutput);
  140.         testInput = "{   \t \"v\"  \t :  1.7976931348623157E308  }";
  141.         json = JSON.parse(testInput);
  142.         testOutput = json.toJSON();
  143.         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
  144.         assertEquals(testSoultion, testOutput);
  145.     }
  146.    
  147. }
clone this paste RAW Paste Data