/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.juniform; import org.junit.Assert; import org.junit.Test; /** * * @author acherkashin */ public class JUniformMutableObjectTest { @Test public void testValue() { JUniformMutableObject object = new JUniformMutableObject(1); Assert.assertTrue(1 == object.toInteger()); object.setValue(2); Assert.assertTrue(2 == object.toInteger()); } @Test public void testCreateMap() { JUniformMutableObject object = JUniformMutableObject.newMap(); object.setProperty("hahaha", 512.33f); Assert.assertEquals(512.33f, object.getProperty("hahaha").toFloat(), 0.00001); } @Test public void testCreate2DimMap() { JUniformMutableObject object = JUniformMutableObject.newMap(); object.setProperty("hahaha", 512.33f); JUniformMutableObject innerObject = JUniformMutableObject.newMap(); innerObject.setProperty("nonono", "lol"); object.setProperty("map", innerObject); Assert.assertEquals("lol", object.getProperty("map").getProperty("nonono").toString()); } @Test public void testCreate2DimMapToJSON() { JUniformMutableObject innerObject = JUniformMutableObject.newMap(); innerObject.setProperty("nonono", "lol"); JUniformMutableObject object = JUniformMutableObject.newMap(); object.setProperty("map", innerObject); String json = JUniform.getPackerInstance(JUniform.PACKER_TYPE_JSON).fromUniformObjectToString(object); Assert.assertEquals("{\"map\":{\"nonono\":\"lol\"}}", json); } @Test public void testCreate2DimMapWithArray() { JUniformMutableObject innerArray = JUniformMutableObject.newArray(); innerArray.addElement(123); innerArray.addElement("test"); JUniformMutableObject innerObject = JUniformMutableObject.newMap(); innerObject.setProperty("nonono", innerArray); JUniformMutableObject object = JUniformMutableObject.newMap(); object.setProperty("map", innerObject); String json = JUniform.getPackerInstance(JUniform.PACKER_TYPE_JSON).fromUniformObjectToString(object); Assert.assertEquals("{\"map\":{\"nonono\":[123,\"test\"]}}", json); } }