Printer { public Printer spaces(int n) { while(n > 0) { int c = Math.min(n, SPACES.length); printWriter.write(SPACES, 0, c); persistentPrintWriter.write(SPACES, 0, c); n -= c; } return this; } Printer(Writer writer); static Printer createStdOutPrinter(); Writer getWriter(); void pushWriter(Writer writer); PrintWriter asPrintWriter(); Writer popWriter(); void addPersistentWriter(Writer writer); void removePersistentWriter(Writer writer); Printer print(String output); Printer print(String format, Object ... args); Formatter asFormatter(); Printer startNewLine(); Printer flush(); Printer warn(String message); Printer warn(String format, Object ... args); boolean isPrintWarnings(); Printer setPrintWarnings(boolean printWarnings); Printer error(String message); Printer error(String format, Object ... args); Printer spaces(int n); List<String> getWarningsAndClear();  }
@Test public void testSpaces() { StringWriter first = new StringWriter(); Printer printer = new Printer(first); printer.spaces(500); String result = first.toString(); char[] spaceArray = new char[500]; Arrays.fill(spaceArray, ' '); assertEquals(new String(spaceArray), result); }