@Test
public void testgetAmbariServerURI() throws Exception {

  // create mocks
  Injector injector = createStrictMock(Injector.class);
  Capture<AmbariManagementController> controllerCapture = EasyMock.newCapture();
  // set expectations
  injector.injectMembers(capture(controllerCapture));
  expect(injector.getInstance(Gson.class)).andReturn(null);
  expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
  expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class));
  //replay
  replay(injector);
  AmbariManagementControllerImpl controller = new AmbariManagementControllerImpl(null, null, injector);
  class AmbariConfigsSetter {
    public void setConfigs(AmbariManagementController controller, String masterProtocol, String masterHostname, Integer masterPort) throws Exception {
      // masterProtocol
      Class<?> c = controller.getClass();
      Field f = c.getDeclaredField("masterProtocol");
      f.setAccessible(true);
      Field modifiersField = Field.class.getDeclaredField("modifiers");
      modifiersField.setAccessible(true);
      modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
      f.set(controller, masterProtocol);
      // masterHostname
      f = c.getDeclaredField("masterHostname");
      f.setAccessible(true);
      modifiersField = Field.class.getDeclaredField("modifiers");
      modifiersField.setAccessible(true);
      modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
      f.set(controller, masterHostname);
      // masterPort
      f = c.getDeclaredField("masterPort");
      f.setAccessible(true);
      modifiersField = Field.class.getDeclaredField("modifiers");
      modifiersField.setAccessible(true);
      modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
      f.set(controller, masterPort);
    }
  }
  AmbariConfigsSetter ambariConfigsSetter = new AmbariConfigsSetter();
  ambariConfigsSetter.setConfigs(controller, "http", "hostname", 8080);
  assertEquals("http://hostname:8080/jdk_path", controller.getAmbariServerURI("/jdk_path"));
  ambariConfigsSetter.setConfigs(controller, "https", "somesecuredhost", 8443);
  assertEquals("https://somesecuredhost:8443/mysql_path", controller.getAmbariServerURI("/mysql_path"));
  ambariConfigsSetter.setConfigs(controller, "https", "othersecuredhost", 8443);
  assertEquals("https://othersecuredhost:8443/oracle/ojdbc/", controller.getAmbariServerURI("/oracle/ojdbc/"));
  ambariConfigsSetter.setConfigs(controller, "http", "hostname", 8080);
  assertEquals("http://hostname:8080/jdk_path?query", controller.getAmbariServerURI("/jdk_path?query"));
  verify(injector);
}