70 lines
2.9 KiB
Java
70 lines
2.9 KiB
Java
/*
|
|
* Copyright 2020 Adler Neves.
|
|
*
|
|
* Licensed 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 br.ufes.inf.decisionelement;
|
|
import br.ufes.inf.decisionelement.wheelreinventions.json.JsonElement;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import org.junit.After;
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
/**
|
|
* Tests JSON deserialization.
|
|
*/
|
|
public class JsonDeserializationTest {
|
|
@Before
|
|
public void setUp() {
|
|
}
|
|
@After
|
|
public void tearDown() {
|
|
}
|
|
@Test
|
|
public void basics() throws Exception {
|
|
JsonElement<?> je;
|
|
Assert.assertEquals(1, 1);
|
|
je = JsonElement.parseJson("{}");
|
|
Assert.assertEquals(0, ((Map) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("{\"1\": 2}");
|
|
Assert.assertEquals(1, ((Map) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("{\"1\": 2, \"3\": 4, \"5\": 6}");
|
|
Assert.assertEquals(3, ((Map) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("{\"true\": true, \"false\": false, \"null\": null}");
|
|
Assert.assertEquals(3, ((Map) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("[]");
|
|
Assert.assertEquals(0, ((List) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("[1,2,3]");
|
|
Assert.assertEquals(3, ((List) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("[true, false, null]");
|
|
Assert.assertEquals(3, ((List) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("{\"map\":{\"list\":[true,false,null]}}");
|
|
Assert.assertEquals(1, ((Map) je.getRepresentation()).size());
|
|
je = JsonElement.parseJson("0");
|
|
Assert.assertEquals((Double) 0d, je.getRepresentation());
|
|
je = JsonElement.parseJson("0.1");
|
|
Assert.assertEquals((Double) 0.1, je.getRepresentation());
|
|
je = JsonElement.parseJson("1.2");
|
|
Assert.assertEquals((Double) 1.2, je.getRepresentation());
|
|
je = JsonElement.parseJson(".2");
|
|
Assert.assertEquals((Double) .2, je.getRepresentation());
|
|
je = JsonElement.parseJson("null");
|
|
Assert.assertEquals((Object) null, je.getRepresentation());
|
|
je = JsonElement.parseJson("true");
|
|
Assert.assertEquals((Boolean) true, je.getRepresentation());
|
|
je = JsonElement.parseJson("false");
|
|
Assert.assertEquals((Boolean) false, je.getRepresentation());
|
|
}
|
|
}
|