Mercurial > hg > ConflictEditor
changeset 14:f2daf738299f
implement a test case for DocumentMatcher that covers the currently implemented cases
author | dirk |
---|---|
date | Fri, 16 Sep 2011 11:38:15 +0200 |
parents | e99bb691f7ce |
children | e60d38aa42fe |
files | conflict-editor/pom.xml conflict-editor/src/test/java/de/codedo/conflicteditor/DocumentMatcherTestCase.java |
diffstat | 2 files changed, 78 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <artifactId>conflict-editor</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> - <name>new project</name> + <name>Conflict Editor</name> <url>http://maven.apache.org</url> <properties> @@ -26,11 +26,24 @@ <artifactId>junit</artifactId> <version>4.9</version> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <version>1.3.RC2</version> + <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.8.5</version> + <scope>test</scope> </dependency> </dependencies>
--- /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<Difference> 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<Difference> 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<Difference> 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); + } +}