JongoUtils { public static String generateQuery(final Map<String,Object> params){ final StringBuilder sb = new StringBuilder(); boolean newEntry = false; sb.append("{"); for(final Entry<String,Object> param: params.entrySet()){ if(newEntry){ sb.append(", "); } sb.append(param.getKey()); sb.append(": "); sb.append(getParam(param.getValue())); newEntry = true; } sb.append("}"); return sb.toString(); } private  JongoUtils(); static String generateQuery(final Map<String,Object> params); static String generateQuery(final String key, final Object value);  }
@Test public void generateJongoQuery(){ Map<String, Object> params = new HashMap<String, Object>(); params.put("key2", "value2"); params.put("key1", "value1"); Map<String, Object> sortParams = new TreeMap<String, Object>(params); assertEquals("{}", JongoUtils.generateQuery(new HashMap<String, Object>())); assertEquals("{key1: 'value1'}", JongoUtils.generateQuery("key1", "value1")); assertEquals("{key1: 1}", JongoUtils.generateQuery("key1", 1)); assertEquals("{key1: true}", JongoUtils.generateQuery("key1", true)); assertEquals("{key1: 'value1', key2: 'value2'}",JongoUtils.generateQuery(sortParams)); }