### Question:
OverriddenMetricsHostProvider implements MetricHostProvider { @Override public Optional<String> getExternalHostName(String clusterName, String componentName) { return getOverriddenHost(componentName).map(host -> replaceVariables(clusterName, host)); } OverriddenMetricsHostProvider(Map<String, String> overriddenHosts, MetricHostProvider metricHostProvider, ConfigHelper configHelper); @Override Optional<String> getExternalHostName(String clusterName, String componentName); @Override boolean isCollectorHostExternal(String clusterName); @Override String getHostName(String clusterName, String componentName); @Override String getCollectorHostName(String clusterName, MetricsServiceProvider.MetricsService service); @Override String getCollectorPort(String clusterName, MetricsServiceProvider.MetricsService service); @Override boolean isCollectorHostLive(String clusterName, MetricsServiceProvider.MetricsService service); @Override boolean isCollectorComponentLive(String clusterName, MetricsServiceProvider.MetricsService service);  }### Answer:
@Test public void testReturnsDefaultWhenNotOverridden() throws Exception { replayAll(); assertThat(hostProvider.getExternalHostName(CLUSTER_1, COMPONENT_WITHOUT_OVERRIDDEN_HOST), is(Optional.empty())); verifyAll(); }
@Test public void testReturnOverriddenHostIfPresent() throws Exception { expect(configHelper.getEffectiveConfigProperties(CLUSTER_1, null)).andReturn(emptyMap()).anyTimes(); replayAll(); assertThat(hostProvider.getExternalHostName(CLUSTER_1, COMPONENT_WITH_OVERRIDDEN_HOST), is(Optional.of(OVERRIDEN_HOST))); verifyAll(); }