### Question:
TwitterAdapterFactory implements AdapterFactory { @VisibleForTesting Twitter getInstance() { return factory.getInstance(); } TwitterAdapterFactory(String httpProxyHost, int httpProxyPort, boolean useSsl); @VisibleForTesting  TwitterAdapterFactory(); @SuppressWarnings("unchecked") @Override AdapterType getAdapter(Object adaptable, Class<AdapterType> type);  }### Answer:
@Test public void activateWithoutProxy() throws Exception { TwitterAdapterFactoryRegisterer registerer = new TwitterAdapterFactoryRegisterer(); registerer.activate(bundleContext, Collections.emptyMap()); TwitterAdapterFactory adapterFactory = registeredFactory; TwitterFactory factory = (TwitterFactory) PrivateAccessor.getField(adapterFactory, "factory"); Twitter twitter = factory.getInstance(); Configuration configuration = (Configuration) PrivateAccessor.getField(twitter, "conf"); assertEquals(-1, configuration.getHttpProxyPort()); assertNull(configuration.getHttpProxyHost()); }
@Test public void activateWithProxyPortWithoutHost() throws Exception { TwitterAdapterFactoryRegisterer registerer = new TwitterAdapterFactoryRegisterer(); registerer.activate(bundleContext, Collections.singletonMap("http.proxy.port", 8080)); TwitterAdapterFactory adapterFactory = registeredFactory; TwitterFactory factory = (TwitterFactory) PrivateAccessor.getField(adapterFactory, "factory"); Twitter twitter = factory.getInstance(); Configuration configuration = (Configuration) PrivateAccessor.getField(twitter, "conf"); assertEquals(-1, configuration.getHttpProxyPort()); assertNull(configuration.getHttpProxyHost()); }
@Test public void activateWithProxyHostWithoutPort() throws Exception { TwitterAdapterFactoryRegisterer registerer = new TwitterAdapterFactoryRegisterer(); registerer.activate(bundleContext, Collections.singletonMap("http.proxy.host", "myproxy")); TwitterAdapterFactory adapterFactory = registeredFactory; TwitterFactory factory = (TwitterFactory) PrivateAccessor.getField(adapterFactory, "factory"); Twitter twitter = factory.getInstance(); Configuration configuration = (Configuration) PrivateAccessor.getField(twitter, "conf"); assertEquals(-1, configuration.getHttpProxyPort()); assertNull(configuration.getHttpProxyHost()); }
@Test public void activateWithProxy() throws Exception { TwitterAdapterFactoryRegisterer registerer = new TwitterAdapterFactoryRegisterer(); Map<String, Object> config = new HashMap<>(); config.put("http.proxy.host", "myproxy"); config.put("http.proxy.port", 8080); registerer.activate(bundleContext, config); TwitterAdapterFactory adapterFactory = registeredFactory; TwitterFactory factory = (TwitterFactory) PrivateAccessor.getField(adapterFactory, "factory"); Twitter twitter = factory.getInstance(); Configuration configuration = (Configuration) PrivateAccessor.getField(twitter, "conf"); assertEquals(8080, configuration.getHttpProxyPort()); assertEquals("myproxy", configuration.getHttpProxyHost()); }