public void testDebugPrintNullLabelAndMap() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); outPrint.println("null"); final String EXPECTED_OUT = out.toString(); out.reset(); MapUtils.debugPrint(outPrint, null, null); assertEquals(EXPECTED_OUT, out.toString()); }
public void testDebugPrintNullStream() { try { MapUtils.debugPrint(null, "Map", new HashMap()); fail("Should generate NullPointerException"); } catch (NullPointerException expected) { } }
public void testDebugAndVerbosePrintCasting() { final Map inner = new HashMap(2, 1); inner.put( new Integer(2) , "B" ); inner.put( new Integer(3) , "C" ); final Map outer = new HashMap(2, 1); outer.put( new Integer(0) , inner ); outer.put( new Integer(1) , "A"); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); try { MapUtils.debugPrint(outPrint, "Print Map", outer); } catch (final ClassCastException e) { fail("No Casting should be occurring!"); } }
public void testDebugPrintNullKey() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); final String INDENT = " "; final Map map = new HashMap(); map.put( null , "A" ); outPrint.println("{"); outPrint.println(INDENT + "null = A " + String.class.getName()); outPrint.println("} " + HashMap.class.getName()); final String EXPECTED_OUT = out.toString(); out.reset(); MapUtils.debugPrint(outPrint, null, map); assertEquals(EXPECTED_OUT, out.toString()); }
public void testDebugPrintNullKeyToMap1() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); final String INDENT = " "; final Map map = new HashMap(); map.put( null , map ); outPrint.println("{"); outPrint.println(INDENT + "null = (this Map) " + HashMap.class.getName()); outPrint.println("} " + HashMap.class.getName()); final String EXPECTED_OUT = out.toString(); out.reset(); MapUtils.debugPrint(outPrint, null, map); assertEquals(EXPECTED_OUT, out.toString()); }
public void testDebugPrintNullKeyToMap2() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); final String INDENT = " "; final Map map = new HashMap(); final Map map2= new HashMap(); map.put( null , map2 ); map2.put( "2", "B" ); outPrint.println("{"); outPrint.println(INDENT + "null = "); outPrint.println(INDENT + "{"); outPrint.println(INDENT + INDENT + "2 = B " + String.class.getName()); outPrint.println(INDENT + "} " + HashMap.class.getName()); outPrint.println("} " + HashMap.class.getName()); final String EXPECTED_OUT = out.toString(); out.reset(); MapUtils.debugPrint(outPrint, null, map); assertEquals(EXPECTED_OUT, out.toString()); }
public void testDebugPrintNullLabel() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); final String INDENT = " "; final Map map = new TreeMap(); // treeMap guarantees order across JDKs for test map.put( new Integer(2) , "B" ); map.put( new Integer(3) , "C" ); map.put( new Integer(4) , null ); outPrint.println("{"); outPrint.println(INDENT + "2 = B " + String.class.getName()); outPrint.println(INDENT + "3 = C " + String.class.getName()); outPrint.println(INDENT + "4 = null"); outPrint.println("} " + TreeMap.class.getName()); final String EXPECTED_OUT = out.toString(); out.reset(); MapUtils.debugPrint(outPrint, null, map); assertEquals(EXPECTED_OUT, out.toString()); }
public void testDebugAndVerbosePrintNullMap() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); final String LABEL = "Print Map"; outPrint.println(LABEL + " = " + String.valueOf((Object) null)); final String EXPECTED_OUT = out.toString(); out.reset(); MapUtils.debugPrint(outPrint, LABEL, null); assertEquals(EXPECTED_OUT, out.toString()); out.reset(); MapUtils.verbosePrint(outPrint, LABEL, null); assertEquals(EXPECTED_OUT, out.toString()); }
public void testDebugPrint() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); final String LABEL = "Print Map"; final String INDENT = " "; outPrint.println(LABEL + " = "); outPrint.println("{"); outPrint.println(INDENT + "0 = A " + String.class.getName()); outPrint.println(INDENT + "1 = "); outPrint.println(INDENT + "{"); outPrint.println(INDENT + INDENT + "2 = B " + String.class.getName()); outPrint.println(INDENT + INDENT + "3 = C " + String.class.getName()); outPrint.println(INDENT + "} " + TreeMap.class.getName()); outPrint.println(INDENT + "7 = (this Map) " + TreeMap.class.getName()); outPrint.println("} " + TreeMap.class.getName()); final String EXPECTED_OUT = out.toString(); out.reset(); final Map inner = new TreeMap(); // treeMap guarantees order across JDKs for test inner.put( new Integer(2) , "B" ); inner.put( new Integer(3) , "C" ); final Map outer = new TreeMap(); outer.put( new Integer(1) , inner ); outer.put( new Integer(0) , "A"); outer.put( new Integer(7) , outer); MapUtils.debugPrint(outPrint, "Print Map", outer); assertEquals(EXPECTED_OUT, out.toString()); }
MapUtils.debugPrint(outPrint, "Print Map", grandfather);
protected Document findUpdatedDoc(Map<String, Object> message0, String guid, String sensorType) throws InterruptedException, IOException, OriginalNotFoundException { for (int t = 0; t < MAX_RETRIES; ++t, Thread.sleep(SLEEP_MS)) { Document doc = getDao().getLatest(guid, sensorType); if (doc != null && message0.equals(doc.getDocument())) { return doc; } if (t == MAX_RETRIES -1) { MapUtils.debugPrint(System.out, "Expected", message0); MapUtils.debugPrint(System.out, "actual", doc.getDocument()); } } throw new OriginalNotFoundException("Count not find " + guid + " after " + MAX_RETRIES + " tries"); }
/** * Returns the provided {@link Map} as a pretty string, using the system dependent new like character as the * key-value pair separator, and ' -> ' as the individual key and value separator. * * @param map the {@link Map} to be converted to a string * @return a pretty {@link String} representation of the {@link Map} */ public static String getMapAsPrettyString( final Map map ) { final ByteArrayOutputStream writtenBytes = new ByteArrayOutputStream(); MapUtils.debugPrint( new PrintStream( writtenBytes ), "Map", map ); return writtenBytes.toString(); }
@Override @SuppressWarnings("hiding") public void initialize(LocalPackage pkg, boolean restart) throws PackageException { this.pkg = pkg; this.restart = restart; env.put(PKG_ID, pkg.getId()); env.put(PKG_NAME, pkg.getName()); env.put(PKG_VERSION, pkg.getVersion().toString()); env.put(PKG_ROOT, pkg.getData().getRoot().getAbsolutePath()); if (log.isDebugEnabled()) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream outPrint = new PrintStream(out); MapUtils.debugPrint(outPrint, null, env); log.debug(out.toString()); } }
@SuppressWarnings("rawtypes") public static void debugPrint(ActionContext actionContext){ Thing self = actionContext.getObject("self"); Map map = (Map) self.doAction("getMap", actionContext); String label = (String) self.doAction("getLabel", actionContext); PrintStream out = (PrintStream) self.doAction("getOut", actionContext); MapUtils.debugPrint(out, label, map); }