Rollbar { public void log(Throwable error) { log(error, null, null, null); } Rollbar(Config config);   Rollbar(Config config, BodyFactory bodyFactory); static Rollbar init(Config config); void handleUncaughtErrors(); void handleUncaughtErrors(Thread thread); void configure(ConfigProvider configProvider); void configure(Config config); Config config(); void critical(Throwable error); void critical(Throwable error, String description); void critical(Throwable error, Map<String, Object> custom); void critical(String message); void critical(String message, Map<String, Object> custom); void critical(Throwable error, Map<String, Object> custom, String description); void error(Throwable error); void error(Throwable error, String description); void error(Throwable error, Map<String, Object> custom); void error(String message); void error(String message, Map<String, Object> custom); void error(Throwable error, Map<String, Object> custom, String description); void warning(Throwable error); void warning(Throwable error, String description); void warning(Throwable error, Map<String, Object> custom); void warning(String message); void warning(String message, Map<String, Object> custom); void warning(Throwable error, Map<String, Object> custom, String description); void info(Throwable error); void info(Throwable error, String description); void info(Throwable error, Map<String, Object> custom); void info(String message); void info(String message, Map<String, Object> custom); void info(Throwable error, Map<String, Object> custom, String description); void debug(Throwable error); void debug(Throwable error, String description); void debug(Throwable error, Map<String, Object> custom); void debug(String message); void debug(String message, Map<String, Object> custom); void debug(Throwable error, Map<String, Object> custom, String description); void log(Throwable error); void log(Throwable error, String description); void log(Throwable error, Map<String, Object> custom); void log(Throwable error, Map<String, Object> custom, Level level); void log(Throwable error, Level level); void log(Throwable error, String description, Level level); void log(Throwable error, Map<String, Object> custom, String description); void log(String message); void log(String message, Map<String, Object> custom); void log(String message, Level level); void log(String message, Map<String, Object> custom, Level level); void log(Throwable error, Map<String, Object> custom, String description, Level level); void log(Throwable error, Map<String, Object> custom, String description, Level level,
      boolean isUncaught); void log(ThrowableWrapper error, Map<String, Object> custom, String description,
                  Level level, boolean isUncaught); Level level(Config config, Throwable error); void close(boolean wait); void sendJsonPayload(String json);  }
@Test public void shouldDoNothingIfDisabled() { Level level = Level.ERROR; Throwable error = new RuntimeException("Something went wrong."); String description = "description"; Map<String, Object> custom = new HashMap<>(); Config config = withConfig(this.config) .enabled(false) .build(); Rollbar sut = new Rollbar(config, bodyFactory); sut.log(error, custom, description, level); verify(contextProvider, never()).provide(); verify(requestProvider, never()).provide(); verify(personProvider, never()).provide(); verify(serverProvider, never()).provide(); verify(clientProvider, never()).provide(); verify(customProvider, never()).provide(); verify(notifierProvider, never()).provide(); verify(timestampProvider, never()).provide(); verify(filter, never()).preProcess(any(), any(), any(), any()); verify(transformer, never()).transform(any()); verify(uuidGenerator, never()).from(any()); verify(fingerprintGenerator, never()).from(any()); verify(filter, never()).postProcess(any()); verify(sender, never()).send(any()); }
@Test public void shouldPrefilterWithoutGatheringData() { Level level = Level.ERROR; Throwable error = new RuntimeException("Something went wrong."); String description = "description"; Map<String, Object> custom = new HashMap<>(); when(filter.preProcess(level, error, custom, description)).thenReturn(true); Rollbar sut = new Rollbar(config, bodyFactory); sut.log(error, custom, description, level); verify(contextProvider, never()).provide(); verify(requestProvider, never()).provide(); verify(personProvider, never()).provide(); verify(serverProvider, never()).provide(); verify(clientProvider, never()).provide(); verify(customProvider, never()).provide(); verify(notifierProvider, never()).provide(); verify(timestampProvider, never()).provide(); verify(filter).preProcess(level, error, custom, description); verify(transformer, never()).transform(any()); verify(uuidGenerator, never()).from(any()); verify(fingerprintGenerator, never()).from(any()); verify(filter, never()).postProcess(any()); verify(sender, never()).send(any()); }
@Test public void shouldPostFilterWithoutSendingPayload() { Level level = Level.ERROR; Throwable error = new RuntimeException("Something went wrong."); String description = "description"; Map<String, Object> custom = new HashMap<>(); when(transformer.transform(any())).thenReturn(mock(Data.class)); when(filter.preProcess(level, error, custom, description)).thenReturn(false); when(filter.postProcess(any())).thenReturn(true); Rollbar sut = new Rollbar(config, bodyFactory); sut.log(error, custom, description, level); verify(sender, never()).send(any()); }
@Test public void shouldUseTransformedData() { Config config = withAccessToken(ACCESS_TOKEN) .transformer(transformer) .sender(sender) .build(); Data transformedData = mock(Data.class); Level level = Level.ERROR; Throwable error = new RuntimeException("Something went wrong."); String description = "description"; Map<String, Object> custom = new HashMap<>(); when(transformer.transform(any())).thenReturn(transformedData); Rollbar sut = new Rollbar(config, bodyFactory); sut.log(error, custom, description, level); Payload expected = new Payload.Builder() .accessToken(ACCESS_TOKEN) .data(transformedData) .build(); verify(sender).send(expected); }
@Test public void shouldFilterPrefilterWithNullException(){ Level level = Level.INFO; String description = "description"; Rollbar sut = new Rollbar(config, bodyFactory); when(filter.preProcess(level, null, null, description)).thenReturn(false); sut.log(null, null, description, level); verify(filter).preProcess(level, null, null, description); }
@Test public void shouldNotThrowExceptionWithEmptyConfig() { Config config = withAccessToken("access_token").build(); Rollbar sut = new Rollbar(config); Throwable error = new RuntimeException("Something went wrong."); sut.log(error, null, null, Level.ERROR); }
@Test public void shouldNotThrowExceptionIfErrorProcessing() { Config config = withAccessToken("access_token") .transformer(new Transformer() { @Override public Data transform(Data data) { throw new RuntimeException("Unexpected error."); } }) .build(); Rollbar sut = new Rollbar(config); Throwable error = new RuntimeException("Something went wrong."); sut.log(error, null, null, Level.ERROR); }