1 /** 2 * Copyright (C) 2013 The Android Open Source Project 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 */ 16 17 package com.android.internal.util; 18 19 import java.io.ByteArrayInputStream; 20 import java.io.ByteArrayOutputStream; 21 import java.io.InputStream; 22 import java.util.HashMap; 23 import java.util.Map; 24 import junit.framework.TestCase; 25 26 public class XmlUtilsTest extends TestCase { 27 28 // https://code.google.com/p/android/issues/detail?id=63717 29 public void testMapWithNullKeys() throws Exception { 30 ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); 31 Map<String, Object> map = new HashMap<String, Object>(); 32 map.put(null, "nullValue"); 33 map.put("foo", "fooValue"); 34 XmlUtils.writeMapXml(map, baos); 35 36 InputStream mapInput = new ByteArrayInputStream(baos.toByteArray()); 37 HashMap<String, ?> deserialized = XmlUtils.readMapXml(mapInput); 38 assertEquals("nullValue", deserialized.get(null)); 39 assertEquals("fooValue", deserialized.get("foo")); 40 } 41 } 42