/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.sling.commons.json.util;

import static org.junit.Assert.assertTrue;

import org.apache.sling.commons.json.JSONException;
import org.junit.Test;

/**
 * Test the Validator.
 */
public class ValidatorTest {

    @Test
    public void testSimpleJSON() throws JSONException {
        Validator.validate("");
        Validator.validate("[]");
        Validator.validate("{}");
    }

    @Test
    public void testBasicJSON() throws JSONException {
        Validator.validate("[1,true,\"hallo\"]");
        Validator.validate("{a:\"you\", b:2, c:true}");
    }

    @Test
    public void testNestedJSON() throws JSONException {
        Validator.validate("[1,true,\"hallo\", {a:1}, [1,2]]");
        Validator.validate("{a:\"you\", b:2, c:true, d: {d:1}, e: []}");
    }

    /**
     * These tests are supposed to fail!
     */
    @Test
    public void testTrailingChars() {
        try {
            Validator.validate("[1,true,\"hallo\",]");
            assertTrue("Trailing separator should not be allowed.", false);
        } catch (JSONException e) {
            // ignore
        }
        try {
            Validator.validate("{a:\"you\", b:2, c:true,}");
            assertTrue("Trailing separator should not be allowed.", false);
        } catch (JSONException e) {
            // ignore
        }
    }

}

@@ -845,52 +845,8 @@
 l;%0A%0A
-import static org.junit.Assert.assertTrue;%0A%0A
 impo
@@ -1547,70 +1547,43 @@
     
-/**%0A     * These tests are supposed to fail!%0A     */%0A    @Test
+@Test(expected=JSONException.class)
 %0A   
@@ -1616,24 +1616,36 @@
 hars
-() %7B%0A        try
+Array() throws JSONException
  %7B%0A 
@@ -1643,36 +1643,32 @@
 ption %7B%0A        
- 
-   
 Validator.valida
@@ -1702,97 +1702,100 @@
     
+%7D%0A%0A
     
-    assertTrue(%22Trailing separator should not be allowed.%22, false);%0A        %7D catch (
+@Test(expected=JSONException.class)%0A    public void testTrailingCharsObject() throws 
 JSON
@@ -1795,35 +1795,32 @@
 ws JSONException
- e)
  %7B%0A            /
@@ -1818,250 +1818,56 @@
     
-    // ignore%0A        %7D%0A        try %7B%0A            Validator.validate(%22%7Ba:%5C%22you%5C%22, b:2, c:true,%7D%22);%0A            assertTrue(%22Trailing separator should not be allowed.%22, false);%0A        %7D catch (JSONException e) %7B%0A            // ignore%0A        %7D
+Validator.validate(%22%7Ba:%5C%22you%5C%22, b:2, c:true,%7D%22);
 %0A   

simplify test cases expected to fail (no functional change)