### Question:
ListenerConfigUtil { public static List<ListenerConfig> buildListenerConfigs(ControllerConf controllerConf) { List<ListenerConfig> listenerConfigs = new ArrayList<>(); if (controllerConf.getControllerPort() != null) { listenerConfigs.add( new ListenerConfig("http", "0.0.0.0", Integer.valueOf(controllerConf.getControllerPort()), "http", null)); } listenerConfigs.addAll(controllerConf.getControllerAccessProtocols().stream() .map(protocol -> buildListenerConfig(protocol, controllerConf)) .collect(Collectors.toList())); return listenerConfigs; }  static List<ListenerConfig> buildListenerConfigs(ControllerConf controllerConf);  }### Answer:
@Test public void assertControllerPortConfig() { ControllerConf controllerConf = new ControllerConf(); controllerConf.setProperty("controller.port", "9000"); controllerConf.setProperty("controller.query.console.useHttps", "true"); List<ListenerConfig> listenerConfigs = ListenerConfigUtil.buildListenerConfigs(controllerConf); Assert.assertEquals(listenerConfigs.size(), 1); assertLegacyListener(listenerConfigs.get(0)); }
@Test public void assertLegacyAndHttps() { ControllerConf controllerConf = new ControllerConf(); controllerConf.setProperty("controller.port", "9000"); controllerConf.setProperty("controller.access.protocols", "https"); configureHttpsProperties(controllerConf, "10.0.0.10", 9443); List<ListenerConfig> listenerConfigs = ListenerConfigUtil.buildListenerConfigs(controllerConf); Assert.assertEquals(listenerConfigs.size(), 2); ListenerConfig legacyListener = getListener("http", listenerConfigs); ListenerConfig httpsListener = getListener("https", listenerConfigs); assertLegacyListener(legacyListener); assertHttpsListener(httpsListener, "10.0.0.10", 9443); }
@Test public void assertHttpsOnly() { ControllerConf controllerConf = new ControllerConf(); controllerConf.setProperty("controller.access.protocols", "https"); configureHttpsProperties(controllerConf, 9443); List<ListenerConfig> listenerConfigs = ListenerConfigUtil.buildListenerConfigs(controllerConf); Assert.assertEquals(listenerConfigs.size(), 1); assertHttpsListener(listenerConfigs.get(0), "0.0.0.0", 9443); }
@Test(expectedExceptions = IllegalArgumentException.class) public void assertInvalidHost() { ControllerConf controllerConf = new ControllerConf(); controllerConf.setProperty("controller.access.protocols", "https"); configureHttpsProperties(controllerConf, "", 9443); ListenerConfigUtil.buildListenerConfigs(controllerConf); }
@Test(expectedExceptions = IllegalArgumentException.class) public void assertInvalidPort() { ControllerConf controllerConf = new ControllerConf(); controllerConf.setProperty("controller.access.protocols", "https"); configureHttpsProperties(controllerConf, "", 9443); controllerConf.setProperty("controller.access.protocol.https.port", "10.10"); ListenerConfigUtil.buildListenerConfigs(controllerConf); }
@Test(expectedExceptions = IllegalArgumentException.class) public void assertEmptyHttpPort() { ControllerConf controllerConf = new ControllerConf(); controllerConf.setProperty("controller.access.protocols", "http"); controllerConf.setProperty("controller.access.protocols.http.port", ""); ListenerConfigUtil.buildListenerConfigs(controllerConf); }
@Test(expectedExceptions = IllegalArgumentException.class) public void assertEmptyHttpsPort() { ControllerConf controllerConf = new ControllerConf(); controllerConf.setProperty("controller.access.protocols", "https"); controllerConf.setProperty("controller.access.protocols.https.port", ""); ListenerConfigUtil.buildListenerConfigs(controllerConf); }