use of java.util.Collections.emptyMap in project elasticsearch by elastic.
the class BaseXContentTestCase method testMap.
public void testMap() throws Exception {
Map<String, Map<String, ?>> maps = new HashMap<>();
maps.put("{'map':null}", (Map) null);
maps.put("{'map':{}}", Collections.emptyMap());
maps.put("{'map':{'key':'value'}}", singletonMap("key", "value"));
Map<String, Object> innerMap = new HashMap<>();
innerMap.put("string", "value");
innerMap.put("int", 42);
innerMap.put("long", 42L);
innerMap.put("long[]", new long[] { 1L, 3L });
innerMap.put("path", PathUtils.get("path", "to", "file"));
innerMap.put("object", singletonMap("key", "value"));
final String path = Constants.WINDOWS ? "path\\\\to\\\\file" : "path/to/file";
maps.put("{'map':{'path':'" + path + "','string':'value','long[]':[1,3],'int':42,'long':42,'object':{'key':'value'}}}", innerMap);
for (Map.Entry<String, Map<String, ?>> m : maps.entrySet()) {
final String expected = m.getKey();
assertResult(expected, () -> builder().startObject().field("map", m.getValue()).endObject());
assertResult(expected, () -> builder().startObject().field("map").value(m.getValue()).endObject());
assertResult(expected, () -> builder().startObject().field("map").map(m.getValue()).endObject());
}
}
Aggregations