### Question:
ThrowableSerializer implements JsonSerializer<Throwable> { @Override public JsonElement serialize(final Throwable src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonPrimitive(StringUtils.EMPTY); } JsonObject obj = new JsonObject(); StringWriter sw = new StringWriter(); src.printStackTrace(new PrintWriter(sw)); obj.addProperty("stackTrace", sw.toString()); obj.addProperty("detailMessage", src.getMessage()); if (SakuliExceptionWithScreenshot.class.isAssignableFrom(src.getClass())) { obj.add("screenshot", context.serialize(((SakuliExceptionWithScreenshot)src).getScreenshot(), Path.class)); } return obj; }  @Override JsonElement serialize(final Throwable src, final Type typeOfSrc, final JsonSerializationContext context);  }### Answer:
@Test(dataProvider = "serializeDP") public void serialize(Throwable throwable, String regexForExpectedOutput, boolean exceptionWithScreenshot) { assertTrue(testling.serialize(throwable, Throwable.class, jsonSerializationContext).toString().matches(regexForExpectedOutput)); verify(jsonSerializationContext, times(exceptionWithScreenshot ? 1 : 0)).serialize(any(), eq(Path.class)); }