RollbarFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { String accessToken = filterConfig.getInitParameter(ACCESS_TOKEN_PARAM_NAME); String userIpHeaderName = filterConfig.getInitParameter(USER_IP_HEADER_PARAM_NAME); String configProviderClassName = filterConfig.getInitParameter(CONFIG_PROVIDER_CLASS_PARAM_NAME); String captureIp = filterConfig.getInitParameter(CONFIG_IP_CAPTURE_PARAM_NAME); ConfigProvider configProvider = ConfigProviderHelper.getConfigProvider(configProviderClassName); Config config; RequestProvider requestProvider = new RequestProvider.Builder() .userIpHeaderName(userIpHeaderName) .captureIp(captureIp) .build(); ConfigBuilder configBuilder = withAccessToken(accessToken) .request(requestProvider) .person(new PersonProvider()); if (configProvider != null) { config = configProvider.provide(configBuilder); } else { config = configBuilder.build(); } rollbar = Rollbar.init(config); } RollbarFilter();  RollbarFilter(Rollbar rollbar); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }
@Test public void shouldInit() throws Exception { sut.init(filterConfig); verify(filterConfig).getInitParameter(ACCESS_TOKEN_PARAM_NAME); verify(filterConfig).getInitParameter(USER_IP_HEADER_PARAM_NAME); verify(filterConfig).getInitParameter(CONFIG_PROVIDER_CLASS_PARAM_NAME); }
@Test public void shouldUseConfigProviderIfAvailable() throws Exception { when(filterConfig.getInitParameter(CONFIG_PROVIDER_CLASS_PARAM_NAME)).thenReturn( FakeConfigProvider.class.getCanonicalName()); sut.init(filterConfig); assertTrue(FakeConfigProvider.CALLED); }
@Test public void shouldNotUseConfigProviderIfError() throws Exception { when(filterConfig.getInitParameter(CONFIG_PROVIDER_CLASS_PARAM_NAME)).thenReturn( "com.rollbar.not.exists"); sut.init(filterConfig); assertFalse(FakeConfigProvider.CALLED); }