### Question:
ZxingPngQrGenerator implements QrGenerator { @Override public byte[] generate(QrData data) throws QrGenerationException { try { BitMatrix bitMatrix = writer.encode(data.getUri(), BarcodeFormat.QR_CODE, imageSize, imageSize); ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream(); MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOutputStream); return pngOutputStream.toByteArray(); } catch (Exception e) { throw new QrGenerationException("Failed to generate QR code. See nested exception.", e); } } ZxingPngQrGenerator();  ZxingPngQrGenerator(Writer writer); void setImageSize(int imageSize); int getImageSize(); String getImageMimeType(); @Override byte[] generate(QrData data);  }### Answer:
@Test public void testSomething() throws QrGenerationException, IOException { ZxingPngQrGenerator generator = new ZxingPngQrGenerator(); QrData data = new QrData.Builder() .label("example@example.com") .secret("EX47GINFPBK5GNLYLILGD2H6ZLGJNNWB") .issuer("AppName") .digits(6) .period(30) .build(); writeFile(generator.generate(data), "./test_qr.png"); }
@Test public void testExceptionIsWrapped() throws WriterException { Throwable exception = new RuntimeException(); Writer writer = mock(Writer.class); when(writer.encode(anyString(), any(), anyInt(), anyInt())).thenThrow(exception); ZxingPngQrGenerator generator = new ZxingPngQrGenerator(writer); QrGenerationException e = assertThrows(QrGenerationException.class, () -> { generator.generate(getData()); }); assertEquals("Failed to generate QR code. See nested exception.", e.getMessage()); assertEquals(exception, e.getCause()); }