### Question:
GraphiteValidator { public ValidatedGraphite validate(Graphite graphite) { if (graphite == null) { graphite = new Graphite(); } Graphite validated = loader.load(graphite.getConfig()); if (graphite.getHost() != null) { validated.setHost(graphite.getHost()); } if (graphite.getPrefix() != null) { validated.setPrefix(graphite.getPrefix()); } if (graphite.getNamespace() != null) { validated.setNamespace(graphite.getNamespace()); } validated.init(); if (validated.isEnabled()) { if (validated.getHost() == null || validated.getPrefix() == null || validated.getNamespace() == null) { throw new CircusTrainException( String.format("Missing graphite configuration property: host[%s], prefix[%s], namespace[%s]", validated.getHost(), validated.getPrefix(), validated.getNamespace())); } } return new ValidatedGraphite(validated); } GraphiteValidator(Configuration conf);   GraphiteValidator(GraphiteLoader loader); ValidatedGraphite validate(Graphite graphite);  }### Answer:
@Test public void nullGraphite() { ValidatedGraphite validated = validator.validate(null); assertThat(validated.isEnabled(), is(false)); }
@Test public void disabledGraphite() { input.init(); ValidatedGraphite validated = validator.validate(input); assertThat(validated.isEnabled(), is(false)); }
@Test public void enabledConfigOnly() { input.setConfig(new Path(".")); input.init(); ValidatedGraphite validated = validator.validate(input); assertThat(validated.isEnabled(), is(false)); }
@Test(expected = CircusTrainException.class) public void enabledNoHost() { input.setPrefix("prefix"); input.setNamespace("namespace"); input.init(); validator.validate(input); }
@Test(expected = CircusTrainException.class) public void enabledNoPrefix() { input.setHost("host"); input.setNamespace("namespace"); input.init(); validator.validate(input); }
@Test(expected = CircusTrainException.class) public void enabledNoNamespace() { input.setHost("host"); input.setPrefix("prefix"); input.init(); validator.validate(input); }
@Test public void enabledHostPrefixAndNamespace() { input.setHost("host"); input.setPrefix("prefix"); input.setNamespace("namespace"); input.init(); ValidatedGraphite validated = validator.validate(input); assertThat(validated.isEnabled(), is(true)); assertThat(validated.getHost(), is("host")); assertThat(validated.getFormattedPrefix(), is("prefix.namespace")); }
@Test public void enabledHostPrefixAndNamespaceFromConfigFile() { loaded.setHost("hostx"); loaded.setPrefix("prefixx"); loaded.setNamespace("namespacex"); loaded.init(); ValidatedGraphite validated = validator.validate(input); assertThat(validated.isEnabled(), is(true)); assertThat(validated.getHost(), is("hostx")); assertThat(validated.getFormattedPrefix(), is("prefixx.namespacex")); }
@Test public void enabledHostPrefixAndNamespaceFromConfigFileWithOverride() { loaded.setHost("hostx"); loaded.setPrefix("prefixx"); loaded.setNamespace("namespacex"); loaded.init(); input.setHost("host"); input.setPrefix("prefix"); input.setNamespace("namespace"); input.init(); ValidatedGraphite validated = validator.validate(input); assertThat(validated.isEnabled(), is(true)); assertThat(validated.getHost(), is("host")); assertThat(validated.getFormattedPrefix(), is("prefix.namespace")); }