Skip to content

Commit 488b5fa

Browse files
committed
Fix edgecases test
1 parent 35b753b commit 488b5fa

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

modules/mongodb/src/test/java/org/testcontainers/mongodb/MongoDBContainerTest.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,29 @@ void shouldExecuteInitScriptWithEdgeCases() {
7272
String expectedComplexName = "test_col_\"_with_specials_!@#%^&*()";
7373
String expectedJapaneseName = "日本語 コレクション テスト";
7474

75-
assertThat(client.getDatabase("test").listCollectionNames())
76-
.as("Check if init script created the collections with special chars and Japanese")
77-
.contains(expectedComplexName, expectedJapaneseName);
75+
com.mongodb.client.MongoDatabase database = client.getDatabase("test");
76+
77+
assertThat(database.listCollectionNames()).contains(expectedComplexName, expectedJapaneseName);
78+
79+
com.mongodb.client.MongoCollection<org.bson.Document> collection = database.getCollection(
80+
expectedComplexName
81+
);
82+
83+
org.bson.Document doc = collection.find(new org.bson.Document("_id", 1)).first();
84+
85+
assertThat(doc).as("Document with _id=1 should exist").isNotNull();
86+
87+
assertThat(doc.getString("key_with_quotes"))
88+
.as("Double quotes should be preserved correctly")
89+
.isEqualTo("This is a \"double quoted\" string");
90+
91+
assertThat(doc.getString("key_with_json_chars"))
92+
.as("JSON special chars should be treated as plain text")
93+
.isEqualTo("{ } [ ] : ,");
94+
95+
assertThat(doc.getString("description"))
96+
.as("Japanese text should be preserved correctly")
97+
.isEqualTo("特殊記号を含むコレクションへの挿入テスト");
7898
}
7999
}
80100
}

0 commit comments

Comments
 (0)