@Test void testprint() { ShapeFactory factory = new ShapeFactory(); Shape triangle = null; Shape square = null; try { triangle = factory.create("triangle", 3); square = factory.create("square", 2); } catch (Exception e) { fail("create failed"); } PrintStream oldOut = System.out; ByteArrayOutputStream outContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent)); triangle.print(); String expectedTriangle = "*\r\n**\r\n***"; assertEquals(expectedTriangle, outContent.toString().trim()); outContent.reset(); square.print(); String expectedSquare = "**\r\n**"; assertEquals(expectedSquare, outContent.toString().trim()); outContent.reset(); System.setOut(oldOut); }
public abstract void print();
Shape { public abstract void print(); }
Shape { public abstract void print(); Shape(int size); }
Shape { public abstract void print(); Shape(int size); abstract void print(); abstract int charNeeded(); }
Shape { public abstract void print(); Shape(int size); abstract void print(); abstract int charNeeded();  }