From cf3818e04cc17a51d92f513387cbea55f13f09b9 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 10 Apr 2014 07:43:13 +0200 Subject: [PATCH] DATAMONGO-907 - Assert compatibility with mongodb 2.6. Fix test to only check on parts of the expected error message common in both 2.4 and 2.6. Original Pull Request: #166. --- .../data/mongodb/core/MongoTemplateTests.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java index 9106065e2..14a6a89fc 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java @@ -34,7 +34,6 @@ import java.util.List; import java.util.Map; import org.bson.types.ObjectId; -import org.hamcrest.CoreMatchers; import org.joda.time.DateTime; import org.junit.After; import org.junit.Before; @@ -299,6 +298,9 @@ public class MongoTemplateTests { @Test public void rejectsDuplicateIdInInsertAll() { + thrown.expect(DataIntegrityViolationException.class); + thrown.expectMessage("E11000 duplicate key error index: database.person.$_id_"); + MongoTemplate template = new MongoTemplate(factory); template.setWriteResultChecking(WriteResultChecking.EXCEPTION); @@ -310,15 +312,7 @@ public class MongoTemplateTests { records.add(person); records.add(person); - try { - template.insertAll(records); - fail("Expected DataIntegrityViolationException!"); - } catch (DataIntegrityViolationException e) { - assertThat( - e.getMessage(), - CoreMatchers - .startsWith("Insert list failed: E11000 duplicate key error index: database.person.$_id_ dup key: { : ObjectId")); - } + template.insertAll(records); } @Test