@@ -213,4 +213,150 @@ private static Media getMedia() {
213
213
return Media .builder ().mimeType (MimeTypeUtils .IMAGE_JPEG ).data (URI .create ("http://type1" )).build ();
214
214
}
215
215
216
+ @ Test
217
+ void testMetadataModeNone () {
218
+ Map <String , Object > metadata = new HashMap <>();
219
+ metadata .put ("secret" , "hidden" );
220
+
221
+ Document document = Document .builder ().text ("Visible content" ).metadata (metadata ).build ();
222
+
223
+ String formattedContent = document .getFormattedContent (MetadataMode .NONE );
224
+ assertThat (formattedContent ).contains ("Visible content" );
225
+ assertThat (formattedContent ).doesNotContain ("secret" );
226
+ assertThat (formattedContent ).doesNotContain ("hidden" );
227
+ }
228
+
229
+ @ Test
230
+ void testMetadataModeEmbed () {
231
+ Map <String , Object > metadata = new HashMap <>();
232
+ metadata .put ("embedKey" , "embedValue" );
233
+ metadata .put ("filterKey" , "filterValue" );
234
+
235
+ Document document = Document .builder ().text ("Test content" ).metadata (metadata ).build ();
236
+
237
+ String formattedContent = document .getFormattedContent (MetadataMode .EMBED );
238
+ // This test assumes EMBED mode includes all metadata - adjust based on actual
239
+ // implementation
240
+ assertThat (formattedContent ).contains ("Test content" );
241
+ }
242
+
243
+ @ Test
244
+ void testDocumentBuilderChaining () {
245
+ Map <String , Object > metadata = new HashMap <>();
246
+ metadata .put ("chain" , "test" );
247
+
248
+ Document document = Document .builder ()
249
+ .text ("Chain test" )
250
+ .metadata (metadata )
251
+ .metadata ("additional" , "value" )
252
+ .score (0.85 )
253
+ .build ();
254
+
255
+ assertThat (document .getText ()).isEqualTo ("Chain test" );
256
+ assertThat (document .getMetadata ()).containsEntry ("chain" , "test" );
257
+ assertThat (document .getMetadata ()).containsEntry ("additional" , "value" );
258
+ assertThat (document .getScore ()).isEqualTo (0.85 );
259
+ }
260
+
261
+ @ Test
262
+ void testDocumentWithScoreGreaterThanOne () {
263
+ Document document = Document .builder ().text ("High score test" ).score (1.5 ).build ();
264
+
265
+ assertThat (document .getScore ()).isEqualTo (1.5 );
266
+ }
267
+
268
+ @ Test
269
+ void testMutateWithChanges () {
270
+ Document original = Document .builder ().text ("Original text" ).score (0.5 ).metadata ("original" , "value" ).build ();
271
+
272
+ Document mutated = original .mutate ().text ("Mutated text" ).score (0.8 ).metadata ("new" , "metadata" ).build ();
273
+
274
+ assertThat (mutated .getText ()).isEqualTo ("Mutated text" );
275
+ assertThat (mutated .getScore ()).isEqualTo (0.8 );
276
+ assertThat (mutated .getMetadata ()).containsEntry ("new" , "metadata" );
277
+ assertThat (original .getText ()).isEqualTo ("Original text" ); // Original unchanged
278
+ }
279
+
280
+ @ Test
281
+ void testDocumentEqualityWithDifferentScores () {
282
+ Document doc1 = Document .builder ().id ("sameId" ).text ("Same text" ).score (0.5 ).build ();
283
+
284
+ Document doc2 = Document .builder ().id ("sameId" ).text ("Same text" ).score (0.8 ).build ();
285
+
286
+ // Assuming score affects equality - adjust if it doesn't
287
+ assertThat (doc1 ).isNotEqualTo (doc2 );
288
+ }
289
+
290
+ @ Test
291
+ void testDocumentWithComplexMetadata () {
292
+ Map <String , Object > nestedMap = new HashMap <>();
293
+ nestedMap .put ("nested" , "value" );
294
+
295
+ Map <String , Object > metadata = new HashMap <>();
296
+ metadata .put ("string" , "value" );
297
+ metadata .put ("number" , 1 );
298
+ metadata .put ("boolean" , true );
299
+ metadata .put ("map" , nestedMap );
300
+
301
+ Document document = Document .builder ().text ("Complex metadata test" ).metadata (metadata ).build ();
302
+
303
+ assertThat (document .getMetadata ()).containsEntry ("string" , "value" );
304
+ assertThat (document .getMetadata ()).containsEntry ("number" , 1 );
305
+ assertThat (document .getMetadata ()).containsEntry ("boolean" , true );
306
+ assertThat (document .getMetadata ()).containsEntry ("map" , nestedMap );
307
+ }
308
+
309
+ @ Test
310
+ void testMetadataImmutability () {
311
+ Map <String , Object > originalMetadata = new HashMap <>();
312
+ originalMetadata .put ("key" , "value" );
313
+
314
+ Document document = Document .builder ().text ("Immutability test" ).metadata (originalMetadata ).build ();
315
+
316
+ // Modify original map
317
+ originalMetadata .put ("key" , "modified" );
318
+ originalMetadata .put ("newKey" , "newValue" );
319
+
320
+ // Document's metadata should be unaffected (if properly copied)
321
+ assertThat (document .getMetadata ()).containsEntry ("key" , "value" );
322
+ assertThat (document .getMetadata ()).doesNotContainKey ("newKey" );
323
+ }
324
+
325
+ @ Test
326
+ void testDocumentWithEmptyMetadata () {
327
+ Document document = Document .builder ().text ("Empty metadata test" ).metadata (new HashMap <>()).build ();
328
+
329
+ assertThat (document .getMetadata ()).isEmpty ();
330
+ }
331
+
332
+ @ Test
333
+ void testMetadataWithNullValueInMap () {
334
+ Map <String , Object > metadata = new HashMap <>();
335
+ metadata .put ("validKey" , "validValue" );
336
+ metadata .put ("nullKey" , null );
337
+
338
+ assertThrows (IllegalArgumentException .class , () -> {
339
+ Document .builder ().text ("test" ).metadata (metadata ).build ();
340
+ });
341
+ }
342
+
343
+ @ Test
344
+ void testDocumentWithWhitespaceOnlyText () {
345
+ String whitespaceText = " \n \t \r " ;
346
+ Document document = Document .builder ().text (whitespaceText ).build ();
347
+
348
+ assertThat (document .getText ()).isEqualTo (whitespaceText );
349
+ assertThat (document .isText ()).isTrue ();
350
+ }
351
+
352
+ @ Test
353
+ void testDocumentHashCodeConsistency () {
354
+ Document document = Document .builder ().text ("Hash test" ).metadata ("key" , "value" ).score (0.1 ).build ();
355
+
356
+ int hashCode1 = document .hashCode ();
357
+ int hashCode2 = document .hashCode ();
358
+
359
+ assertThat (hashCode1 ).isEqualTo (hashCode2 );
360
+ }
361
+
216
362
}
0 commit comments