Report { public static void report(Writer out, List<Machine> machines, Robot robot) throws IOException { out.write("FACTORY REPORT\n"); Iterator<Machine> line = machines.iterator(); while (line.hasNext()) { Machine machine = line.next(); out.write("Machine " + machine.name()); if (machine.bin() != null) out.write(" bin=" + machine.bin()); out.write("\n"); } out.write("\n"); out.write("Robot"); if (robot.location() != null) out.write(" location=" + robot.location().name()); if (robot.bin() != null) out.write(" bin=" + robot.bin()); out.write("\n"); out.write("========\n"); }  static void report(Writer out, List<Machine> machines, Robot robot);  }
@Test public void testReport() throws IOException { ArrayList<Machine> line = new ArrayList<Machine>(); line.add(new Machine("mixer", "left")); Machine extruder = new Machine("extruder", "center"); extruder.put("paste"); line.add(extruder); Machine oven = new Machine("oven", "right"); oven.put("chips"); line.add(oven); Robot robot = new Robot(); robot.moveTo(extruder); robot.pick(); StringWriter out = new StringWriter(); Report.report(out, line, robot); String expected = "FACTORY REPORT\n" + "Machine mixer\nMachine extruder\n" + "Machine oven bin=chips\n\n" + "Robot location=extruder bin=paste\n" + "========\n"; assertEquals(expected, out.toString()); }