ChatAPIFactory { public static IChatApiDAO getChatApiDao(ChatAlyticsConfig config) { ChatConfig chatConfig = config.computeConfig.chatConfig; if (chatConfig instanceof SlackConfig || chatConfig instanceof SlackBackfillerConfig) { return SlackApiDAOFactory.getSlackApiDao(config); } else if (chatConfig instanceof HipChatConfig) { return HipChatApiDAOFactory.getHipChatApiDao(config); } else if (chatConfig instanceof LocalTestConfig) { return new LocalChatDao(config); } else { throw new IllegalArgumentException("Can't determine or get chat API DAO for " + chatConfig.getClass().getSimpleName()); } }  static IChatApiDAO getChatApiDao(ChatAlyticsConfig config);  }
@Test public void testGetChatApiDao() { ChatAlyticsConfig config = new ChatAlyticsConfig(); config.computeConfig.apiDateFormat = "YYYY-MM-dd"; config.computeConfig.chatConfig = new SlackConfig(); assertTrue(ChatAPIFactory.getChatApiDao(config) instanceof JsonSlackDAO); config.computeConfig.chatConfig = new SlackBackfillerConfig(); assertTrue(ChatAPIFactory.getChatApiDao(config) instanceof JsonSlackDAO); config.computeConfig.chatConfig = new HipChatConfig(); assertTrue(ChatAPIFactory.getChatApiDao(config) instanceof JsonHipChatDAO); config.computeConfig.chatConfig = new LocalTestConfig(); assertTrue(ChatAPIFactory.getChatApiDao(config) instanceof LocalChatDao); }
@Test(expected = IllegalArgumentException.class) public void testGetChatApiDao_invalidType() { ChatAlyticsConfig config = new ChatAlyticsConfig(); config.computeConfig.chatConfig = mock(ChatConfig.class); ChatAPIFactory.getChatApiDao(config); }