YamlUtils { public static <T> T readYamlFromResource(String resource, Class<T> clazz) { InputStream is = null; try { is = ClassLoader.getSystemResourceAsStream(resource); if (is == null) { String msg = String.format("Can't find %s to construct %s", resource, clazz); throw new MissingConfigException(msg); } Yaml yaml = new Yaml(); return yaml.loadAs(is, clazz); } finally { try { is.close(); } catch (Exception e) { } } }  static T readYamlFromString(String yamlStr, Class<T> clazz); static ChatAlyticsConfig readChatAlyticsConfigFromString(String yamlStr); static String writeYaml(T value); static T readYamlFromResource(String resource, Class<T> clazz); static ChatAlyticsConfig readChatAlyticsConfig(String resource);  }
@Test public void testReadYamlFromResource() { String expectedURL = "http: String resource = "config/chatalytics-slack.yaml"; ChatAlyticsConfig readConfig = YamlUtils.readChatAlyticsConfig(resource); assertTrue(readConfig.computeConfig.chatConfig instanceof SlackConfig); assertEquals(expectedURL, readConfig.computeConfig.chatConfig.getBaseAPIURL()); resource = "config/chatalytics-hipchat.yaml"; readConfig = YamlUtils.readChatAlyticsConfig(resource); assertTrue(readConfig.computeConfig.chatConfig instanceof HipChatConfig); assertEquals(expectedURL, readConfig.computeConfig.chatConfig.getBaseAPIURL()); resource = "config/chatalytics-local.yaml"; readConfig = YamlUtils.readChatAlyticsConfig(resource); assertTrue(readConfig.computeConfig.chatConfig instanceof LocalTestConfig); resource = "config/chatalytics-slackbackfill.yaml"; readConfig = YamlUtils.readChatAlyticsConfig(resource); assertTrue(readConfig.computeConfig.chatConfig instanceof SlackBackfillerConfig); assertEquals(expectedURL, readConfig.computeConfig.chatConfig.getBaseAPIURL()); }