@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { when(locator.getService(eq(GuiceIntoHK2Bridge.class))).thenReturn(bridge); when(locator.getService(eq(DynamicConfigurationService.class))).thenReturn(dcs); when(dcs.createDynamicConfiguration()).thenReturn(dc); Key<Set<ContainerRequestFilter>> key = Key.get(new TypeLiteral<Set<ContainerRequestFilter>>() { }); Set<ContainerRequestFilter> set = new LinkedHashSet<>(); set.add(mock(ContainerRequestFilter.class)); when(injector.getInstance(Matchers.any(key.getClass()))).thenReturn(set); server = new GuiceJerseyServer(handler, container, () -> options, locator, injector); }