### Question:
MetricsConf { @Bean MetricSender metricSender(ValidatedGraphite validatedGraphite) { if (validatedGraphite.isEnabled()) { return GraphiteMetricSender.newInstance(validatedGraphite.getHost(), validatedGraphite.getFormattedPrefix()); } return MetricSender.DEFAULT_LOG_ONLY; }    }### Answer:
@Test public void graphiteMetricSender() { when(validatedGraphite.getHost()).thenReturn("localhost:123"); when(validatedGraphite.getFormattedPrefix()).thenReturn("prefix.namespace"); when(validatedGraphite.isEnabled()).thenReturn(true); MetricSender sender = new MetricsConf().metricSender(validatedGraphite); assertTrue(sender instanceof GraphiteMetricSender); }
@Test public void defaultMetricSender() { when(validatedGraphite.isEnabled()).thenReturn(false); MetricSender sender = new MetricsConf().metricSender(validatedGraphite); assertTrue(sender == MetricSender.DEFAULT_LOG_ONLY); }