### Question:
GraphiteLoader { Graphite load(Path path) { Graphite graphite = new Graphite(); if (path != null) { graphite.setConfig(path); Properties properties = loadProperties(path); graphite.setHost(properties.getProperty("graphite.host")); graphite.setPrefix(properties.getProperty("graphite.prefix")); graphite.setNamespace(properties.getProperty("graphite.namespace")); } return graphite; } GraphiteLoader(Configuration conf);   }### Answer:
@Test public void readAllProps() throws IOException { Properties properties = new Properties(); properties.put("graphite.host", "h"); properties.put("graphite.prefix", "p"); properties.put("graphite.namespace", "n"); try (OutputStream outputStream = new FileOutputStream(clusterProperties)) { properties.store(outputStream, null); } Graphite graphite = loader.load(path); assertThat(graphite.getConfig(), is(path)); assertThat(graphite.getHost(), is("h")); assertThat(graphite.getPrefix(), is("p")); assertThat(graphite.getNamespace(), is("n")); }
@Test public void nullPath() throws IOException { Graphite graphite = loader.load(null); assertThat(graphite.getConfig(), is(nullValue())); assertThat(graphite.getHost(), is(nullValue())); assertThat(graphite.getPrefix(), is(nullValue())); assertThat(graphite.getNamespace(), is(nullValue())); }
@Test(expected = CircusTrainException.class) public void pathDoesNotExist() throws IOException { loader.load(new Path(new File(temp.getRoot(), "dummy.properties").toURI())); }
@SuppressWarnings("unchecked") @Test(expected = CircusTrainException.class) public void ioException() throws IOException { Path mockPath = mock(Path.class); when(mockPath.getFileSystem(conf)).thenThrow(IOException.class); loader.load(mockPath); }