Permalink
Browse files

Update BsonDocumentTest

I've found a potential bug in the default BsonDocument implementation
DefaultDocument. The default equals method (which is delegated to a
LinkedHashMap if my memory serves me right) compares arrays by reference.

I've added a test case for this which fails like it should. When I'll have time
I'll write a proper hashCode/equals for DefaultDocument.
  • Loading branch information...
1 parent d35d7a4 commit e17522c3757a914443d71ac8e6a446e8e745f958 @kohanyirobert committed Mar 2, 2013
Showing with 22 additions and 7 deletions.
  1. +22 −7 src/test/java/com/github/kohanyirobert/ebson/BsonDocumentTest.java
@@ -8,41 +8,56 @@
public final class BsonDocumentTest {
private static final String STRING_KEY = "string-key";
+ private static final String BINARY_KEY = "binary-key";
private static final String NULL_KEY = "null-key";
private static final String MISSING_KEY = "string-key-not-present";
private static final Object STRING_VALUE = "string-value";
+ private static final Object BINARY_VALUE1 = new byte[] {42};
+ private static final Object BINARY_VALUE2 = new byte[] {42};
- private final BsonDocument document;
+ private final BsonDocument document1;
+ private final BsonDocument document2;
public BsonDocumentTest() {
- document = BsonDocuments.of(
+ document1 = BsonDocuments.of(
STRING_KEY, STRING_VALUE,
+ BINARY_KEY, BINARY_VALUE1,
+ NULL_KEY, null);
+
+ document2 = BsonDocuments.of(
+ STRING_KEY, STRING_VALUE,
+ BINARY_KEY, BINARY_VALUE2,
NULL_KEY, null);
}
@Test
public void containsKey_withStringKey() {
- assertTrue(document.containsKey(STRING_KEY));
+ assertTrue(document1.containsKey(STRING_KEY));
}
@Test(expected = ClassCastException.class)
public void containsKey_withNotStringKey() {
- document.containsKey(new Object());
+ document1.containsKey(new Object());
}
@Test
public void get_keyPresent_withStringKey() {
- assertEquals(STRING_VALUE, document.get(STRING_KEY));
+ assertEquals(STRING_VALUE, document1.get(STRING_KEY));
}
@Test(expected = IllegalArgumentException.class)
public void get_keyNotPresent_withStringKey() {
- document.get(MISSING_KEY);
+ document1.get(MISSING_KEY);
}
@Test(expected = ClassCastException.class)
public void get_keyPresent_withNotStringKey() {
- document.get(new Object());
+ document1.get(new Object());
+ }
+
+ @Test
+ public void equal_twoDocumentsWithSameLogicalValues() {
+ assertEquals(document1, document2);
}
}

0 comments on commit e17522c

Please sign in to comment.