Configuration { public final static <T extends Configuration> T loadJson(InputStream inputStream, Class<T> configClass) throws ConfigurationException { try { T config = ObjectMapper.getInstance().readValue(inputStream, configClass); return config; } catch (Exception e) { throw new ConfigurationException("Error when loading configuration file", e); } }  final static T loadJson(InputStream inputStream, Class<T> configClass);  }
@Test public void testLoadJson() throws Exception { SampleConf sampleConf = Configuration.loadJson(ConfigurationTest.class.getClassLoader().getResourceAsStream("sample.json"), SampleConf.class); assert sampleConf.getName().equals("Node1"); assert sampleConf.getTimeout() == 2000; }
@Test public void testLoadJsonException() throws Exception { try { SampleConf sampleConf = Configuration.loadJson(ConfigurationTest.class.getClassLoader().getResourceAsStream("sampleBad.json"), SampleConf.class); assert false; } catch (ConfigurationException e) { assert e.getCause() instanceof JsonException; } }