@Test public void testMergeWithTwoEquivalentMessages() { SkypeChatBuilderHelper chatHelper = new SkypeChatBuilderHelper() { @Override public void addChatMessages() { addMessage("joe", "m1", "21/03 15:15:18"); addMessage("joe", "m2", "21/03 15:17:18"); addMessage("foo", "C", "21/03 15:24:18"); addMessage("joe", "m6", "22/03 15:24:18"); addMessage("foo", "D", "22/03 16:24:18"); addMessage("moe", "m9", "22/03 16:25:20"); } }; SkypeChat chatA = chatHelper.getChat("toUpdate", "FOO"); SkypeChatBuilderHelper chatFromOtherSource = new SkypeChatBuilderHelper() { @Override public void addChatMessages() { addMessage("moe", "m5", "22/03 15:16:20"); addMessage("foo", "C", "22/03 15:24:18"); addMessage("moe", "m7", "22/03 15:30:22"); addMessage("foo", "D", "23/03 16:24:18"); addMessage("moe", "m10", "23/03 16:25:20"); } }; SkypeChat chatB = chatFromOtherSource.getChat("toUpdate", "FOO"); String expected = "[2011/03/21 15:15:18] JOE: m1\n" + "[2011/03/21 15:16:20] MOE: m5\n" + "[2011/03/21 15:17:18] JOE: m2\n" + "[2011/03/21 15:24:18] FOO: C\n" + "[2011/03/21 15:30:22] MOE: m7\n" + "[2011/03/22 15:24:18] JOE: m6\n" + "[2011/03/22 16:24:18] FOO: D\n" + "[2011/03/22 16:25:20] MOE: m9\n" + "[2011/03/23 16:25:20] MOE: m10"; assertMergeEnsuringCommutativeProperty( chatA.getChatMessages(), chatB.getChatMessages(), expected); }
@Test public void testMergeIdenticalLists() { SkypeChatBuilderHelper chatHelper = new SkypeChatBuilderHelper() { @Override public void addChatMessages() { addMessage("joe", "fellow", "21/03 15:15:18"); addMessage("moe", "Howdy\n I'm doing fine", "21/03 15:24:18"); addMessage("joe", "A day has passed", "22/03 15:24:18"); addMessage("moe", "booo2", "22/03 15:25:02"); addMessage("joe", "gap", "22/03 15:25:05"); } }; SkypeChatImpl chatA = chatHelper.getChat("toUpdate", "FOO"); SkypeChatImpl chatB = chatHelper.getChat("toUpdate", "FOO"); String expectedMessages = chatA.getChatMessages().toString(); String mergedMessages = mergeChatsAndGetBodyAsString(chatA.getChatMessages(), chatB.getChatMessages()); Assert.assertEquals(expectedMessages, mergedMessages); }
@Test public void testMergeListWithoutCommonMessages() { SkypeChatBuilderHelper chatHelper = new SkypeChatBuilderHelper() { @Override public void addChatMessages() { addMessage("joe", "m1", "21/03 15:15:18"); addMessage("moe", "m2", "21/03 15:24:18"); addMessage("joe", "m3", "22/03 15:24:18"); } }; SkypeChat chatA = chatHelper.getChat("toUpdate", "FOO"); SkypeChatBuilderHelper chatFromOtherSource = new SkypeChatBuilderHelper() { @Override public void addChatMessages() { addMessage("cloe", "m1.5", "21/03 15:15:19"); addMessage("joe", "m5", "22/03 15:24:20"); addMessage("moe", "m6", "22/03 15:24:22"); } }; SkypeChat chatB = chatFromOtherSource.getChat("toUpdate", "FOO"); String expected = "[2011/03/21 15:15:18] JOE: m1\n" + "[2011/03/21 15:15:19] CLOE: m1.5\n" + "[2011/03/21 15:24:18] MOE: m2\n" + "[2011/03/22 15:24:18] JOE: m3\n" + "[2011/03/22 15:24:20] JOE: m5\n" + "[2011/03/22 15:24:22] MOE: m6"; assertMergeEnsuringCommutativeProperty( chatA.getChatMessages(), chatB.getChatMessages(), expected); }