@Test
  public void testSimpleCallback() {
    final AtomicBoolean flag = new AtomicBoolean(false);

    DefaultRavenFactory factory =
        new DefaultRavenFactory() {
          @Override
          protected Connection createConnection(Dsn dsn) {
            Connection connection = super.createConnection(dsn);

            connection.addEventSendFailureCallback(
                new EventSendFailureCallback() {
                  @Override
                  public void onFailure(Event event, Exception exception) {
                    flag.set(true);
                  }
                });

            return connection;
          }
        };

    String dsn = "https://*****:*****@localhost:1234/1?raven.async=false";
    Raven raven = factory.createRavenInstance(new Dsn(dsn));
    raven.sendMessage("Message that will fail because DSN points to garbage.");

    assertThat(flag.get(), is(true));
  }
 public void error(Class klass, String message) {
   EventBuilder eventBuilder =
       new EventBuilder()
           .withMessage(message)
           .withLevel(Event.Level.ERROR)
           .withLogger(klass.getName());
   raven.runBuilderHelpers(eventBuilder);
   raven.sendEvent(eventBuilder.build());
 }
 public void error(Class klass, String message, Throwable throwable) {
   EventBuilder eventBuilder =
       new EventBuilder()
           .withMessage(message)
           .withLevel(Event.Level.ERROR)
           .withLogger(klass.getName())
           .withSentryInterface(new ExceptionInterface(throwable));
   raven.runBuilderHelpers(eventBuilder);
   raven.sendEvent(eventBuilder.build());
 }
  @Test
  public void testExceptionInsideCallback() {
    DefaultRavenFactory factory =
        new DefaultRavenFactory() {
          @Override
          protected Connection createConnection(Dsn dsn) {
            Connection connection = super.createConnection(dsn);

            connection.addEventSendFailureCallback(
                new EventSendFailureCallback() {
                  @Override
                  public void onFailure(Event event, Exception exception) {
                    throw new RuntimeException("Error inside of EventSendFailureCallback");
                  }
                });

            return connection;
          }
        };

    String dsn = "https://*****:*****@localhost:1234/1?raven.async=false";
    Raven raven = factory.createRavenInstance(new Dsn(dsn));
    raven.sendMessage("Message that will fail because DSN points to garbage.");
  }