Skip to content

Instantly share code, notes, and snippets.

@eishay
Created October 4, 2011 22:51
Show Gist options
  • Save eishay/1263088 to your computer and use it in GitHub Desktop.
Save eishay/1263088 to your computer and use it in GitHub Desktop.
Test Guice can init all bounded servlets
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.inject.Binding;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceFilter;
...
public static void assertInit(Injector injector) {
GuiceFilter filter = injector.getInstance(GuiceFilter.class);
FilterConfig filterConfig = mock(FilterConfig.class);
ServletContext context = mock(ServletContext.class);
when(filterConfig.getServletContext()).thenReturn(context);
try {
filter.init(filterConfig);
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment