package com.jsoniter.output; import com.jsoniter.spi.TypeLiteral; import junit.framework.TestCase; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.HashMap; public class TestMap extends TestCase { static { // JsonStream.setMode(EncodingMode.REFLECTION_MODE); } private ByteArrayOutputStream baos; private JsonStream stream; public void setUp() { baos = new ByteArrayOutputStream(); stream = new JsonStream(baos, 4096); } public void test() throws IOException { HashMap map = new HashMap(); map.put("hello", "world"); stream.writeVal(map); stream.close(); assertEquals("{'hello':'world'}".replace('\'', '"'), baos.toString()); } public void test_empty() throws IOException { HashMap map = new HashMap(); stream.writeVal(map); stream.close(); assertEquals("{}".replace('\'', '"'), baos.toString()); } public void test_null() throws IOException { stream.writeVal(new TypeLiteral(){}, null); stream.close(); assertEquals("null".replace('\'', '"'), baos.toString()); } }