### Question:
WordCloud { public void writeToStreamAsPNG(final OutputStream outputStream) { writeToStream("png", outputStream); } WordCloud(final Dimension dimension, final CollisionMode collisionMode); void build(final List<WordFrequency> wordFrequencies); void writeToFile(final String outputFileName); void writeToStreamAsPNG(final OutputStream outputStream); void writeToStream(final String format, final OutputStream outputStream); void setBackgroundColor(final Color backgroundColor); void setPadding(final int padding); void setColorPalette(final ColorPalette colorPalette); void setBackground(final Background background); void setFontScalar(final FontScalar fontScalar); void setKumoFont(final KumoFont kumoFont); void setAngleGenerator(final AngleGenerator angleGenerator); BufferedImage getBufferedImage(); Set<Word> getSkipped(); void setWordStartStrategy(final WordStartStrategy wordStartStrategy); void setWordPlacer(final RectangleWordPlacer wordPlacer);  }### Answer:
@Test public void testWriteToStreamAsPNG() throws IOException { final Dimension dimension = new Dimension(200, 200); final WordCloud wordCloud = new WordCloud(dimension, CollisionMode.PIXEL_PERFECT); wordCloud.build(WORD_FREQUENCIES); wordCloud.setPadding(2); wordCloud.setBackground(new RectangleBackground(dimension)); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); wordCloud.writeToStreamAsPNG(byteArrayOutputStream); final byte[] bytes = byteArrayOutputStream.toByteArray(); assertNotEquals(0, bytes.length); final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); final ImageInputStream imageInputStream = ImageIO.createImageInputStream(byteArrayInputStream); final Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream); assertTrue(imageReaders.hasNext()); final ImageReader imageReader = imageReaders.next(); assertEquals("png", imageReader.getFormatName()); }