1/*
2 * Copyright 2001-2008 Artima, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.scalatest.matchers
17
18import org.scalatest._
19import org.scalatest.prop.Checkers
20import org.scalacheck._
21import Arbitrary._
22import Prop._
23
24class ShouldContainElementSpec extends Spec with ShouldMatchers with Checkers with ReturnsNormallyThrowsAssertion {
25
26  // Checking for a specific size
27  describe("The 'contain (Int)' syntax") {
28
29    describe("on Array") {
30
31      it("should do nothing if array contains the specified element") {
32        Array(1, 2) should contain (2)
33        Array(1, 2) should (contain (2))
34        // check((arr: Array[Int]) => arr.size != 0 ==> returnsNormally(arr should contain (arr(arr.length - 1))))
35      }
36
37      it("should do nothing if array does not contain the element and used with should not") {
38        Array(1, 2) should not { contain (3) }
39        Array(1, 2) should not contain (3)
40        // check((arr: Array[Int], i: Int) => !arr.exists(_ == i) ==> returnsNormally(arr should not { contain (i) }))
41        // check((arr: Array[Int], i: Int) => !arr.exists(_ == i) ==> returnsNormally(arr should not contain (i)))
42      }
43
44      it("should do nothing when array contains the specified element and used in a logical-and expression") {
45        Array(1, 2) should { contain (2) and (contain (1)) }
46        Array(1, 2) should ((contain (2)) and (contain (1)))
47        Array(1, 2) should (contain (2) and contain (1))
48       }
49
50      it("should do nothing when array contains the specified element and used in a logical-or expression") {
51        Array(1, 2) should { contain (77) or (contain (2)) }
52        Array(1, 2) should ((contain (77)) or (contain (2)))
53        Array(1, 2) should (contain (77) or contain (2))
54      }
55
56      it("should do nothing when array doesn't contain the specified element and used in a logical-and expression with not") {
57        Array(1, 2) should { not { contain (5) } and not { contain (3) }}
58        Array(1, 2) should ((not contain (5)) and (not contain (3)))
59        Array(1, 2) should (not contain (5) and not contain (3))
60      }
61
62      it("should do nothing when array doesn't contain the specified element and used in a logical-or expression with not") {
63        Array(1, 2) should { not { contain (1) } or not { contain (3) }}
64        Array(1, 2) should ((not contain (1)) or (not contain (3)))
65        Array(1, 2) should (not contain (3) or not contain (2))
66      }
67
68      it("should throw TestFailedException if array does not contain the specified element") {
69        val caught = intercept[TestFailedException] {
70          Array(1, 2) should contain (3)
71        }
72        assert(caught.getMessage === "Array(1, 2) did not contain element 3")
73        // check((arr: Array[String], s: String) => !arr.exists(_ == s) ==> throwsTestFailedException(arr should contain (s)))
74      }
75
76      it("should throw TestFailedException if array contains the specified element, when used with not") {
77
78        val caught1 = intercept[TestFailedException] {
79          Array(1, 2) should not contain (2)
80        }
81        assert(caught1.getMessage === "Array(1, 2) contained element 2")
82        // check((arr: Array[String]) => arr.length > 0 ==> throwsTestFailedException(arr should not contain (arr(0))))
83
84        val caught2 = intercept[TestFailedException] {
85          Array(1, 2) should not (contain (2))
86        }
87        assert(caught2.getMessage === "Array(1, 2) contained element 2")
88        // check((arr: Array[String]) => arr.length > 0 ==> throwsTestFailedException(arr should not (contain (arr(0)))))
89
90        val caught3 = intercept[TestFailedException] {
91          Array(1, 2) should (not contain (2))
92        }
93        assert(caught3.getMessage === "Array(1, 2) contained element 2")
94        // check((arr: Array[String]) => arr.length > 0 ==> throwsTestFailedException(arr should not (contain (arr(0)))))
95      }
96
97      it("should throw a TestFailedException when array doesn't contain the specified element and used in a logical-and expression") {
98
99        val caught1 = intercept[TestFailedException] {
100          Array(1, 2) should { contain (5) and (contain (2 - 1)) }
101        }
102        assert(caught1.getMessage === "Array(1, 2) did not contain element 5")
103
104        val caught2 = intercept[TestFailedException] {
105          Array(1, 2) should (contain (5) and contain (2 - 1))
106        }
107        assert(caught2.getMessage === "Array(1, 2) did not contain element 5")
108      }
109
110      it("should throw a TestFailedException when array doesn't contain the specified element and used in a logical-or expression") {
111
112        val caught1 = intercept[TestFailedException] {
113          Array(1, 2) should { contain (55) or (contain (22)) }
114        }
115        assert(caught1.getMessage === "Array(1, 2) did not contain element 55, and Array(1, 2) did not contain element 22")
116
117        val caught2 = intercept[TestFailedException] {
118          Array(1, 2) should (contain (55) or contain (22))
119        }
120        assert(caught2.getMessage === "Array(1, 2) did not contain element 55, and Array(1, 2) did not contain element 22")
121      }
122
123      it("should throw a TestFailedException when array contains the specified element and used in a logical-and expression with not") {
124
125        val caught1 = intercept[TestFailedException] {
126          Array(1, 2) should { not { contain (3) } and not { contain (2) }}
127        }
128        assert(caught1.getMessage === "Array(1, 2) did not contain element 3, but Array(1, 2) contained element 2")
129
130        val caught2 = intercept[TestFailedException] {
131          Array(1, 2) should ((not contain (3)) and (not contain (2)))
132        }
133        assert(caught2.getMessage === "Array(1, 2) did not contain element 3, but Array(1, 2) contained element 2")
134
135        val caught3 = intercept[TestFailedException] {
136          Array(1, 2) should (not contain (3) and not contain (2))
137        }
138        assert(caught3.getMessage === "Array(1, 2) did not contain element 3, but Array(1, 2) contained element 2")
139      }
140
141      it("should throw a TestFailedException when array contains the specified element and used in a logical-or expression with not") {
142
143        val caught1 = intercept[TestFailedException] {
144          Array(1, 2) should { not { contain (2) } or not { contain (2) }}
145        }
146        assert(caught1.getMessage === "Array(1, 2) contained element 2, and Array(1, 2) contained element 2")
147
148        val caught2 = intercept[TestFailedException] {
149          Array(1, 2) should ((not contain (2)) or (not contain (2)))
150        }
151        assert(caught2.getMessage === "Array(1, 2) contained element 2, and Array(1, 2) contained element 2")
152
153        val caught3 = intercept[TestFailedException] {
154          Array(1, 2) should (not contain (2) or not contain (2))
155        }
156        assert(caught3.getMessage === "Array(1, 2) contained element 2, and Array(1, 2) contained element 2")
157      }
158    }
159
160    describe("on scala.collection.immutable.Set") {
161
162      it("should do nothing if set contains the specified element") {
163        Set(1, 2) should contain (2)
164        Set(1, 2) should (contain (2))
165      }
166
167      it("should do nothing if set does not contain the element and used with should not") {
168        Set(1, 2) should not { contain (3) }
169        Set(1, 2) should not contain (3)
170      }
171
172      it("should do nothing when set contains the specified element and used in a logical-and expression") {
173        Set(1, 2) should { contain (2) and (contain (1)) }
174        Set(1, 2) should ((contain (2)) and (contain (1)))
175        Set(1, 2) should (contain (2) and contain (1))
176       }
177
178      it("should do nothing when set contains the specified element and used in a logical-or expression") {
179        Set(1, 2) should { contain (77) or (contain (2)) }
180        Set(1, 2) should ((contain (77)) or (contain (2)))
181        Set(1, 2) should (contain (77) or contain (2))
182      }
183
184      it("should do nothing when set doesn't contain the specified element and used in a logical-and expression with not") {
185        Set(1, 2) should { not { contain (5) } and not { contain (3) }}
186        Set(1, 2) should ((not contain (5)) and (not contain (3)))
187        Set(1, 2) should (not contain (5) and not contain (3))
188      }
189
190      it("should do nothing when set doesn't contain the specified element and used in a logical-or expression with not") {
191        Set(1, 2) should { not { contain (1) } or not { contain (3) }}
192        Set(1, 2) should ((not contain (1)) or (not contain (3)))
193        Set(1, 2) should (not contain (3) or not contain (2))
194      }
195
196      it("should throw TestFailedException if set does not contain the specified element") {
197        val caught = intercept[TestFailedException] {
198          Set(1, 2) should contain (3)
199        }
200        assert(caught.getMessage === "Set(1, 2) did not contain element 3")
201      }
202
203      it("should throw TestFailedException if set contains the specified element, when used with not") {
204
205        val caught1 = intercept[TestFailedException] {
206          Set(1, 2) should not contain (2)
207        }
208        assert(caught1.getMessage === "Set(1, 2) contained element 2")
209
210        val caught2 = intercept[TestFailedException] {
211          Set(1, 2) should not (contain (2))
212        }
213        assert(caught2.getMessage === "Set(1, 2) contained element 2")
214
215        val caught3 = intercept[TestFailedException] {
216          Set(1, 2) should (not contain (2))
217        }
218        assert(caught3.getMessage === "Set(1, 2) contained element 2")
219      }
220
221      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-and expression") {
222
223        val caught1 = intercept[TestFailedException] {
224          Set(1, 2) should { contain (5) and (contain (2 - 1)) }
225        }
226        assert(caught1.getMessage === "Set(1, 2) did not contain element 5")
227
228        val caught2 = intercept[TestFailedException] {
229          Set(1, 2) should (contain (5) and contain (2 - 1))
230        }
231        assert(caught2.getMessage === "Set(1, 2) did not contain element 5")
232      }
233
234      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-or expression") {
235
236        val caught1 = intercept[TestFailedException] {
237          Set(1, 2) should { contain (55) or (contain (22)) }
238        }
239        assert(caught1.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
240
241        val caught2 = intercept[TestFailedException] {
242          Set(1, 2) should (contain (55) or contain (22))
243        }
244        assert(caught2.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
245      }
246
247      it("should throw a TestFailedException when set contains the specified element and used in a logical-and expression with not") {
248
249        val caught1 = intercept[TestFailedException] {
250          Set(1, 2) should { not { contain (3) } and not { contain (2) }}
251        }
252        assert(caught1.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
253
254        val caught2 = intercept[TestFailedException] {
255          Set(1, 2) should ((not contain (3)) and (not contain (2)))
256        }
257        assert(caught2.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
258
259        val caught3 = intercept[TestFailedException] {
260          Set(1, 2) should (not contain (3) and not contain (2))
261        }
262        assert(caught3.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
263      }
264
265      it("should throw a TestFailedException when set contains the specified element and used in a logical-or expression with not") {
266
267        val caught1 = intercept[TestFailedException] {
268          Set(1, 2) should { not { contain (2) } or not { contain (2) }}
269        }
270        assert(caught1.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
271
272        val caught2 = intercept[TestFailedException] {
273          Set(1, 2) should ((not contain (2)) or (not contain (2)))
274        }
275        assert(caught2.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
276
277        val caught3 = intercept[TestFailedException] {
278          Set(1, 2) should (not contain (2) or not contain (2))
279        }
280        assert(caught3.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
281      }
282    }
283
284    describe("on scala.collection.mutable.Set") {
285
286      import scala.collection.mutable
287
288      it("should do nothing if set contains the specified element") {
289        mutable.Set(1, 2) should contain (2)
290        mutable.Set(1, 2) should (contain (2))
291      }
292
293      it("should do nothing if set does not contain the element and used with should not") {
294        mutable.Set(1, 2) should not { contain (3) }
295        mutable.Set(1, 2) should not contain (3)
296      }
297
298      it("should do nothing when set contains the specified element and used in a logical-and expression") {
299        mutable.Set(1, 2) should { contain (2) and (contain (1)) }
300        mutable.Set(1, 2) should ((contain (2)) and (contain (1)))
301        mutable.Set(1, 2) should (contain (2) and contain (1))
302       }
303
304      it("should do nothing when set contains the specified element and used in a logical-or expression") {
305        mutable.Set(1, 2) should { contain (77) or (contain (2)) }
306        mutable.Set(1, 2) should ((contain (77)) or (contain (2)))
307        mutable.Set(1, 2) should (contain (77) or contain (2))
308      }
309
310      it("should do nothing when set doesn't contain the specified element and used in a logical-and expression with not") {
311        mutable.Set(1, 2) should { not { contain (5) } and not { contain (3) }}
312        mutable.Set(1, 2) should ((not contain (5)) and (not contain (3)))
313        mutable.Set(1, 2) should (not contain (5) and not contain (3))
314      }
315
316      it("should do nothing when set doesn't contain the specified element and used in a logical-or expression with not") {
317        mutable.Set(1, 2) should { not { contain (1) } or not { contain (3) }}
318        mutable.Set(1, 2) should ((not contain (1)) or (not contain (3)))
319        mutable.Set(1, 2) should (not contain (3) or not contain (2))
320      }
321
322      it("should throw TestFailedException if set does not contain the specified element") {
323        val caught = intercept[TestFailedException] {
324          mutable.Set(1, 2) should contain (3)
325        }
326        assert(caught.getMessage === "Set(1, 2) did not contain element 3")
327      }
328
329      it("should throw TestFailedException if set contains the specified element, when used with not") {
330
331        val caught1 = intercept[TestFailedException] {
332          mutable.Set(1, 2) should not contain (2)
333        }
334        assert(caught1.getMessage === "Set(1, 2) contained element 2")
335
336        val caught2 = intercept[TestFailedException] {
337          mutable.Set(1, 2) should not (contain (2))
338        }
339        assert(caught2.getMessage === "Set(1, 2) contained element 2")
340
341        val caught3 = intercept[TestFailedException] {
342          mutable.Set(1, 2) should (not contain (2))
343        }
344        assert(caught3.getMessage === "Set(1, 2) contained element 2")
345      }
346
347      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-and expression") {
348
349        val caught1 = intercept[TestFailedException] {
350          mutable.Set(1, 2) should { contain (5) and (contain (2 - 1)) }
351        }
352        assert(caught1.getMessage === "Set(1, 2) did not contain element 5")
353
354        val caught2 = intercept[TestFailedException] {
355          mutable.Set(1, 2) should (contain (5) and contain (2 - 1))
356        }
357        assert(caught2.getMessage === "Set(1, 2) did not contain element 5")
358      }
359
360      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-or expression") {
361
362        val caught1 = intercept[TestFailedException] {
363          mutable.Set(1, 2) should { contain (55) or (contain (22)) }
364        }
365        assert(caught1.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
366
367        val caught2 = intercept[TestFailedException] {
368          mutable.Set(1, 2) should (contain (55) or contain (22))
369        }
370        assert(caught2.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
371      }
372
373      it("should throw a TestFailedException when set contains the specified element and used in a logical-and expression with not") {
374
375        val caught1 = intercept[TestFailedException] {
376          mutable.Set(1, 2) should { not { contain (3) } and not { contain (2) }}
377        }
378        assert(caught1.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
379
380        val caught2 = intercept[TestFailedException] {
381          mutable.Set(1, 2) should ((not contain (3)) and (not contain (2)))
382        }
383        assert(caught2.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
384
385        val caught3 = intercept[TestFailedException] {
386          mutable.Set(1, 2) should (not contain (3) and not contain (2))
387        }
388        assert(caught3.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
389      }
390
391      it("should throw a TestFailedException when set contains the specified element and used in a logical-or expression with not") {
392
393        val caught1 = intercept[TestFailedException] {
394          mutable.Set(1, 2) should { not { contain (2) } or not { contain (2) }}
395        }
396        assert(caught1.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
397
398        val caught2 = intercept[TestFailedException] {
399          mutable.Set(1, 2) should ((not contain (2)) or (not contain (2)))
400        }
401        assert(caught2.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
402
403        val caught3 = intercept[TestFailedException] {
404          mutable.Set(1, 2) should (not contain (2) or not contain (2))
405        }
406        assert(caught3.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
407      }
408    }
409
410    describe("on scala.collection.Set") {
411
412      val set: scala.collection.Set[Int] = Set(1, 2)
413
414      it("should do nothing if set contains the specified element") {
415        set should contain (2)
416        set should (contain (2))
417      }
418
419      it("should do nothing if set does not contain the element and used with should not") {
420        set should not { contain (3) }
421        set should not contain (3)
422      }
423
424      it("should do nothing when set contains the specified element and used in a logical-and expression") {
425        set should { contain (2) and (contain (1)) }
426        set should ((contain (2)) and (contain (1)))
427        set should (contain (2) and contain (1))
428       }
429
430      it("should do nothing when set contains the specified element and used in a logical-or expression") {
431        set should { contain (77) or (contain (2)) }
432        set should ((contain (77)) or (contain (2)))
433        set should (contain (77) or contain (2))
434      }
435
436      it("should do nothing when set doesn't contain the specified element and used in a logical-and expression with not") {
437        set should { not { contain (5) } and not { contain (3) }}
438        set should ((not contain (5)) and (not contain (3)))
439        set should (not contain (5) and not contain (3))
440      }
441
442      it("should do nothing when set doesn't contain the specified element and used in a logical-or expression with not") {
443        set should { not { contain (1) } or not { contain (3) }}
444        set should ((not contain (1)) or (not contain (3)))
445        set should (not contain (3) or not contain (2))
446      }
447
448      it("should throw TestFailedException if set does not contain the specified element") {
449        val caught = intercept[TestFailedException] {
450          set should contain (3)
451        }
452        assert(caught.getMessage === "Set(1, 2) did not contain element 3")
453      }
454
455      it("should throw TestFailedException if set contains the specified element, when used with not") {
456
457        val caught1 = intercept[TestFailedException] {
458          set should not contain (2)
459        }
460        assert(caught1.getMessage === "Set(1, 2) contained element 2")
461
462        val caught2 = intercept[TestFailedException] {
463          set should not (contain (2))
464        }
465        assert(caught2.getMessage === "Set(1, 2) contained element 2")
466
467        val caught3 = intercept[TestFailedException] {
468          set should (not contain (2))
469        }
470        assert(caught3.getMessage === "Set(1, 2) contained element 2")
471      }
472
473      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-and expression") {
474
475        val caught1 = intercept[TestFailedException] {
476          set should { contain (5) and (contain (2 - 1)) }
477        }
478        assert(caught1.getMessage === "Set(1, 2) did not contain element 5")
479
480        val caught2 = intercept[TestFailedException] {
481          set should (contain (5) and contain (2 - 1))
482        }
483        assert(caught2.getMessage === "Set(1, 2) did not contain element 5")
484      }
485
486      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-or expression") {
487
488        val caught1 = intercept[TestFailedException] {
489          set should { contain (55) or (contain (22)) }
490        }
491        assert(caught1.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
492
493        val caught2 = intercept[TestFailedException] {
494          set should (contain (55) or contain (22))
495        }
496        assert(caught2.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
497      }
498
499      it("should throw a TestFailedException when set contains the specified element and used in a logical-and expression with not") {
500
501        val caught1 = intercept[TestFailedException] {
502          set should { not { contain (3) } and not { contain (2) }}
503        }
504        assert(caught1.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
505
506        val caught2 = intercept[TestFailedException] {
507          set should ((not contain (3)) and (not contain (2)))
508        }
509        assert(caught2.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
510
511        val caught3 = intercept[TestFailedException] {
512          set should (not contain (3) and not contain (2))
513        }
514        assert(caught3.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
515      }
516
517      it("should throw a TestFailedException when set contains the specified element and used in a logical-or expression with not") {
518
519        val caught1 = intercept[TestFailedException] {
520          set should { not { contain (2) } or not { contain (2) }}
521        }
522        assert(caught1.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
523
524        val caught2 = intercept[TestFailedException] {
525          set should ((not contain (2)) or (not contain (2)))
526        }
527        assert(caught2.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
528
529        val caught3 = intercept[TestFailedException] {
530          set should (not contain (2) or not contain (2))
531        }
532        assert(caught3.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
533      }
534    }
535
536    describe("on scala.collection.immutable.HashSet") {
537
538      import scala.collection.immutable.HashSet
539
540      it("should do nothing if set contains the specified element") {
541        HashSet(1, 2) should contain (2)
542        HashSet(1, 2) should (contain (2))
543      }
544
545      it("should do nothing if set does not contain the element and used with should not") {
546        HashSet(1, 2) should not { contain (3) }
547        HashSet(1, 2) should not contain (3)
548      }
549
550      it("should do nothing when set contains the specified element and used in a logical-and expression") {
551        HashSet(1, 2) should { contain (2) and (contain (1)) }
552        HashSet(1, 2) should ((contain (2)) and (contain (1)))
553        HashSet(1, 2) should (contain (2) and contain (1))
554       }
555
556      it("should do nothing when set contains the specified element and used in a logical-or expression") {
557        HashSet(1, 2) should { contain (77) or (contain (2)) }
558        HashSet(1, 2) should ((contain (77)) or (contain (2)))
559        HashSet(1, 2) should (contain (77) or contain (2))
560      }
561
562      it("should do nothing when set doesn't contain the specified element and used in a logical-and expression with not") {
563        HashSet(1, 2) should { not { contain (5) } and not { contain (3) }}
564        HashSet(1, 2) should ((not contain (5)) and (not contain (3)))
565        HashSet(1, 2) should (not contain (5) and not contain (3))
566      }
567
568      it("should do nothing when set doesn't contain the specified element and used in a logical-or expression with not") {
569        HashSet(1, 2) should { not { contain (1) } or not { contain (3) }}
570        HashSet(1, 2) should ((not contain (1)) or (not contain (3)))
571        HashSet(1, 2) should (not contain (3) or not contain (2))
572      }
573
574      it("should throw TestFailedException if set does not contain the specified element") {
575        val caught = intercept[TestFailedException] {
576          HashSet(1, 2) should contain (3)
577        }
578        assert(caught.getMessage === "Set(1, 2) did not contain element 3")
579      }
580
581      it("should throw TestFailedException if set contains the specified element, when used with not") {
582
583        val caught1 = intercept[TestFailedException] {
584          HashSet(1, 2) should not contain (2)
585        }
586        assert(caught1.getMessage === "Set(1, 2) contained element 2")
587
588        val caught2 = intercept[TestFailedException] {
589          HashSet(1, 2) should not (contain (2))
590        }
591        assert(caught2.getMessage === "Set(1, 2) contained element 2")
592
593        val caught3 = intercept[TestFailedException] {
594          HashSet(1, 2) should (not contain (2))
595        }
596        assert(caught3.getMessage === "Set(1, 2) contained element 2")
597      }
598
599      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-and expression") {
600
601        val caught1 = intercept[TestFailedException] {
602          HashSet(1, 2) should { contain (5) and (contain (2 - 1)) }
603        }
604        assert(caught1.getMessage === "Set(1, 2) did not contain element 5")
605
606        val caught2 = intercept[TestFailedException] {
607          HashSet(1, 2) should (contain (5) and contain (2 - 1))
608        }
609        assert(caught2.getMessage === "Set(1, 2) did not contain element 5")
610      }
611
612      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-or expression") {
613
614        val caught1 = intercept[TestFailedException] {
615          HashSet(1, 2) should { contain (55) or (contain (22)) }
616        }
617        assert(caught1.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
618
619        val caught2 = intercept[TestFailedException] {
620          HashSet(1, 2) should (contain (55) or contain (22))
621        }
622        assert(caught2.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
623      }
624
625      it("should throw a TestFailedException when set contains the specified element and used in a logical-and expression with not") {
626
627        val caught1 = intercept[TestFailedException] {
628          HashSet(1, 2) should { not { contain (3) } and not { contain (2) }}
629        }
630        assert(caught1.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
631
632        val caught2 = intercept[TestFailedException] {
633          HashSet(1, 2) should ((not contain (3)) and (not contain (2)))
634        }
635        assert(caught2.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
636
637        val caught3 = intercept[TestFailedException] {
638          HashSet(1, 2) should (not contain (3) and not contain (2))
639        }
640        assert(caught3.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
641      }
642
643      it("should throw a TestFailedException when set contains the specified element and used in a logical-or expression with not") {
644
645        val caught1 = intercept[TestFailedException] {
646          HashSet(1, 2) should { not { contain (2) } or not { contain (2) }}
647        }
648        assert(caught1.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
649
650        val caught2 = intercept[TestFailedException] {
651          HashSet(1, 2) should ((not contain (2)) or (not contain (2)))
652        }
653        assert(caught2.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
654
655        val caught3 = intercept[TestFailedException] {
656          HashSet(1, 2) should (not contain (2) or not contain (2))
657        }
658        assert(caught3.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
659      }
660    }
661
662    describe("on scala.collection.mutable.HashSet") {
663
664      import scala.collection.mutable
665
666      it("should do nothing if set contains the specified element") {
667        mutable.HashSet(1, 2) should contain (2)
668        mutable.HashSet(1, 2) should (contain (2))
669      }
670
671      it("should do nothing if set does not contain the element and used with should not") {
672        mutable.HashSet(1, 2) should not { contain (3) }
673        mutable.HashSet(1, 2) should not contain (3)
674      }
675
676      it("should do nothing when set contains the specified element and used in a logical-and expression") {
677        mutable.HashSet(1, 2) should { contain (2) and (contain (1)) }
678        mutable.HashSet(1, 2) should ((contain (2)) and (contain (1)))
679        mutable.HashSet(1, 2) should (contain (2) and contain (1))
680       }
681
682      it("should do nothing when set contains the specified element and used in a logical-or expression") {
683        mutable.HashSet(1, 2) should { contain (77) or (contain (2)) }
684        mutable.HashSet(1, 2) should ((contain (77)) or (contain (2)))
685        mutable.HashSet(1, 2) should (contain (77) or contain (2))
686      }
687
688      it("should do nothing when set doesn't contain the specified element and used in a logical-and expression with not") {
689        mutable.HashSet(1, 2) should { not { contain (5) } and not { contain (3) }}
690        mutable.HashSet(1, 2) should ((not contain (5)) and (not contain (3)))
691        mutable.HashSet(1, 2) should (not contain (5) and not contain (3))
692      }
693
694      it("should do nothing when set doesn't contain the specified element and used in a logical-or expression with not") {
695        mutable.HashSet(1, 2) should { not { contain (1) } or not { contain (3) }}
696        mutable.HashSet(1, 2) should ((not contain (1)) or (not contain (3)))
697        mutable.HashSet(1, 2) should (not contain (3) or not contain (2))
698      }
699
700      it("should throw TestFailedException if set does not contain the specified element") {
701        val caught = intercept[TestFailedException] {
702          mutable.HashSet(1, 2) should contain (3)
703        }
704        assert(caught.getMessage === "Set(1, 2) did not contain element 3")
705      }
706
707      it("should throw TestFailedException if set contains the specified element, when used with not") {
708
709        val caught1 = intercept[TestFailedException] {
710          mutable.HashSet(1, 2) should not contain (2)
711        }
712        assert(caught1.getMessage === "Set(1, 2) contained element 2")
713
714        val caught2 = intercept[TestFailedException] {
715          mutable.HashSet(1, 2) should not (contain (2))
716        }
717        assert(caught2.getMessage === "Set(1, 2) contained element 2")
718
719        val caught3 = intercept[TestFailedException] {
720          mutable.HashSet(1, 2) should (not contain (2))
721        }
722        assert(caught3.getMessage === "Set(1, 2) contained element 2")
723      }
724
725      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-and expression") {
726
727        val caught1 = intercept[TestFailedException] {
728          mutable.HashSet(1, 2) should { contain (5) and (contain (2 - 1)) }
729        }
730        assert(caught1.getMessage === "Set(1, 2) did not contain element 5")
731
732        val caught2 = intercept[TestFailedException] {
733          mutable.HashSet(1, 2) should (contain (5) and contain (2 - 1))
734        }
735        assert(caught2.getMessage === "Set(1, 2) did not contain element 5")
736      }
737
738      it("should throw a TestFailedException when set doesn't contain the specified element and used in a logical-or expression") {
739
740        val caught1 = intercept[TestFailedException] {
741          mutable.HashSet(1, 2) should { contain (55) or (contain (22)) }
742        }
743        assert(caught1.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
744
745        val caught2 = intercept[TestFailedException] {
746          mutable.HashSet(1, 2) should (contain (55) or contain (22))
747        }
748        assert(caught2.getMessage === "Set(1, 2) did not contain element 55, and Set(1, 2) did not contain element 22")
749      }
750
751      it("should throw a TestFailedException when set contains the specified element and used in a logical-and expression with not") {
752
753        val caught1 = intercept[TestFailedException] {
754          mutable.HashSet(1, 2) should { not { contain (3) } and not { contain (2) }}
755        }
756        assert(caught1.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
757
758        val caught2 = intercept[TestFailedException] {
759          mutable.HashSet(1, 2) should ((not contain (3)) and (not contain (2)))
760        }
761        assert(caught2.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
762
763        val caught3 = intercept[TestFailedException] {
764          mutable.HashSet(1, 2) should (not contain (3) and not contain (2))
765        }
766        assert(caught3.getMessage === "Set(1, 2) did not contain element 3, but Set(1, 2) contained element 2")
767      }
768
769      it("should throw a TestFailedException when set contains the specified element and used in a logical-or expression with not") {
770
771        val caught1 = intercept[TestFailedException] {
772          mutable.HashSet(1, 2) should { not { contain (2) } or not { contain (2) }}
773        }
774        assert(caught1.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
775
776        val caught2 = intercept[TestFailedException] {
777          mutable.HashSet(1, 2) should ((not contain (2)) or (not contain (2)))
778        }
779        assert(caught2.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
780
781        val caught3 = intercept[TestFailedException] {
782          mutable.HashSet(1, 2) should (not contain (2) or not contain (2))
783        }
784        assert(caught3.getMessage === "Set(1, 2) contained element 2, and Set(1, 2) contained element 2")
785      }
786    }
787
788    describe("on List") {
789
790      it("should do nothing if list contains the specified element") {
791        List(1, 2) should contain (2)
792        List(1, 2) should (contain (2))
793        check((list: List[Int]) => list.size != 0 ==> returnsNormally(list should contain (list(list.length - 1))))
794      }
795
796      it("should do nothing if list does not contain the element and used with should not") {
797        List(1, 2) should not { contain (3) }
798        List(1, 2) should not contain (3)
799        check((list: List[Int], i: Int) => !list.exists(_ == i) ==> returnsNormally(list should not { contain (i) }))
800        check((list: List[Int], i: Int) => !list.exists(_ == i) ==> returnsNormally(list should not contain (i)))
801      }
802
803      it("should do nothing when list contains the specified element and used in a logical-and expression") {
804        List(1, 2) should { contain (2) and (contain (1)) }
805        List(1, 2) should ((contain (2)) and (contain (1)))
806        List(1, 2) should (contain (2) and contain (1))
807       }
808
809      it("should do nothing when list contains the specified element and used in a logical-or expression") {
810        List(1, 2) should { contain (77) or (contain (2)) }
811        List(1, 2) should ((contain (77)) or (contain (2)))
812        List(1, 2) should (contain (77) or contain (2))
813      }
814
815      it("should do nothing when list doesn't contain the specified element and used in a logical-and expression with not") {
816        List(1, 2) should { not { contain (5) } and not { contain (3) }}
817        List(1, 2) should ((not contain (5)) and (not contain (3)))
818        List(1, 2) should (not contain (5) and not contain (3))
819      }
820
821      it("should do nothing when list doesn't contain the specified element and used in a logical-or expression with not") {
822        List(1, 2) should { not { contain (1) } or not { contain (3) }}
823        List(1, 2) should ((not contain (1)) or (not contain (3)))
824        List(1, 2) should (not contain (3) or not contain (2))
825      }
826
827      it("should throw TestFailedException if list does not contain the specified element") {
828        val caught = intercept[TestFailedException] {
829          List(1, 2) should contain (3)
830        }
831        assert(caught.getMessage === "List(1, 2) did not contain element 3")
832        check((list: List[String], s: String) => !list.exists(_ == s) ==> throwsTestFailedException(list should contain (s)))
833      }
834
835      it("should throw TestFailedException if list contains the specified element, when used with not") {
836
837        val caught1 = intercept[TestFailedException] {
838          List(1, 2) should not contain (2)
839        }
840        assert(caught1.getMessage === "List(1, 2) contained element 2")
841        check((list: List[String]) => list.length > 0 ==> throwsTestFailedException(list should not contain (list(0))))
842
843        val caught2 = intercept[TestFailedException] {
844          List(1, 2) should not (contain (2))
845        }
846        assert(caught2.getMessage === "List(1, 2) contained element 2")
847        check((list: List[String]) => list.length > 0 ==> throwsTestFailedException(list should not (contain (list(0)))))
848
849        val caught3 = intercept[TestFailedException] {
850          List(1, 2) should (not contain (2))
851        }
852        assert(caught3.getMessage === "List(1, 2) contained element 2")
853        check((list: List[String]) => list.length > 0 ==> throwsTestFailedException(list should not (contain (list(0)))))
854      }
855
856      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-and expression") {
857
858        val caught1 = intercept[TestFailedException] {
859          List(1, 2) should { contain (5) and (contain (2 - 1)) }
860        }
861        assert(caught1.getMessage === "List(1, 2) did not contain element 5")
862
863        val caught2 = intercept[TestFailedException] {
864          List(1, 2) should (contain (5) and contain (2 - 1))
865        }
866        assert(caught2.getMessage === "List(1, 2) did not contain element 5")
867      }
868
869      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-or expression") {
870
871        val caught1 = intercept[TestFailedException] {
872          List(1, 2) should { contain (55) or (contain (22)) }
873        }
874        assert(caught1.getMessage === "List(1, 2) did not contain element 55, and List(1, 2) did not contain element 22")
875
876        val caught2 = intercept[TestFailedException] {
877          List(1, 2) should (contain (55) or contain (22))
878        }
879        assert(caught2.getMessage === "List(1, 2) did not contain element 55, and List(1, 2) did not contain element 22")
880      }
881
882      it("should throw a TestFailedException when list contains the specified element and used in a logical-and expression with not") {
883
884        val caught1 = intercept[TestFailedException] {
885          List(1, 2) should { not { contain (3) } and not { contain (2) }}
886        }
887        assert(caught1.getMessage === "List(1, 2) did not contain element 3, but List(1, 2) contained element 2")
888
889        val caught2 = intercept[TestFailedException] {
890          List(1, 2) should ((not contain (3)) and (not contain (2)))
891        }
892        assert(caught2.getMessage === "List(1, 2) did not contain element 3, but List(1, 2) contained element 2")
893
894        val caught3 = intercept[TestFailedException] {
895          List(1, 2) should (not contain (3) and not contain (2))
896        }
897        assert(caught3.getMessage === "List(1, 2) did not contain element 3, but List(1, 2) contained element 2")
898      }
899
900      it("should throw a TestFailedException when list contains the specified element and used in a logical-or expression with not") {
901
902        val caught1 = intercept[TestFailedException] {
903          List(1, 2) should { not { contain (2) } or not { contain (2) }}
904        }
905        assert(caught1.getMessage === "List(1, 2) contained element 2, and List(1, 2) contained element 2")
906
907        val caught2 = intercept[TestFailedException] {
908          List(1, 2) should ((not contain (2)) or (not contain (2)))
909        }
910        assert(caught2.getMessage === "List(1, 2) contained element 2, and List(1, 2) contained element 2")
911
912        val caught3 = intercept[TestFailedException] {
913          List(1, 2) should (not contain (2) or not contain (2))
914        }
915        assert(caught3.getMessage === "List(1, 2) contained element 2, and List(1, 2) contained element 2")
916      }
917    }
918
919    describe("on java.util.List") {
920
921      val javaList: java.util.List[Int] = new java.util.ArrayList
922      javaList.add(1)
923      javaList.add(2)
924
925      it("should do nothing if list contains the specified element") {
926        javaList should contain (2)
927        javaList should (contain (2))
928      }
929
930      it("should do nothing if list does not contain the element and used with should not") {
931        javaList should (not contain (3))
932        javaList should not { contain (3) }
933        javaList should not contain (3)
934      }
935
936      it("should do nothing when list contains the specified element and used in a logical-and expression") {
937        javaList should { contain (2) and (contain (1)) }
938        javaList should ((contain (2)) and (contain (1)))
939        javaList should (contain (2) and contain (1))
940       }
941
942      it("should do nothing when list contains the specified element and used in a logical-or expression") {
943        javaList should { contain (77) or (contain (2)) }
944        javaList should ((contain (77)) or (contain (2)))
945        javaList should (contain (77) or contain (2))
946      }
947
948      it("should do nothing when list doesn't contain the specified element and used in a logical-and expression with not") {
949        javaList should { not { contain (5) } and not { contain (3) }}
950        javaList should ((not contain (5)) and (not contain (3)))
951        javaList should (not contain (5) and not contain (3))
952      }
953
954      it("should do nothing when list doesn't contain the specified element and used in a logical-or expression with not") {
955        javaList should { not { contain (1) } or not { contain (3) }}
956        javaList should ((not contain (1)) or (not contain (3)))
957        javaList should (not contain (3) or not contain (2))
958      }
959
960      it("should throw TestFailedException if list does not contain the specified element") {
961        val caught = intercept[TestFailedException] {
962          javaList should contain (3)
963        }
964        assert(caught.getMessage === "[1, 2] did not contain element 3")
965      }
966
967      it("should throw TestFailedException if list contains the specified element, when used with not") {
968
969        val caught1 = intercept[TestFailedException] {
970          javaList should not contain (2)
971        }
972        assert(caught1.getMessage === "[1, 2] contained element 2")
973
974        val caught2 = intercept[TestFailedException] {
975          javaList should not (contain (2))
976        }
977        assert(caught2.getMessage === "[1, 2] contained element 2")
978
979        val caught3 = intercept[TestFailedException] {
980          javaList should (not contain (2))
981        }
982        assert(caught3.getMessage === "[1, 2] contained element 2")
983      }
984
985      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-and expression") {
986
987        val caught1 = intercept[TestFailedException] {
988          javaList should { contain (5) and (contain (2 - 1)) }
989        }
990        assert(caught1.getMessage === "[1, 2] did not contain element 5")
991
992        val caught2 = intercept[TestFailedException] {
993          javaList should (contain (5) and contain (2 - 1))
994        }
995        assert(caught2.getMessage === "[1, 2] did not contain element 5")
996      }
997
998      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-or expression") {
999
1000        val caught1 = intercept[TestFailedException] {
1001          javaList should { contain (55) or (contain (22)) }
1002        }
1003        assert(caught1.getMessage === "[1, 2] did not contain element 55, and [1, 2] did not contain element 22")
1004
1005        val caught2 = intercept[TestFailedException] {
1006          javaList should (contain (55) or contain (22))
1007        }
1008        assert(caught2.getMessage === "[1, 2] did not contain element 55, and [1, 2] did not contain element 22")
1009      }
1010
1011      it("should throw a TestFailedException when list contains the specified element and used in a logical-and expression with not") {
1012
1013        val caught1 = intercept[TestFailedException] {
1014          javaList should { not { contain (3) } and not { contain (2) }}
1015        }
1016        assert(caught1.getMessage === "[1, 2] did not contain element 3, but [1, 2] contained element 2")
1017
1018        val caught2 = intercept[TestFailedException] {
1019          javaList should ((not contain (3)) and (not contain (2)))
1020        }
1021        assert(caught2.getMessage === "[1, 2] did not contain element 3, but [1, 2] contained element 2")
1022
1023        val caught3 = intercept[TestFailedException] {
1024          javaList should (not contain (3) and not contain (2))
1025        }
1026        assert(caught3.getMessage === "[1, 2] did not contain element 3, but [1, 2] contained element 2")
1027      }
1028
1029      it("should throw a TestFailedException when list contains the specified element and used in a logical-or expression with not") {
1030
1031        val caught1 = intercept[TestFailedException] {
1032          javaList should { not { contain (2) } or not { contain (2) }}
1033        }
1034        assert(caught1.getMessage === "[1, 2] contained element 2, and [1, 2] contained element 2")
1035
1036        val caught2 = intercept[TestFailedException] {
1037          javaList should ((not contain (2)) or (not contain (2)))
1038        }
1039        assert(caught2.getMessage === "[1, 2] contained element 2, and [1, 2] contained element 2")
1040
1041        val caught3 = intercept[TestFailedException] {
1042          javaList should (not contain (2) or not contain (2))
1043        }
1044        assert(caught3.getMessage === "[1, 2] contained element 2, and [1, 2] contained element 2")
1045      }
1046    }
1047
1048    describe("on scala.collection.immutable.Map") {
1049
1050      it("should do nothing if map contains specified element") {
1051        Map("one" -> 1, "two" -> 2) should contain ("two" -> 2)
1052        Map("one" -> 1, "two" -> 2) should (contain ("two" -> 2))
1053        Map(1 -> "one", 2 -> "two") should contain (2 -> "two")
1054      }
1055
1056      it("should do nothing if map does not contain the specified element and used with not") {
1057        Map("one" -> 1, "two" -> 2) should not { contain ("three" -> 3) }
1058        Map("one" -> 1, "two" -> 2) should not contain ("three" -> 3)
1059        Map("one" -> 1, "two" -> 2) should (not contain ("three" -> 3))
1060      }
1061
1062      it("should do nothing when map contains specified element and used in a logical-and expression") {
1063        Map("one" -> 1, "two" -> 2) should { contain ("two" -> 2) and (contain ("one" -> 1)) }
1064        Map("one" -> 1, "two" -> 2) should ((contain ("two" -> 2)) and (contain ("one" -> 1)))
1065        Map("one" -> 1, "two" -> 2) should (contain ("two" -> 2) and contain ("one" -> 1))
1066      }
1067
1068      it("should do nothing when map contains specified element and used in a logical-or expression") {
1069        Map("one" -> 1, "two" -> 2) should { contain ("cat" -> 77) or (contain ("one" -> 1)) }
1070        Map("one" -> 1, "two" -> 2) should ((contain ("cat" -> 77)) or (contain ("one" -> 1)))
1071        Map("one" -> 1, "two" -> 2) should (contain ("cat" -> 77) or contain ("one" -> 1))
1072      }
1073
1074      it("should do nothing when map does not contain the specified element and used in a logical-and expression with not") {
1075        Map("one" -> 1, "two" -> 2) should { not { contain ("five" -> 5) } and not { contain ("three" -> 3) }}
1076        Map("one" -> 1, "two" -> 2) should ((not contain ("five" -> 5)) and (not contain ("three" -> 3)))
1077        Map("one" -> 1, "two" -> 2) should (not contain ("five" -> 5) and not contain ("three" -> 3))
1078      }
1079
1080      it("should do nothing when map does not contain the specified element and used in a logical-or expression with not") {
1081        Map("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("three" -> 3) }}
1082        Map("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("three" -> 3)))
1083        Map("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("three" -> 3))
1084      }
1085
1086      it("should throw TestFailedException if map does not contain the specified element") {
1087        val caught1 = intercept[TestFailedException] {
1088          Map("one" -> 1, "two" -> 2) should contain ("three" -> 3)
1089        }
1090        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3)")
1091      }
1092
1093      it("should throw TestFailedException if contains the specified element when used with not") {
1094
1095        val caught1 = intercept[TestFailedException] {
1096          Map("one" -> 1, "two" -> 2) should (not contain ("two" -> 2))
1097        }
1098        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1099
1100        val caught2 = intercept[TestFailedException] {
1101          Map("one" -> 1, "two" -> 2) should not (contain ("two" -> 2))
1102        }
1103        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1104
1105        val caught3 = intercept[TestFailedException] {
1106          Map("one" -> 1, "two" -> 2) should not contain ("two" -> 2)
1107        }
1108        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1109      }
1110
1111      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-and expression") {
1112
1113        val caught1 = intercept[TestFailedException] {
1114          Map("one" -> 1, "two" -> 2) should { contain ("five" -> 5) and (contain ("two" -> 2)) }
1115        }
1116        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1117
1118        val caught2 = intercept[TestFailedException] {
1119          Map("one" -> 1, "two" -> 2) should ((contain ("five" -> 5)) and (contain ("two" -> 2)))
1120        }
1121        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1122
1123        val caught3 = intercept[TestFailedException] {
1124          Map("one" -> 1, "two" -> 2) should (contain ("five" -> 5) and contain ("two" -> 2))
1125        }
1126        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1127      }
1128
1129      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-or expression") {
1130
1131        val caught1 = intercept[TestFailedException] {
1132          Map("one" -> 1, "two" -> 2) should { contain ("fifty five" -> 55) or (contain ("twenty two" -> 22)) }
1133        }
1134        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1135
1136        val caught2 = intercept[TestFailedException] {
1137          Map("one" -> 1, "two" -> 2) should ((contain ("fifty five" -> 55)) or (contain ("twenty two" -> 22)))
1138        }
1139        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1140
1141        val caught3 = intercept[TestFailedException] {
1142          Map("one" -> 1, "two" -> 2) should (contain ("fifty five" -> 55) or contain ("twenty two" -> 22))
1143        }
1144        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1145      }
1146
1147      it("should throw an TestFailedException when map contains specified element and used in a logical-and expression with not") {
1148
1149        val caught1 = intercept[TestFailedException] {
1150          Map("one" -> 1, "two" -> 2) should { not { contain ("three" -> 3) } and not { contain ("two" -> 2) }}
1151        }
1152        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1153
1154        val caught2 = intercept[TestFailedException] {
1155          Map("one" -> 1, "two" -> 2) should ((not contain ("three" -> 3)) and (not contain ("two" -> 2)))
1156        }
1157        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1158
1159        val caught3 = intercept[TestFailedException] {
1160          Map("one" -> 1, "two" -> 2) should (not contain ("three" -> 3) and not contain ("two" -> 2))
1161        }
1162        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1163      }
1164
1165      it("should throw an TestFailedException when map contains specified element and used in a logical-or expression with not") {
1166
1167        val caught1 = intercept[TestFailedException] {
1168          Map("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("two" -> 2) }}
1169        }
1170        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1171
1172        val caught2 = intercept[TestFailedException] {
1173          Map("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("two" -> 2)))
1174        }
1175        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1176
1177        val caught3 = intercept[TestFailedException] {
1178          Map("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("two" -> 2))
1179        }
1180        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1181      }
1182    }
1183
1184    describe("on scala.collection.mutable.Map") {
1185
1186      import scala.collection.mutable
1187
1188      it("should do nothing if map contains specified element") {
1189        mutable.Map("one" -> 1, "two" -> 2) should contain ("two" -> 2)
1190        mutable.Map("one" -> 1, "two" -> 2) should (contain ("two" -> 2))
1191        mutable.Map(1 -> "one", 2 -> "two") should contain (2 -> "two")
1192      }
1193
1194      it("should do nothing if map does not contain the specified element and used with not") {
1195        mutable.Map("one" -> 1, "two" -> 2) should not { contain ("three" -> 3) }
1196        mutable.Map("one" -> 1, "two" -> 2) should not contain ("three" -> 3)
1197        mutable.Map("one" -> 1, "two" -> 2) should (not contain ("three" -> 3))
1198      }
1199
1200      it("should do nothing when map contains specified element and used in a logical-and expression") {
1201        mutable.Map("one" -> 1, "two" -> 2) should { contain ("two" -> 2) and (contain ("one" -> 1)) }
1202        mutable.Map("one" -> 1, "two" -> 2) should ((contain ("two" -> 2)) and (contain ("one" -> 1)))
1203        mutable.Map("one" -> 1, "two" -> 2) should (contain ("two" -> 2) and contain ("one" -> 1))
1204      }
1205
1206      it("should do nothing when map contains specified element and used in a logical-or expression") {
1207        mutable.Map("one" -> 1, "two" -> 2) should { contain ("cat" -> 77) or (contain ("one" -> 1)) }
1208        mutable.Map("one" -> 1, "two" -> 2) should ((contain ("cat" -> 77)) or (contain ("one" -> 1)))
1209        mutable.Map("one" -> 1, "two" -> 2) should (contain ("cat" -> 77) or contain ("one" -> 1))
1210      }
1211
1212      it("should do nothing when map does not contain the specified element and used in a logical-and expression with not") {
1213        mutable.Map("one" -> 1, "two" -> 2) should { not { contain ("five" -> 5) } and not { contain ("three" -> 3) }}
1214        mutable.Map("one" -> 1, "two" -> 2) should ((not contain ("five" -> 5)) and (not contain ("three" -> 3)))
1215        mutable.Map("one" -> 1, "two" -> 2) should (not contain ("five" -> 5) and not contain ("three" -> 3))
1216      }
1217
1218      it("should do nothing when map does not contain the specified element and used in a logical-or expression with not") {
1219        mutable.Map("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("three" -> 3) }}
1220        mutable.Map("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("three" -> 3)))
1221        mutable.Map("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("three" -> 3))
1222      }
1223
1224      it("should throw TestFailedException if map does not contain the specified element") {
1225        val caught1 = intercept[TestFailedException] {
1226          mutable.Map("one" -> 1, "two" -> 2) should contain ("three" -> 3)
1227        }
1228        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3)")
1229      }
1230
1231      it("should throw TestFailedException if contains the specified element when used with not") {
1232
1233        val caught1 = intercept[TestFailedException] {
1234          mutable.Map("one" -> 1, "two" -> 2) should (not contain ("two" -> 2))
1235        }
1236        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1237
1238        val caught2 = intercept[TestFailedException] {
1239          mutable.Map("one" -> 1, "two" -> 2) should not (contain ("two" -> 2))
1240        }
1241        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1242
1243        val caught3 = intercept[TestFailedException] {
1244          mutable.Map("one" -> 1, "two" -> 2) should not contain ("two" -> 2)
1245        }
1246        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1247      }
1248
1249      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-and expression") {
1250
1251        val caught1 = intercept[TestFailedException] {
1252          mutable.Map("one" -> 1, "two" -> 2) should { contain ("five" -> 5) and (contain ("two" -> 2)) }
1253        }
1254        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1255
1256        val caught2 = intercept[TestFailedException] {
1257          mutable.Map("one" -> 1, "two" -> 2) should ((contain ("five" -> 5)) and (contain ("two" -> 2)))
1258        }
1259        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1260
1261        val caught3 = intercept[TestFailedException] {
1262          mutable.Map("one" -> 1, "two" -> 2) should (contain ("five" -> 5) and contain ("two" -> 2))
1263        }
1264        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1265      }
1266
1267      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-or expression") {
1268
1269        val caught1 = intercept[TestFailedException] {
1270          mutable.Map("one" -> 1, "two" -> 2) should { contain ("fifty five" -> 55) or (contain ("twenty two" -> 22)) }
1271        }
1272        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1273
1274        val caught2 = intercept[TestFailedException] {
1275          mutable.Map("one" -> 1, "two" -> 2) should ((contain ("fifty five" -> 55)) or (contain ("twenty two" -> 22)))
1276        }
1277        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1278
1279        val caught3 = intercept[TestFailedException] {
1280          mutable.Map("one" -> 1, "two" -> 2) should (contain ("fifty five" -> 55) or contain ("twenty two" -> 22))
1281        }
1282        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1283      }
1284
1285      it("should throw an TestFailedException when map contains specified element and used in a logical-and expression with not") {
1286
1287        val caught1 = intercept[TestFailedException] {
1288          mutable.Map("one" -> 1, "two" -> 2) should { not { contain ("three" -> 3) } and not { contain ("two" -> 2) }}
1289        }
1290        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1291
1292        val caught2 = intercept[TestFailedException] {
1293          mutable.Map("one" -> 1, "two" -> 2) should ((not contain ("three" -> 3)) and (not contain ("two" -> 2)))
1294        }
1295        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1296
1297        val caught3 = intercept[TestFailedException] {
1298          mutable.Map("one" -> 1, "two" -> 2) should (not contain ("three" -> 3) and not contain ("two" -> 2))
1299        }
1300        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1301      }
1302
1303      it("should throw an TestFailedException when map contains specified element and used in a logical-or expression with not") {
1304
1305        val caught1 = intercept[TestFailedException] {
1306          mutable.Map("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("two" -> 2) }}
1307        }
1308        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1309
1310        val caught2 = intercept[TestFailedException] {
1311          mutable.Map("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("two" -> 2)))
1312        }
1313        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1314
1315        val caught3 = intercept[TestFailedException] {
1316          mutable.Map("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("two" -> 2))
1317        }
1318        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1319      }
1320    }
1321
1322    describe("on scala.collection.Map") {
1323
1324      val map: scala.collection.Map[String, Int] = Map("one" -> 1, "two" -> 2)
1325
1326      it("should do nothing if map contains specified element") {
1327        map should contain ("two" -> 2)
1328        map should (contain ("two" -> 2))
1329        map should contain ("two" -> 2)
1330      }
1331
1332      it("should do nothing if map does not contain the specified element and used with not") {
1333        map should not { contain ("three" -> 3) }
1334        map should not contain ("three" -> 3)
1335        map should (not contain ("three" -> 3))
1336      }
1337
1338      it("should do nothing when map contains specified element and used in a logical-and expression") {
1339        map should { contain ("two" -> 2) and (contain ("one" -> 1)) }
1340        map should ((contain ("two" -> 2)) and (contain ("one" -> 1)))
1341        map should (contain ("two" -> 2) and contain ("one" -> 1))
1342      }
1343
1344      it("should do nothing when map contains specified element and used in a logical-or expression") {
1345        map should { contain ("cat" -> 77) or (contain ("one" -> 1)) }
1346        map should ((contain ("cat" -> 77)) or (contain ("one" -> 1)))
1347        map should (contain ("cat" -> 77) or contain ("one" -> 1))
1348      }
1349
1350      it("should do nothing when map does not contain the specified element and used in a logical-and expression with not") {
1351        map should { not { contain ("five" -> 5) } and not { contain ("three" -> 3) }}
1352        map should ((not contain ("five" -> 5)) and (not contain ("three" -> 3)))
1353        map should (not contain ("five" -> 5) and not contain ("three" -> 3))
1354      }
1355
1356      it("should do nothing when map does not contain the specified element and used in a logical-or expression with not") {
1357        map should { not { contain ("two" -> 2) } or not { contain ("three" -> 3) }}
1358        map should ((not contain ("two" -> 2)) or (not contain ("three" -> 3)))
1359        map should (not contain ("two" -> 2) or not contain ("three" -> 3))
1360      }
1361
1362      it("should throw TestFailedException if map does not contain the specified element") {
1363        val caught1 = intercept[TestFailedException] {
1364          map should contain ("three" -> 3)
1365        }
1366        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3)")
1367      }
1368
1369      it("should throw TestFailedException if contains the specified element when used with not") {
1370
1371        val caught1 = intercept[TestFailedException] {
1372          map should (not contain ("two" -> 2))
1373        }
1374        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1375
1376        val caught2 = intercept[TestFailedException] {
1377          map should not (contain ("two" -> 2))
1378        }
1379        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1380
1381        val caught3 = intercept[TestFailedException] {
1382          map should not contain ("two" -> 2)
1383        }
1384        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1385      }
1386
1387      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-and expression") {
1388
1389        val caught1 = intercept[TestFailedException] {
1390          map should { contain ("five" -> 5) and (contain ("two" -> 2)) }
1391        }
1392        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1393
1394        val caught2 = intercept[TestFailedException] {
1395          map should ((contain ("five" -> 5)) and (contain ("two" -> 2)))
1396        }
1397        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1398
1399        val caught3 = intercept[TestFailedException] {
1400          map should (contain ("five" -> 5) and contain ("two" -> 2))
1401        }
1402        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1403      }
1404
1405      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-or expression") {
1406
1407        val caught1 = intercept[TestFailedException] {
1408          map should { contain ("fifty five" -> 55) or (contain ("twenty two" -> 22)) }
1409        }
1410        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1411
1412        val caught2 = intercept[TestFailedException] {
1413          map should ((contain ("fifty five" -> 55)) or (contain ("twenty two" -> 22)))
1414        }
1415        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1416
1417        val caught3 = intercept[TestFailedException] {
1418          map should (contain ("fifty five" -> 55) or contain ("twenty two" -> 22))
1419        }
1420        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1421      }
1422
1423      it("should throw an TestFailedException when map contains specified element and used in a logical-and expression with not") {
1424
1425        val caught1 = intercept[TestFailedException] {
1426          map should { not { contain ("three" -> 3) } and not { contain ("two" -> 2) }}
1427        }
1428        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1429
1430        val caught2 = intercept[TestFailedException] {
1431          map should ((not contain ("three" -> 3)) and (not contain ("two" -> 2)))
1432        }
1433        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1434
1435        val caught3 = intercept[TestFailedException] {
1436          map should (not contain ("three" -> 3) and not contain ("two" -> 2))
1437        }
1438        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1439      }
1440
1441      it("should throw an TestFailedException when map contains specified element and used in a logical-or expression with not") {
1442
1443        val caught1 = intercept[TestFailedException] {
1444          map should { not { contain ("two" -> 2) } or not { contain ("two" -> 2) }}
1445        }
1446        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1447
1448        val caught2 = intercept[TestFailedException] {
1449          map should ((not contain ("two" -> 2)) or (not contain ("two" -> 2)))
1450        }
1451        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1452
1453        val caught3 = intercept[TestFailedException] {
1454          map should (not contain ("two" -> 2) or not contain ("two" -> 2))
1455        }
1456        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1457      }
1458    }
1459
1460    describe("on scala.collection.immutable.HashMap") {
1461
1462      import scala.collection.immutable.HashMap
1463
1464      it("should do nothing if map contains specified element") {
1465        HashMap("one" -> 1, "two" -> 2) should contain ("two" -> 2)
1466        HashMap("one" -> 1, "two" -> 2) should (contain ("two" -> 2))
1467        HashMap(1 -> "one", 2 -> "two") should contain (2 -> "two")
1468      }
1469
1470      it("should do nothing if map does not contain the specified element and used with not") {
1471        HashMap("one" -> 1, "two" -> 2) should not { contain ("three" -> 3) }
1472        HashMap("one" -> 1, "two" -> 2) should not contain ("three" -> 3)
1473        HashMap("one" -> 1, "two" -> 2) should (not contain ("three" -> 3))
1474      }
1475
1476      it("should do nothing when map contains specified element and used in a logical-and expression") {
1477        HashMap("one" -> 1, "two" -> 2) should { contain ("two" -> 2) and (contain ("one" -> 1)) }
1478        HashMap("one" -> 1, "two" -> 2) should ((contain ("two" -> 2)) and (contain ("one" -> 1)))
1479        HashMap("one" -> 1, "two" -> 2) should (contain ("two" -> 2) and contain ("one" -> 1))
1480      }
1481
1482      it("should do nothing when map contains specified element and used in a logical-or expression") {
1483        HashMap("one" -> 1, "two" -> 2) should { contain ("cat" -> 77) or (contain ("one" -> 1)) }
1484        HashMap("one" -> 1, "two" -> 2) should ((contain ("cat" -> 77)) or (contain ("one" -> 1)))
1485        HashMap("one" -> 1, "two" -> 2) should (contain ("cat" -> 77) or contain ("one" -> 1))
1486      }
1487
1488      it("should do nothing when map does not contain the specified element and used in a logical-and expression with not") {
1489        HashMap("one" -> 1, "two" -> 2) should { not { contain ("five" -> 5) } and not { contain ("three" -> 3) }}
1490        HashMap("one" -> 1, "two" -> 2) should ((not contain ("five" -> 5)) and (not contain ("three" -> 3)))
1491        HashMap("one" -> 1, "two" -> 2) should (not contain ("five" -> 5) and not contain ("three" -> 3))
1492      }
1493
1494      it("should do nothing when map does not contain the specified element and used in a logical-or expression with not") {
1495        HashMap("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("three" -> 3) }}
1496        HashMap("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("three" -> 3)))
1497        HashMap("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("three" -> 3))
1498      }
1499
1500      it("should throw TestFailedException if map does not contain the specified element") {
1501        val caught1 = intercept[TestFailedException] {
1502          HashMap("one" -> 1, "two" -> 2) should contain ("three" -> 3)
1503        }
1504        assert(caught1.getMessage.startsWith("Map("))
1505        assert(caught1.getMessage.endsWith(") did not contain element (three,3)"))
1506      }
1507
1508      it("should throw TestFailedException if contains the specified element when used with not") {
1509
1510        val caught1 = intercept[TestFailedException] {
1511          HashMap("one" -> 1, "two" -> 2) should (not contain ("two" -> 2))
1512        }
1513        assert(caught1.getMessage.startsWith("Map("))
1514        assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1515
1516
1517        val caught2 = intercept[TestFailedException] {
1518          HashMap("one" -> 1, "two" -> 2) should not (contain ("two" -> 2))
1519        }
1520        assert(caught1.getMessage.startsWith("Map("))
1521        assert(caught1.getMessage.endsWith(" contained element (two,2)"))
1522
1523
1524        val caught3 = intercept[TestFailedException] {
1525          HashMap("one" -> 1, "two" -> 2) should not contain ("two" -> 2)
1526        }
1527        assert(caught1.getMessage.startsWith("Map("))
1528        assert(caught1.getMessage.endsWith(" contained element (two,2)"))
1529      }
1530
1531      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-and expression") {
1532
1533        val caught1 = intercept[TestFailedException] {
1534          HashMap("one" -> 1, "two" -> 2) should { contain ("five" -> 5) and (contain ("two" -> 2)) }
1535        }
1536        assert(caught1.getMessage.startsWith("Map("))
1537        assert(caught1.getMessage.endsWith(" did not contain element (five,5)"))
1538
1539        val caught2 = intercept[TestFailedException] {
1540          HashMap("one" -> 1, "two" -> 2) should ((contain ("five" -> 5)) and (contain ("two" -> 2)))
1541        }
1542        assert(caught1.getMessage.startsWith("Map("))
1543        assert(caught1.getMessage.endsWith(" did not contain element (five,5)"))
1544
1545        val caught3 = intercept[TestFailedException] {
1546          HashMap("one" -> 1, "two" -> 2) should (contain ("five" -> 5) and contain ("two" -> 2))
1547        }
1548        assert(caught1.getMessage.startsWith("Map("))
1549        assert(caught1.getMessage.endsWith(" did not contain element (five,5)"))
1550      }
1551
1552      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-or expression") {
1553
1554        val caught1 = intercept[TestFailedException] {
1555          HashMap("one" -> 1, "two" -> 2) should { contain ("fifty five" -> 55) or (contain ("twenty two" -> 22)) }
1556        }
1557        assert(caught1.getMessage.startsWith("Map("))
1558        assert(caught1.getMessage.contains(") did not contain element (fifty five,55), and Map("))
1559        assert(caught1.getMessage.endsWith(") did not contain element (twenty two,22)"))
1560
1561        val caught2 = intercept[TestFailedException] {
1562          HashMap("one" -> 1, "two" -> 2) should ((contain ("fifty five" -> 55)) or (contain ("twenty two" -> 22)))
1563        }
1564        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1565        assert(caught1.getMessage.startsWith("Map("))
1566        assert(caught1.getMessage.contains(") did not contain element (fifty five,55), and Map("))
1567        assert(caught1.getMessage.endsWith(") did not contain element (twenty two,22)"))
1568
1569        val caught3 = intercept[TestFailedException] {
1570          HashMap("one" -> 1, "two" -> 2) should (contain ("fifty five" -> 55) or contain ("twenty two" -> 22))
1571        }
1572        //assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1573        assert(caught1.getMessage.startsWith("Map("))
1574        assert(caught1.getMessage.contains(") did not contain element (fifty five,55), and Map("))
1575        assert(caught1.getMessage.endsWith(") did not contain element (twenty two,22)"))
1576      }
1577
1578      it("should throw an TestFailedException when map contains specified element and used in a logical-and expression with not") {
1579
1580        val caught1 = intercept[TestFailedException] {
1581          HashMap("one" -> 1, "two" -> 2) should { not { contain ("three" -> 3) } and not { contain ("two" -> 2) }}
1582        }
1583        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1584        assert(caught1.getMessage.startsWith("Map("))
1585        assert(caught1.getMessage.contains(") did not contain element (three,3), but Map("))
1586        assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1587
1588        val caught2 = intercept[TestFailedException] {
1589          HashMap("one" -> 1, "two" -> 2) should ((not contain ("three" -> 3)) and (not contain ("two" -> 2)))
1590        }
1591        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1592        assert(caught1.getMessage.startsWith("Map("))
1593        assert(caught1.getMessage.contains(") did not contain element (three,3), but Map("))
1594        assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1595
1596        val caught3 = intercept[TestFailedException] {
1597          HashMap("one" -> 1, "two" -> 2) should (not contain ("three" -> 3) and not contain ("two" -> 2))
1598        }
1599        //assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1600        assert(caught1.getMessage.startsWith("Map("))
1601        assert(caught1.getMessage.contains(") did not contain element (three,3), but Map("))
1602        assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1603      }
1604
1605      it("should throw an TestFailedException when map contains specified element and used in a logical-or expression with not") {
1606
1607        val caught1 = intercept[TestFailedException] {
1608          HashMap("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("two" -> 2) }}
1609        }
1610        //assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1611        assert(caught1.getMessage.startsWith("Map("))
1612        assert(caught1.getMessage.contains(" contained element (two,2), and Map("))
1613        assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1614
1615        val caught2 = intercept[TestFailedException] {
1616          HashMap("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("two" -> 2)))
1617        }
1618        //assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1619        assert(caught1.getMessage.startsWith("Map("))
1620        assert(caught1.getMessage.contains(" contained element (two,2), and Map("))
1621        assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1622
1623        val caught3 = intercept[TestFailedException] {
1624          HashMap("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("two" -> 2))
1625        }
1626        //assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1627        assert(caught1.getMessage.startsWith("Map("))
1628        assert(caught1.getMessage.contains(" contained element (two,2), and Map("))
1629        assert(caught1.getMessage.endsWith(") contained element (two,2)"))
1630      }
1631    }
1632
1633    describe("on scala.collection.mutable.HashMap") {
1634
1635      import scala.collection.mutable
1636
1637      it("should do nothing if map contains specified element") {
1638        mutable.HashMap("one" -> 1, "two" -> 2) should contain ("two" -> 2)
1639        mutable.HashMap("one" -> 1, "two" -> 2) should (contain ("two" -> 2))
1640        mutable.HashMap(1 -> "one", 2 -> "two") should contain (2 -> "two")
1641      }
1642
1643      it("should do nothing if map does not contain the specified element and used with not") {
1644        mutable.HashMap("one" -> 1, "two" -> 2) should not { contain ("three" -> 3) }
1645        mutable.HashMap("one" -> 1, "two" -> 2) should not contain ("three" -> 3)
1646        mutable.HashMap("one" -> 1, "two" -> 2) should (not contain ("three" -> 3))
1647      }
1648
1649      it("should do nothing when map contains specified element and used in a logical-and expression") {
1650        mutable.HashMap("one" -> 1, "two" -> 2) should { contain ("two" -> 2) and (contain ("one" -> 1)) }
1651        mutable.HashMap("one" -> 1, "two" -> 2) should ((contain ("two" -> 2)) and (contain ("one" -> 1)))
1652        mutable.HashMap("one" -> 1, "two" -> 2) should (contain ("two" -> 2) and contain ("one" -> 1))
1653      }
1654
1655      it("should do nothing when map contains specified element and used in a logical-or expression") {
1656        mutable.HashMap("one" -> 1, "two" -> 2) should { contain ("cat" -> 77) or (contain ("one" -> 1)) }
1657        mutable.HashMap("one" -> 1, "two" -> 2) should ((contain ("cat" -> 77)) or (contain ("one" -> 1)))
1658        mutable.HashMap("one" -> 1, "two" -> 2) should (contain ("cat" -> 77) or contain ("one" -> 1))
1659      }
1660
1661      it("should do nothing when map does not contain the specified element and used in a logical-and expression with not") {
1662        mutable.HashMap("one" -> 1, "two" -> 2) should { not { contain ("five" -> 5) } and not { contain ("three" -> 3) }}
1663        mutable.HashMap("one" -> 1, "two" -> 2) should ((not contain ("five" -> 5)) and (not contain ("three" -> 3)))
1664        mutable.HashMap("one" -> 1, "two" -> 2) should (not contain ("five" -> 5) and not contain ("three" -> 3))
1665      }
1666
1667      it("should do nothing when map does not contain the specified element and used in a logical-or expression with not") {
1668        mutable.HashMap("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("three" -> 3) }}
1669        mutable.HashMap("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("three" -> 3)))
1670        mutable.HashMap("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("three" -> 3))
1671      }
1672
1673      it("should throw TestFailedException if map does not contain the specified element") {
1674        val caught1 = intercept[TestFailedException] {
1675          mutable.HashMap("one" -> 1, "two" -> 2) should contain ("three" -> 3)
1676        }
1677        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3)")
1678      }
1679
1680      it("should throw TestFailedException if contains the specified element when used with not") {
1681
1682        val caught1 = intercept[TestFailedException] {
1683          mutable.HashMap("one" -> 1, "two" -> 2) should (not contain ("two" -> 2))
1684        }
1685        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1686
1687        val caught2 = intercept[TestFailedException] {
1688          mutable.HashMap("one" -> 1, "two" -> 2) should not (contain ("two" -> 2))
1689        }
1690        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1691
1692        val caught3 = intercept[TestFailedException] {
1693          mutable.HashMap("one" -> 1, "two" -> 2) should not contain ("two" -> 2)
1694        }
1695        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2)")
1696      }
1697
1698      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-and expression") {
1699
1700        val caught1 = intercept[TestFailedException] {
1701          mutable.HashMap("one" -> 1, "two" -> 2) should { contain ("five" -> 5) and (contain ("two" -> 2)) }
1702        }
1703        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1704
1705        val caught2 = intercept[TestFailedException] {
1706          mutable.HashMap("one" -> 1, "two" -> 2) should ((contain ("five" -> 5)) and (contain ("two" -> 2)))
1707        }
1708        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1709
1710        val caught3 = intercept[TestFailedException] {
1711          mutable.HashMap("one" -> 1, "two" -> 2) should (contain ("five" -> 5) and contain ("two" -> 2))
1712        }
1713        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (five,5)")
1714      }
1715
1716      it("should throw an TestFailedException when map doesn't contain specified element and used in a logical-or expression") {
1717
1718        val caught1 = intercept[TestFailedException] {
1719          mutable.HashMap("one" -> 1, "two" -> 2) should { contain ("fifty five" -> 55) or (contain ("twenty two" -> 22)) }
1720        }
1721        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1722
1723        val caught2 = intercept[TestFailedException] {
1724          mutable.HashMap("one" -> 1, "two" -> 2) should ((contain ("fifty five" -> 55)) or (contain ("twenty two" -> 22)))
1725        }
1726        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1727
1728        val caught3 = intercept[TestFailedException] {
1729          mutable.HashMap("one" -> 1, "two" -> 2) should (contain ("fifty five" -> 55) or contain ("twenty two" -> 22))
1730        }
1731        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (fifty five,55), and Map(one -> 1, two -> 2) did not contain element (twenty two,22)")
1732      }
1733
1734      it("should throw an TestFailedException when map contains specified element and used in a logical-and expression with not") {
1735
1736        val caught1 = intercept[TestFailedException] {
1737          mutable.HashMap("one" -> 1, "two" -> 2) should { not { contain ("three" -> 3) } and not { contain ("two" -> 2) }}
1738        }
1739        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1740
1741        val caught2 = intercept[TestFailedException] {
1742          mutable.HashMap("one" -> 1, "two" -> 2) should ((not contain ("three" -> 3)) and (not contain ("two" -> 2)))
1743        }
1744        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1745
1746        val caught3 = intercept[TestFailedException] {
1747          mutable.HashMap("one" -> 1, "two" -> 2) should (not contain ("three" -> 3) and not contain ("two" -> 2))
1748        }
1749        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not contain element (three,3), but Map(one -> 1, two -> 2) contained element (two,2)")
1750      }
1751
1752      it("should throw an TestFailedException when map contains specified element and used in a logical-or expression with not") {
1753
1754        val caught1 = intercept[TestFailedException] {
1755          mutable.HashMap("one" -> 1, "two" -> 2) should { not { contain ("two" -> 2) } or not { contain ("two" -> 2) }}
1756        }
1757        assert(caught1.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1758
1759        val caught2 = intercept[TestFailedException] {
1760          mutable.HashMap("one" -> 1, "two" -> 2) should ((not contain ("two" -> 2)) or (not contain ("two" -> 2)))
1761        }
1762        assert(caught2.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1763
1764        val caught3 = intercept[TestFailedException] {
1765          mutable.HashMap("one" -> 1, "two" -> 2) should (not contain ("two" -> 2) or not contain ("two" -> 2))
1766        }
1767        assert(caught3.getMessage === "Map(one -> 1, two -> 2) contained element (two,2), and Map(one -> 1, two -> 2) contained element (two,2)")
1768      }
1769    }
1770
1771    describe("on java.util.Set") {
1772
1773      val javaSet: java.util.Set[Int] = new java.util.HashSet
1774      javaSet.add(1)
1775      javaSet.add(2)
1776
1777      it("should do nothing if list contains the specified element") {
1778        javaSet should contain (2)
1779        javaSet should (contain (2))
1780      }
1781
1782      it("should do nothing if list does not contain the element and used with should not") {
1783        javaSet should (not contain (3))
1784        javaSet should not { contain (3) }
1785        javaSet should not contain (3)
1786      }
1787
1788      it("should do nothing when list contains the specified element and used in a logical-and expression") {
1789        javaSet should { contain (2) and (contain (1)) }
1790        javaSet should ((contain (2)) and (contain (1)))
1791        javaSet should (contain (2) and contain (1))
1792       }
1793
1794      it("should do nothing when list contains the specified element and used in a logical-or expression") {
1795        javaSet should { contain (77) or (contain (2)) }
1796        javaSet should ((contain (77)) or (contain (2)))
1797        javaSet should (contain (77) or contain (2))
1798      }
1799
1800      it("should do nothing when list doesn't contain the specified element and used in a logical-and expression with not") {
1801        javaSet should { not { contain (5) } and not { contain (3) }}
1802        javaSet should ((not contain (5)) and (not contain (3)))
1803        javaSet should (not contain (5) and not contain (3))
1804      }
1805
1806      it("should do nothing when list doesn't contain the specified element and used in a logical-or expression with not") {
1807        javaSet should { not { contain (1) } or not { contain (3) }}
1808        javaSet should ((not contain (1)) or (not contain (3)))
1809        javaSet should (not contain (3) or not contain (2))
1810      }
1811
1812      it("should throw TestFailedException if list does not contain the specified element") {
1813        val caught = intercept[TestFailedException] {
1814          javaSet should contain (3)
1815        }
1816        assert(caught.getMessage endsWith "] did not contain element 3")
1817      }
1818
1819      it("should throw TestFailedException if list contains the specified element, when used with not") {
1820
1821        val caught1 = intercept[TestFailedException] {
1822          javaSet should not contain (2)
1823        }
1824        assert(caught1.getMessage endsWith "] contained element 2")
1825
1826        val caught2 = intercept[TestFailedException] {
1827          javaSet should not (contain (2))
1828        }
1829        assert(caught2.getMessage endsWith "] contained element 2")
1830
1831        val caught3 = intercept[TestFailedException] {
1832          javaSet should (not contain (2))
1833        }
1834        assert(caught3.getMessage endsWith "] contained element 2")
1835      }
1836
1837      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-and expression") {
1838
1839        val caught1 = intercept[TestFailedException] {
1840          javaSet should { contain (5) and (contain (2 - 1)) }
1841        }
1842        assert(caught1.getMessage endsWith "] did not contain element 5")
1843
1844        val caught2 = intercept[TestFailedException] {
1845          javaSet should (contain (5) and contain (2 - 1))
1846        }
1847        assert(caught2.getMessage endsWith "] did not contain element 5")
1848      }
1849
1850      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-or expression") {
1851
1852        val caught1 = intercept[TestFailedException] {
1853          javaSet should { contain (55) or (contain (22)) }
1854        }
1855        assert(caught1.getMessage endsWith "] did not contain element 22")
1856        assert(caught1.getMessage.indexOf("] did not contain element 55, and [") != -1)
1857
1858        val caught2 = intercept[TestFailedException] {
1859          javaSet should (contain (55) or contain (22))
1860        }
1861        assert(caught1.getMessage endsWith "] did not contain element 22")
1862        assert(caught1.getMessage.indexOf("] did not contain element 55, and [") != -1)
1863        // assert(caught2.getMessage === "[2, 1] did not contain element 55, and [2, 1] did not contain element 22")
1864      }
1865
1866      it("should throw a TestFailedException when list contains the specified element and used in a logical-and expression with not") {
1867
1868        val caught1 = intercept[TestFailedException] {
1869          javaSet should { not { contain (3) } and not { contain (2) }}
1870        }
1871        assert(caught1.getMessage endsWith "] contained element 2")
1872        assert(caught1.getMessage.indexOf("] did not contain element 3, but [") != -1)
1873        // assert(caught1.getMessage === "[2, 1] did not contain element 3, but [2, 1] contained element 2")
1874
1875        val caught2 = intercept[TestFailedException] {
1876          javaSet should ((not contain (3)) and (not contain (2)))
1877        }
1878        assert(caught1.getMessage endsWith "] contained element 2")
1879        assert(caught1.getMessage.indexOf("] did not contain element 3, but [") != -1)
1880        // assert(caught2.getMessage === "[2, 1] did not contain element 3, but [2, 1] contained element 2")
1881
1882        val caught3 = intercept[TestFailedException] {
1883          javaSet should (not contain (3) and not contain (2))
1884        }
1885        assert(caught1.getMessage endsWith "] contained element 2")
1886        assert(caught1.getMessage.indexOf("] did not contain element 3, but [") != -1)
1887        // assert(caught3.getMessage === "[2, 1] did not contain element 3, but [2, 1] contained element 2")
1888      }
1889
1890      it("should throw a TestFailedException when list contains the specified element and used in a logical-or expression with not") {
1891
1892        val caught1 = intercept[TestFailedException] {
1893          javaSet should { not { contain (2) } or not { contain (2) }}
1894        }
1895        assert(caught1.getMessage endsWith "] contained element 2")
1896        assert(caught1.getMessage.indexOf("] contained element 2, and [") != -1)
1897        // assert(caught1.getMessage === "[2, 1] contained element 2, and [2, 1] contained element 2")
1898
1899        val caught2 = intercept[TestFailedException] {
1900          javaSet should ((not contain (2)) or (not contain (2)))
1901        }
1902        assert(caught1.getMessage endsWith "] contained element 2")
1903        assert(caught1.getMessage.indexOf("] contained element 2, and [") != -1)
1904        // assert(caught2.getMessage === "[2, 1] contained element 2, and [2, 1] contained element 2")
1905
1906        val caught3 = intercept[TestFailedException] {
1907          javaSet should (not contain (2) or not contain (2))
1908        }
1909        assert(caught1.getMessage endsWith "] contained element 2")
1910        assert(caught1.getMessage.indexOf("] contained element 2, and [") != -1)
1911        // assert(caught3.getMessage === "[2, 1] contained element 2, and [2, 1] contained element 2")
1912      }
1913    }
1914
1915/*
1916    I'm just not going to support this for now. Let them do whatever, and when someone
1917    comes back with a good suggestion, then I can consider adding it.
1918
1919    describe("on java.util.Map") {
1920
1921      val javaMap: java.util.Map[String, Int] = new java.util.HashMap
1922      javaMap.put("one",1)
1923      javaMap.put("two", 2)
1924
1925      import java.util.Map.Entry
1926
1927      it("should do nothing if list contains the specified element") {
1928        javaMap.entrySet should contain ("one" -> 1)
1929        javaMap.entrySet should (contain ("two" -> 2))
1930      }
1931
1932      it("should do nothing if list does not contain the element and used with should not") {
1933        javaMap should (not contain (3))
1934        javaMap should not { contain (3) }
1935        javaMap should not contain (3)
1936      }
1937
1938      it("should do nothing when list contains the specified element and used in a logical-and expression") {
1939        javaMap should { contain (2) and (contain (1)) }
1940        javaMap should ((contain (2)) and (contain (1)))
1941        javaMap should (contain (2) and contain (1))
1942       }
1943
1944      it("should do nothing when list contains the specified element and used in a logical-or expression") {
1945        javaMap should { contain (77) or (contain (2)) }
1946        javaMap should ((contain (77)) or (contain (2)))
1947        javaMap should (contain (77) or contain (2))
1948      }
1949
1950      it("should do nothing when list doesn't contain the specified element and used in a logical-and expression with not") {
1951        javaMap should { not { contain (5) } and not { contain (3) }}
1952        javaMap should ((not contain (5)) and (not contain (3)))
1953        javaMap should (not contain (5) and not contain (3))
1954      }
1955
1956      it("should do nothing when list doesn't contain the specified element and used in a logical-or expression with not") {
1957        javaMap should { not { contain (1) } or not { contain (3) }}
1958        javaMap should ((not contain (1)) or (not contain (3)))
1959        javaMap should (not contain (3) or not contain (2))
1960      }
1961
1962      it("should throw TestFailedException if list does not contain the specified element") {
1963        val caught = intercept[TestFailedException] {
1964          javaMap should contain (3)
1965        }
1966        assert(caught.getMessage === "{one=1, two=2} did not contain element 3")
1967      }
1968
1969      it("should throw TestFailedException if list contains the specified element, when used with not") {
1970
1971        val caught1 = intercept[TestFailedException] {
1972          javaMap should not contain (2)
1973        }
1974        assert(caught1.getMessage === "{one=1, two=2} contained element 2")
1975
1976        val caught2 = intercept[TestFailedException] {
1977          javaMap should not (contain (2))
1978        }
1979        assert(caught2.getMessage === "{one=1, two=2} contained element 2")
1980
1981        val caught3 = intercept[TestFailedException] {
1982          javaMap should (not contain (2))
1983        }
1984        assert(caught3.getMessage === "{one=1, two=2} contained element 2")
1985      }
1986
1987      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-and expression") {
1988
1989        val caught1 = intercept[TestFailedException] {
1990          javaMap should { contain (5) and (contain (2 - 1)) }
1991        }
1992        assert(caught1.getMessage === "{one=1, two=2} did not contain element 5")
1993
1994        val caught2 = intercept[TestFailedException] {
1995          javaMap should (contain (5) and contain (2 - 1))
1996        }
1997        assert(caught2.getMessage === "{one=1, two=2} did not contain element 5")
1998      }
1999
2000      it("should throw a TestFailedException when list doesn't contain the specified element and used in a logical-or expression") {
2001
2002        val caught1 = intercept[TestFailedException] {
2003          javaMap should { contain (55) or (contain (22)) }
2004        }
2005        assert(caught1.getMessage === "{one=1, two=2} did not contain element 55, and {one=1, two=2} did not contain element 22")
2006
2007        val caught2 = intercept[TestFailedException] {
2008          javaMap should (contain (55) or contain (22))
2009        }
2010        assert(caught2.getMessage === "{one=1, two=2} did not contain element 55, and {one=1, two=2} did not contain element 22")
2011      }
2012
2013      it("should throw a TestFailedException when list contains the specified element and used in a logical-and expression with not") {
2014
2015        val caught1 = intercept[TestFailedException] {
2016          javaMap should { not { contain (3) } and not { contain (2) }}
2017        }
2018        assert(caught1.getMessage === "{one=1, two=2} did not contain element 3, but {one=1, two=2} contained element 2")
2019
2020        val caught2 = intercept[TestFailedException] {
2021          javaMap should ((not contain (3)) and (not contain (2)))
2022        }
2023        assert(caught2.getMessage === "{one=1, two=2} did not contain element 3, but {one=1, two=2} contained element 2")
2024
2025        val caught3 = intercept[TestFailedException] {
2026          javaMap should (not contain (3) and not contain (2))
2027        }
2028        assert(caught3.getMessage === "{one=1, two=2} did not contain element 3, but {one=1, two=2} contained element 2")
2029      }
2030
2031      it("should throw a TestFailedException when list contains the specified element and used in a logical-or expression with not") {
2032
2033        val caught1 = intercept[TestFailedException] {
2034          javaMap should { not { contain (2) } or not { contain (2) }}
2035        }
2036        assert(caught1.getMessage === "{one=1, two=2} contained element 2, and {one=1, two=2} contained element 2")
2037
2038        val caught2 = intercept[TestFailedException] {
2039          javaMap should ((not contain (2)) or (not contain (2)))
2040        }
2041        assert(caught2.getMessage === "{one=1, two=2} contained element 2, and {one=1, two=2} contained element 2")
2042
2043        val caught3 = intercept[TestFailedException] {
2044          javaMap should (not contain (2) or not contain (2))
2045        }
2046        assert(caught3.getMessage === "{one=1, two=2} contained element 2, and {one=1, two=2} contained element 2")
2047      }
2048    }
2049*/
2050  }
2051}
2052