# HG changeset patch # User dirk # Date 1316165895 -7200 # Node ID f2daf738299fea44bc88b2dd3a90d2aa6c7373c9 # Parent e99bb691f7ce404e13dafc20b03b0ce025893c7c implement a test case for DocumentMatcher that covers the currently implemented cases diff -r e99bb691f7ce -r f2daf738299f conflict-editor/pom.xml --- a/conflict-editor/pom.xml Tue Sep 13 08:24:35 2011 +0200 +++ b/conflict-editor/pom.xml Fri Sep 16 11:38:15 2011 +0200 @@ -5,7 +5,7 @@ conflict-editor 1.0-SNAPSHOT jar - new project + Conflict Editor http://maven.apache.org @@ -26,11 +26,24 @@ junit 4.9 test + + + org.hamcrest + hamcrest-core + + + + + org.hamcrest + hamcrest-library + 1.3.RC2 + test org.mockito mockito-all 1.8.5 + test diff -r e99bb691f7ce -r f2daf738299f conflict-editor/src/test/java/de/codedo/conflicteditor/DocumentMatcherTestCase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conflict-editor/src/test/java/de/codedo/conflicteditor/DocumentMatcherTestCase.java Fri Sep 16 11:38:15 2011 +0200 @@ -0,0 +1,64 @@ + +package de.codedo.conflicteditor; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Ignore; +import org.junit.Test; + +public class DocumentMatcherTestCase extends Object +{ + private ObjectMapper _mapper = new ObjectMapper(); + + @Test + public void equalDocumentsShouldProduceNoDifferences() throws Exception + { + JsonNode node = parse("{ 'key' : 'value' }"); + List diffs = new DocumentMatcher(node, node).compare(); + assertThat(diffs, hasSize(0)); + } + + @Test + public void differentValuesShouldProduceOneDifferencePerKey() throws Exception + { + JsonNode original = parse("{ 'key' : 'value' }"); + JsonNode conflict = parse("{ 'key' : 'other-value' }"); + List diffs = new DocumentMatcher(original, conflict).compare(); + assertEquals(1, diffs.size()); + + Difference diff = diffs.get(0); + assertEquals("key", diff.key); + assertEquals("value", diff.currentValue); + assertEquals("other-value", diff.otherValue); + } + + @Ignore("does not work yet") + @Test + public void valuePresentOnlyInOriginalShouldProduceDifference() throws Exception + { + JsonNode original = parse("{ 'key' : 'value', 'only-here' : 'test' }"); + JsonNode conflict = parse("{ 'key' : 'value' }"); + List diffs = new DocumentMatcher(original, conflict).compare(); + assertThat(diffs, hasSize(1)); + } + + @Ignore("not yet implemented") + @Test + public void valueOnlyInConflict() throws Exception + { + } + + private JsonNode parse(String input) throws IOException + { + // Jackson cannot parse JSON that uses single quotes ... + String convertedInput = input.replace("'", "\""); + return _mapper.readTree(convertedInput); + } +}