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._
23import Integer.MIN_VALUE
24
25class ShouldSizeSpec extends Spec with ShouldMatchers with Checkers with ReturnsNormallyThrowsAssertion {
26
27  // Checking for a specific size
28  describe("The 'have size (Int)' syntax") {
29
30    describe("on Array") {
31
32      it("should do nothing if array size matches specified size") {
33        Array(1, 2) should have size (2)
34        // check((arr: Array[Int]) => returnsNormally(arr should have size (arr.size)))
35      }
36
37      it("should do nothing if array size does not match and used with should not") {
38        Array(1, 2) should not { have size (3) }
39        Array(1, 2) should not have size (3)
40        // check((arr: Array[Int], i: Int) => i != arr.size ==> returnsNormally(arr should not { have size (i) }))
41        // check((arr: Array[Int], i: Int) => i != arr.size ==> returnsNormally(arr should not have size (i)))
42      }
43
44      it("should do nothing when array size matches and used in a logical-and expression") {
45        Array(1, 2) should { have size (2) and (have size (3 - 1)) }
46        Array(1, 2) should ((have size (2)) and (have size (3 - 1)))
47        Array(1, 2) should (have size (2) and have size (3 - 1))
48      }
49
50      it("should do nothing when array size matches and used in a logical-or expression") {
51        Array(1, 2) should { have size (77) or (have size (3 - 1)) }
52        Array(1, 2) should ((have size (77)) or (have size (3 - 1)))
53        Array(1, 2) should (have size (77) or have size (3 - 1))
54      }
55
56      it("should do nothing when array size doesn't match and used in a logical-and expression with not") {
57        Array(1, 2) should { not { have size (5) } and not { have size (3) }}
58        Array(1, 2) should ((not have size (5)) and (not have size (3)))
59        Array(1, 2) should (not have size (5) and not have size (3))
60      }
61
62      it("should do nothing when array size doesn't match and used in a logical-or expression with not") {
63        Array(1, 2) should { not { have size (2) } or not { have size (3) }}
64        Array(1, 2) should ((not have size (2)) or (not have size (3)))
65        Array(1, 2) should (not have size (2) or not have size (3))
66      }
67
68      it("should throw TestFailedException if array size does not match specified size") {
69        val caught1 = intercept[TestFailedException] {
70          Array(1, 2) should have size (3)
71        }
72        assert(caught1.getMessage endsWith "Array(1, 2) did not have size 3")
73        // check((arr: Array[String]) => throwsTestFailedException(arr should have size (arr.size + 1)))
74      }
75
76      it("should throw TestFailedException with normal error message if specified size is negative") {
77        val caught1 = intercept[TestFailedException] {
78          Array(1, 2) should have size (-2)
79        }
80        assert(caught1.getMessage endsWith "Array(1, 2) did not have size -2")
81        // check((arr: Array[Int]) => throwsTestFailedException(arr should have size (if (arr.size == 0) -1 else -arr.size)))
82      }
83
84      it("should throw an assertion error when array size doesn't match and used in a logical-and expression") {
85
86        val caught1 = intercept[TestFailedException] {
87          Array(1, 2) should { have size (5) and (have size (2 - 1)) }
88        }
89        assert(caught1.getMessage === "Array(1, 2) did not have size 5")
90
91        val caught2 = intercept[TestFailedException] {
92          Array(1, 2) should ((have size (5)) and (have size (2 - 1)))
93        }
94        assert(caught2.getMessage === "Array(1, 2) did not have size 5")
95
96        val caught3 = intercept[TestFailedException] {
97          Array(1, 2) should (have size (5) and have size (2 - 1))
98        }
99        assert(caught3.getMessage === "Array(1, 2) did not have size 5")
100      }
101
102      it("should throw an assertion error when array size doesn't match and used in a logical-or expression") {
103
104        val caught1 = intercept[TestFailedException] {
105          Array(1, 2) should { have size (55) or (have size (22)) }
106        }
107        assert(caught1.getMessage === "Array(1, 2) did not have size 55, and Array(1, 2) did not have size 22")
108
109        val caught2 = intercept[TestFailedException] {
110          Array(1, 2) should ((have size (55)) or (have size (22)))
111        }
112        assert(caught2.getMessage === "Array(1, 2) did not have size 55, and Array(1, 2) did not have size 22")
113
114        val caught3 = intercept[TestFailedException] {
115          Array(1, 2) should (have size (55) or have size (22))
116        }
117        assert(caught3.getMessage === "Array(1, 2) did not have size 55, and Array(1, 2) did not have size 22")
118      }
119
120      it("should throw an assertion error when array size matches and used in a logical-and expression with not") {
121
122        val caught1 = intercept[TestFailedException] {
123          Array(1, 2) should { not { have size (3) } and not { have size (2) }}
124        }
125        assert(caught1.getMessage === "Array(1, 2) did not have size 3, but Array(1, 2) had size 2")
126
127        val caught2 = intercept[TestFailedException] {
128          Array(1, 2) should ((not have size (3)) and (not have size (2)))
129        }
130        assert(caught2.getMessage === "Array(1, 2) did not have size 3, but Array(1, 2) had size 2")
131
132        val caught3 = intercept[TestFailedException] {
133          Array(1, 2) should (not have size (3) and not have size (2))
134        }
135        assert(caught3.getMessage === "Array(1, 2) did not have size 3, but Array(1, 2) had size 2")
136      }
137
138      it("should throw an assertion error when array size matches and used in a logical-or expression with not") {
139
140        val caught1 = intercept[TestFailedException] {
141          Array(1, 2) should { not { have size (2) } or not { have size (2) }}
142        }
143        assert(caught1.getMessage === "Array(1, 2) had size 2, and Array(1, 2) had size 2")
144
145        val caught2 = intercept[TestFailedException] {
146          Array(1, 2) should ((not have size (2)) or (not have size (2)))
147        }
148        assert(caught2.getMessage === "Array(1, 2) had size 2, and Array(1, 2) had size 2")
149
150        val caught3 = intercept[TestFailedException] {
151          Array(1, 2) should (not have size (2) or not have size (2))
152        }
153        assert(caught3.getMessage === "Array(1, 2) had size 2, and Array(1, 2) had size 2")
154      }
155    }
156
157    describe("on scala.collection.immutable.Set") {
158
159      it("should do nothing if set size matches specified size") {
160        Set(1, 2) should have size (2)
161        Set("one", "two") should have size (2)
162        // check((set: Set[Int]) => returnsNormally(set should have size (set.size)))
163      }
164
165      it("should do nothing if set size does not match and used with should not") {
166        Set(1, 2) should not { have size (3) }
167        Set(1, 2) should not have size (3)
168        // check((set: Set[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
169      }
170
171      it("should do nothing when set size matches and used in a logical-and expression") {
172        Set(1, 2) should { have size (2) and (have size (3 - 1)) }
173        Set(1, 2) should ((have size (2)) and (have size (3 - 1)))
174        Set(1, 2) should (have size (2) and have size (3 - 1))
175      }
176
177      it("should do nothing when set size matches and used in a logical-or expression") {
178        Set(1, 2) should { have size (77) or (have size (3 - 1)) }
179        Set(1, 2) should ((have size (77)) or (have size (3 - 1)))
180        Set(1, 2) should (have size (77) or have size (3 - 1))
181      }
182
183      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
184        Set(1, 2) should { not { have size (5) } and not { have size (3) }}
185        Set(1, 2) should ((not have size (5)) and (not have size (3)))
186        Set(1, 2) should (not have size (5) and not have size (3))
187      }
188
189      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
190        Set(1, 2) should { not { have size (2) } or not { have size (3) }}
191        Set(1, 2) should ((not have size (2)) or (not have size (3)))
192        Set(1, 2) should (not have size (2) or not have size (3))
193      }
194
195      it("should throw TestFailedException if set size does not match specified size") {
196        val caught1 = intercept[TestFailedException] {
197          Set(1, 2) should have size (3)
198        }
199        assert(caught1.getMessage === "Set(1, 2) did not have size 3")
200        // check((set: Set[String]) => throwsTestFailedException(set should have size (set.size + 1)))
201      }
202
203      it("should throw TestFailedException with normal error message if specified size is negative") {
204        val caught1 = intercept[TestFailedException] {
205          Set(1, 2) should have size (-2)
206        }
207        assert(caught1.getMessage === "Set(1, 2) did not have size -2")
208        // check((set: Set[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
209      }
210
211      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
212
213        val caught1 = intercept[TestFailedException] {
214          Set(1, 2) should { have size (5) and (have size (2 - 1)) }
215        }
216        assert(caught1.getMessage === "Set(1, 2) did not have size 5")
217
218        val caught2 = intercept[TestFailedException] {
219          Set(1, 2) should ((have size (5)) and (have size (2 - 1)))
220        }
221        assert(caught2.getMessage === "Set(1, 2) did not have size 5")
222
223        val caught3 = intercept[TestFailedException] {
224          Set(1, 2) should (have size (5) and have size (2 - 1))
225        }
226        assert(caught3.getMessage === "Set(1, 2) did not have size 5")
227      }
228
229      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
230
231        val caught1 = intercept[TestFailedException] {
232          Set(1, 2) should { have size (55) or (have size (22)) }
233        }
234        assert(caught1.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
235
236        val caught2 = intercept[TestFailedException] {
237          Set(1, 2) should ((have size (55)) or (have size (22)))
238        }
239        assert(caught2.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
240
241        val caught3 = intercept[TestFailedException] {
242          Set(1, 2) should (have size (55) or have size (22))
243        }
244        assert(caught3.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
245      }
246
247      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
248
249        val caught1 = intercept[TestFailedException] {
250          Set(1, 2) should { not { have size (3) } and not { have size (2) }}
251        }
252        assert(caught1.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
253
254        val caught2 = intercept[TestFailedException] {
255          Set(1, 2) should ((not have size (3)) and (not have size (2)))
256        }
257        assert(caught2.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
258
259        val caught3 = intercept[TestFailedException] {
260          Set(1, 2) should (not have size (3) and not have size (2))
261        }
262        assert(caught3.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
263      }
264
265      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
266
267        val caught1 = intercept[TestFailedException] {
268          Set(1, 2) should { not { have size (2) } or not { have size (2) }}
269        }
270        assert(caught1.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
271
272        val caught2 = intercept[TestFailedException] {
273          Set(1, 2) should ((not have size (2)) or (not have size (2)))
274        }
275        assert(caught2.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
276
277        val caught3 = intercept[TestFailedException] {
278          Set(1, 2) should (not have size (2) or not have size (2))
279        }
280        assert(caught3.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 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 size matches specified size") {
289        mutable.Set(1, 2) should have size (2)
290        mutable.Set("one", "two") should have size (2)
291        // check((set: Set[Int]) => returnsNormally(set should have size (set.size)))
292      }
293
294      it("should do nothing if set size does not match and used with should not") {
295        mutable.Set(1, 2) should not { have size (3) }
296        mutable.Set(1, 2) should not have size (3)
297        // check((set: Set[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
298      }
299
300      it("should do nothing when set size matches and used in a logical-and expression") {
301        mutable.Set(1, 2) should { have size (2) and (have size (3 - 1)) }
302        mutable.Set(1, 2) should ((have size (2)) and (have size (3 - 1)))
303        mutable.Set(1, 2) should (have size (2) and have size (3 - 1))
304      }
305
306      it("should do nothing when set size matches and used in a logical-or expression") {
307        mutable.Set(1, 2) should { have size (77) or (have size (3 - 1)) }
308        mutable.Set(1, 2) should ((have size (77)) or (have size (3 - 1)))
309        mutable.Set(1, 2) should (have size (77) or have size (3 - 1))
310      }
311
312      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
313        mutable.Set(1, 2) should { not { have size (5) } and not { have size (3) }}
314        mutable.Set(1, 2) should ((not have size (5)) and (not have size (3)))
315        mutable.Set(1, 2) should (not have size (5) and not have size (3))
316      }
317
318      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
319        mutable.Set(1, 2) should { not { have size (2) } or not { have size (3) }}
320        mutable.Set(1, 2) should ((not have size (2)) or (not have size (3)))
321        mutable.Set(1, 2) should (not have size (2) or not have size (3))
322      }
323
324      it("should throw TestFailedException if set size does not match specified size") {
325        val caught1 = intercept[TestFailedException] {
326          mutable.Set(1, 2) should have size (3)
327        }
328        assert(caught1.getMessage === "Set(1, 2) did not have size 3")
329        // check((set: Set[String]) => throwsTestFailedException(set should have size (set.size + 1)))
330      }
331
332      it("should throw TestFailedException with normal error message if specified size is negative") {
333        val caught1 = intercept[TestFailedException] {
334          mutable.Set(1, 2) should have size (-2)
335        }
336        assert(caught1.getMessage === "Set(1, 2) did not have size -2")
337        // check((set: Set[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
338      }
339
340      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
341
342        val caught1 = intercept[TestFailedException] {
343          mutable.Set(1, 2) should { have size (5) and (have size (2 - 1)) }
344        }
345        assert(caught1.getMessage === "Set(1, 2) did not have size 5")
346
347        val caught2 = intercept[TestFailedException] {
348          mutable.Set(1, 2) should ((have size (5)) and (have size (2 - 1)))
349        }
350        assert(caught2.getMessage === "Set(1, 2) did not have size 5")
351
352        val caught3 = intercept[TestFailedException] {
353          mutable.Set(1, 2) should (have size (5) and have size (2 - 1))
354        }
355        assert(caught3.getMessage === "Set(1, 2) did not have size 5")
356      }
357
358      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
359
360        val caught1 = intercept[TestFailedException] {
361          mutable.Set(1, 2) should { have size (55) or (have size (22)) }
362        }
363        assert(caught1.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
364
365        val caught2 = intercept[TestFailedException] {
366          mutable.Set(1, 2) should ((have size (55)) or (have size (22)))
367        }
368        assert(caught2.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
369
370        val caught3 = intercept[TestFailedException] {
371          mutable.Set(1, 2) should (have size (55) or have size (22))
372        }
373        assert(caught3.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
374      }
375
376      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
377
378        val caught1 = intercept[TestFailedException] {
379          mutable.Set(1, 2) should { not { have size (3) } and not { have size (2) }}
380        }
381        assert(caught1.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
382
383        val caught2 = intercept[TestFailedException] {
384          mutable.Set(1, 2) should ((not have size (3)) and (not have size (2)))
385        }
386        assert(caught2.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
387
388        val caught3 = intercept[TestFailedException] {
389          mutable.Set(1, 2) should (not have size (3) and not have size (2))
390        }
391        assert(caught3.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
392      }
393
394      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
395
396        val caught1 = intercept[TestFailedException] {
397          mutable.Set(1, 2) should { not { have size (2) } or not { have size (2) }}
398        }
399        assert(caught1.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
400
401        val caught2 = intercept[TestFailedException] {
402          mutable.Set(1, 2) should ((not have size (2)) or (not have size (2)))
403        }
404        assert(caught2.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
405
406        val caught3 = intercept[TestFailedException] {
407          mutable.Set(1, 2) should (not have size (2) or not have size (2))
408        }
409        assert(caught3.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
410      }
411    }
412
413    describe("on scala.collection.Set") {
414
415      val set: scala.collection.Set[Int] = Set(1, 2)
416
417      it("should do nothing if set size matches specified size") {
418        set should have size (2)
419        Set("one", "two") should have size (2)
420        // check((set: Set[Int]) => returnsNormally(set should have size (set.size)))
421      }
422
423      it("should do nothing if set size does not match and used with should not") {
424        set should not { have size (3) }
425        set should not have size (3)
426        // check((set: Set[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
427      }
428
429      it("should do nothing when set size matches and used in a logical-and expression") {
430        set should { have size (2) and (have size (3 - 1)) }
431        set should ((have size (2)) and (have size (3 - 1)))
432        set should (have size (2) and have size (3 - 1))
433      }
434
435      it("should do nothing when set size matches and used in a logical-or expression") {
436        set should { have size (77) or (have size (3 - 1)) }
437        set should ((have size (77)) or (have size (3 - 1)))
438        set should (have size (77) or have size (3 - 1))
439      }
440
441      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
442        set should { not { have size (5) } and not { have size (3) }}
443        set should ((not have size (5)) and (not have size (3)))
444        set should (not have size (5) and not have size (3))
445      }
446
447      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
448        set should { not { have size (2) } or not { have size (3) }}
449        set should ((not have size (2)) or (not have size (3)))
450        set should (not have size (2) or not have size (3))
451      }
452
453      it("should throw TestFailedException if set size does not match specified size") {
454        val caught1 = intercept[TestFailedException] {
455          set should have size (3)
456        }
457        assert(caught1.getMessage === "Set(1, 2) did not have size 3")
458        // check((set: Set[String]) => throwsTestFailedException(set should have size (set.size + 1)))
459      }
460
461      it("should throw TestFailedException with normal error message if specified size is negative") {
462        val caught1 = intercept[TestFailedException] {
463          set should have size (-2)
464        }
465        assert(caught1.getMessage === "Set(1, 2) did not have size -2")
466        // check((set: Set[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
467      }
468
469      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
470
471        val caught1 = intercept[TestFailedException] {
472          set should { have size (5) and (have size (2 - 1)) }
473        }
474        assert(caught1.getMessage === "Set(1, 2) did not have size 5")
475
476        val caught2 = intercept[TestFailedException] {
477          set should ((have size (5)) and (have size (2 - 1)))
478        }
479        assert(caught2.getMessage === "Set(1, 2) did not have size 5")
480
481        val caught3 = intercept[TestFailedException] {
482          set should (have size (5) and have size (2 - 1))
483        }
484        assert(caught3.getMessage === "Set(1, 2) did not have size 5")
485      }
486
487      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
488
489        val caught1 = intercept[TestFailedException] {
490          set should { have size (55) or (have size (22)) }
491        }
492        assert(caught1.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
493
494        val caught2 = intercept[TestFailedException] {
495          set should ((have size (55)) or (have size (22)))
496        }
497        assert(caught2.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
498
499        val caught3 = intercept[TestFailedException] {
500          set should (have size (55) or have size (22))
501        }
502        assert(caught3.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
503      }
504
505      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
506
507        val caught1 = intercept[TestFailedException] {
508          set should { not { have size (3) } and not { have size (2) }}
509        }
510        assert(caught1.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
511
512        val caught2 = intercept[TestFailedException] {
513          set should ((not have size (3)) and (not have size (2)))
514        }
515        assert(caught2.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
516
517        val caught3 = intercept[TestFailedException] {
518          set should (not have size (3) and not have size (2))
519        }
520        assert(caught3.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
521      }
522
523      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
524
525        val caught1 = intercept[TestFailedException] {
526          set should { not { have size (2) } or not { have size (2) }}
527        }
528        assert(caught1.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
529
530        val caught2 = intercept[TestFailedException] {
531          set should ((not have size (2)) or (not have size (2)))
532        }
533        assert(caught2.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
534
535        val caught3 = intercept[TestFailedException] {
536          set should (not have size (2) or not have size (2))
537        }
538        assert(caught3.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
539      }
540    }
541
542    describe("on scala.collection.immutable.HashSet") {
543
544      import scala.collection.immutable.HashSet
545
546      it("should do nothing if set size matches specified size") {
547        HashSet(1, 2) should have size (2)
548        HashSet("one", "two") should have size (2)
549        // check((set: Set[Int]) => returnsNormally(set should have size (set.size)))
550      }
551
552      it("should do nothing if set size does not match and used with should not") {
553        HashSet(1, 2) should not { have size (3) }
554        HashSet(1, 2) should not have size (3)
555        // check((set: Set[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
556      }
557
558      it("should do nothing when set size matches and used in a logical-and expression") {
559        HashSet(1, 2) should { have size (2) and (have size (3 - 1)) }
560        HashSet(1, 2) should ((have size (2)) and (have size (3 - 1)))
561        HashSet(1, 2) should (have size (2) and have size (3 - 1))
562      }
563
564      it("should do nothing when set size matches and used in a logical-or expression") {
565        HashSet(1, 2) should { have size (77) or (have size (3 - 1)) }
566        HashSet(1, 2) should ((have size (77)) or (have size (3 - 1)))
567        HashSet(1, 2) should (have size (77) or have size (3 - 1))
568      }
569
570      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
571        HashSet(1, 2) should { not { have size (5) } and not { have size (3) }}
572        HashSet(1, 2) should ((not have size (5)) and (not have size (3)))
573        HashSet(1, 2) should (not have size (5) and not have size (3))
574      }
575
576      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
577        HashSet(1, 2) should { not { have size (2) } or not { have size (3) }}
578        HashSet(1, 2) should ((not have size (2)) or (not have size (3)))
579        HashSet(1, 2) should (not have size (2) or not have size (3))
580      }
581
582      it("should throw TestFailedException if set size does not match specified size") {
583        val caught1 = intercept[TestFailedException] {
584          HashSet(1, 2) should have size (3)
585        }
586        assert(caught1.getMessage === "Set(1, 2) did not have size 3")
587        // check((set: Set[String]) => throwsTestFailedException(set should have size (set.size + 1)))
588      }
589
590      it("should throw TestFailedException with normal error message if specified size is negative") {
591        val caught1 = intercept[TestFailedException] {
592          HashSet(1, 2) should have size (-2)
593        }
594        assert(caught1.getMessage === "Set(1, 2) did not have size -2")
595        // check((set: Set[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
596      }
597
598      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
599
600        val caught1 = intercept[TestFailedException] {
601          HashSet(1, 2) should { have size (5) and (have size (2 - 1)) }
602        }
603        assert(caught1.getMessage === "Set(1, 2) did not have size 5")
604
605        val caught2 = intercept[TestFailedException] {
606          HashSet(1, 2) should ((have size (5)) and (have size (2 - 1)))
607        }
608        assert(caught2.getMessage === "Set(1, 2) did not have size 5")
609
610        val caught3 = intercept[TestFailedException] {
611          HashSet(1, 2) should (have size (5) and have size (2 - 1))
612        }
613        assert(caught3.getMessage === "Set(1, 2) did not have size 5")
614      }
615
616      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
617
618        val caught1 = intercept[TestFailedException] {
619          HashSet(1, 2) should { have size (55) or (have size (22)) }
620        }
621        assert(caught1.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
622
623        val caught2 = intercept[TestFailedException] {
624          HashSet(1, 2) should ((have size (55)) or (have size (22)))
625        }
626        assert(caught2.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
627
628        val caught3 = intercept[TestFailedException] {
629          HashSet(1, 2) should (have size (55) or have size (22))
630        }
631        assert(caught3.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
632      }
633
634      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
635
636        val caught1 = intercept[TestFailedException] {
637          HashSet(1, 2) should { not { have size (3) } and not { have size (2) }}
638        }
639        assert(caught1.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
640
641        val caught2 = intercept[TestFailedException] {
642          HashSet(1, 2) should ((not have size (3)) and (not have size (2)))
643        }
644        assert(caught2.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
645
646        val caught3 = intercept[TestFailedException] {
647          HashSet(1, 2) should (not have size (3) and not have size (2))
648        }
649        assert(caught3.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
650      }
651
652      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
653
654        val caught1 = intercept[TestFailedException] {
655          HashSet(1, 2) should { not { have size (2) } or not { have size (2) }}
656        }
657        assert(caught1.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
658
659        val caught2 = intercept[TestFailedException] {
660          HashSet(1, 2) should ((not have size (2)) or (not have size (2)))
661        }
662        assert(caught2.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
663
664        val caught3 = intercept[TestFailedException] {
665          HashSet(1, 2) should (not have size (2) or not have size (2))
666        }
667        assert(caught3.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
668      }
669    }
670
671    describe("on scala.collection.mutable.HashSet") {
672
673      import scala.collection.mutable
674
675      it("should do nothing if set size matches specified size") {
676        mutable.HashSet(1, 2) should have size (2)
677        mutable.HashSet("one", "two") should have size (2)
678        // check((set: Set[Int]) => returnsNormally(set should have size (set.size)))
679      }
680
681      it("should do nothing if set size does not match and used with should not") {
682        mutable.HashSet(1, 2) should not { have size (3) }
683        mutable.HashSet(1, 2) should not have size (3)
684        // check((set: Set[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
685      }
686
687      it("should do nothing when set size matches and used in a logical-and expression") {
688        mutable.HashSet(1, 2) should { have size (2) and (have size (3 - 1)) }
689        mutable.HashSet(1, 2) should ((have size (2)) and (have size (3 - 1)))
690        mutable.HashSet(1, 2) should (have size (2) and have size (3 - 1))
691      }
692
693      it("should do nothing when set size matches and used in a logical-or expression") {
694        mutable.HashSet(1, 2) should { have size (77) or (have size (3 - 1)) }
695        mutable.HashSet(1, 2) should ((have size (77)) or (have size (3 - 1)))
696        mutable.HashSet(1, 2) should (have size (77) or have size (3 - 1))
697      }
698
699      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
700        mutable.HashSet(1, 2) should { not { have size (5) } and not { have size (3) }}
701        mutable.HashSet(1, 2) should ((not have size (5)) and (not have size (3)))
702        mutable.HashSet(1, 2) should (not have size (5) and not have size (3))
703      }
704
705      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
706        mutable.HashSet(1, 2) should { not { have size (2) } or not { have size (3) }}
707        mutable.HashSet(1, 2) should ((not have size (2)) or (not have size (3)))
708        mutable.HashSet(1, 2) should (not have size (2) or not have size (3))
709      }
710
711      it("should throw TestFailedException if set size does not match specified size") {
712        val caught1 = intercept[TestFailedException] {
713          mutable.HashSet(1, 2) should have size (3)
714        }
715        assert(caught1.getMessage === "Set(1, 2) did not have size 3")
716        // check((set: Set[String]) => throwsTestFailedException(set should have size (set.size + 1)))
717      }
718
719      it("should throw TestFailedException with normal error message if specified size is negative") {
720        val caught1 = intercept[TestFailedException] {
721          mutable.HashSet(1, 2) should have size (-2)
722        }
723        assert(caught1.getMessage === "Set(1, 2) did not have size -2")
724        // check((set: Set[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
725      }
726
727      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
728
729        val caught1 = intercept[TestFailedException] {
730          mutable.HashSet(1, 2) should { have size (5) and (have size (2 - 1)) }
731        }
732        assert(caught1.getMessage === "Set(1, 2) did not have size 5")
733
734        val caught2 = intercept[TestFailedException] {
735          mutable.HashSet(1, 2) should ((have size (5)) and (have size (2 - 1)))
736        }
737        assert(caught2.getMessage === "Set(1, 2) did not have size 5")
738
739        val caught3 = intercept[TestFailedException] {
740          mutable.HashSet(1, 2) should (have size (5) and have size (2 - 1))
741        }
742        assert(caught3.getMessage === "Set(1, 2) did not have size 5")
743      }
744
745      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
746
747        val caught1 = intercept[TestFailedException] {
748          mutable.HashSet(1, 2) should { have size (55) or (have size (22)) }
749        }
750        assert(caught1.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
751
752        val caught2 = intercept[TestFailedException] {
753          mutable.HashSet(1, 2) should ((have size (55)) or (have size (22)))
754        }
755        assert(caught2.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
756
757        val caught3 = intercept[TestFailedException] {
758          mutable.HashSet(1, 2) should (have size (55) or have size (22))
759        }
760        assert(caught3.getMessage === "Set(1, 2) did not have size 55, and Set(1, 2) did not have size 22")
761      }
762
763      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
764
765        val caught1 = intercept[TestFailedException] {
766          mutable.HashSet(1, 2) should { not { have size (3) } and not { have size (2) }}
767        }
768        assert(caught1.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
769
770        val caught2 = intercept[TestFailedException] {
771          mutable.HashSet(1, 2) should ((not have size (3)) and (not have size (2)))
772        }
773        assert(caught2.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
774
775        val caught3 = intercept[TestFailedException] {
776          mutable.HashSet(1, 2) should (not have size (3) and not have size (2))
777        }
778        assert(caught3.getMessage === "Set(1, 2) did not have size 3, but Set(1, 2) had size 2")
779      }
780
781      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
782
783        val caught1 = intercept[TestFailedException] {
784          mutable.HashSet(1, 2) should { not { have size (2) } or not { have size (2) }}
785        }
786        assert(caught1.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
787
788        val caught2 = intercept[TestFailedException] {
789          mutable.HashSet(1, 2) should ((not have size (2)) or (not have size (2)))
790        }
791        assert(caught2.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
792
793        val caught3 = intercept[TestFailedException] {
794          mutable.HashSet(1, 2) should (not have size (2) or not have size (2))
795        }
796        assert(caught3.getMessage === "Set(1, 2) had size 2, and Set(1, 2) had size 2")
797      }
798    }
799
800    describe("on scala.List") {
801
802      it("should do nothing if list size matches specified size") {
803        List(1, 2) should have size (2)
804        check((lst: List[Int]) => returnsNormally(lst should have size (lst.size)))
805      }
806
807      it("should do nothing if list size does not match and used with should not") {
808        List(1, 2) should not { have size (3) }
809        List(1, 2) should not have size (3)
810        check((lst: List[Int], i: Int) => i != lst.size ==> returnsNormally(lst should not { have size (i) }))
811      }
812
813      it("should do nothing when list size matches and used in a logical-and expression") {
814        List(1, 2) should { have size (2) and (have size (3 - 1)) }
815        List(1, 2) should ((have size (2)) and (have size (3 - 1)))
816        List(1, 2) should (have size (2) and have size (3 - 1))
817      }
818
819      it("should do nothing when list size matches and used in a logical-or expression") {
820        List(1, 2) should { have size (77) or (have size (3 - 1)) }
821        List(1, 2) should ((have size (77)) or (have size (3 - 1)))
822        List(1, 2) should (have size (77) or have size (3 - 1))
823      }
824
825      it("should do nothing when list size doesn't match and used in a logical-and expression with not") {
826        List(1, 2) should { not { have size (5) } and not { have size (3) }}
827        List(1, 2) should ((not have size (5)) and (not have size (3)))
828        List(1, 2) should (not have size (5) and not have size (3))
829      }
830
831      it("should do nothing when list size doesn't match and used in a logical-or expression with not") {
832        List(1, 2) should { not { have size (2) } or not { have size (3) }}
833        List(1, 2) should ((not have size (2)) or (not have size (3)))
834        List(1, 2) should (not have size (2) or not have size (3))
835      }
836
837      it("should throw TestFailedException if list size does not match specified size") {
838        val caught1 = intercept[TestFailedException] {
839          List(1, 2) should have size (3)
840        }
841        assert(caught1.getMessage === "List(1, 2) did not have size 3")
842        check((lst: List[String]) => throwsTestFailedException(lst should have size (lst.size + 1)))
843      }
844
845      it("should throw TestFailedException with normal error message if specified size is negative") {
846        val caught1 = intercept[TestFailedException] {
847          List(1, 2) should have size (-2)
848        }
849        assert(caught1.getMessage === "List(1, 2) did not have size -2")
850        check((lst: List[Int]) => throwsTestFailedException(lst should have size (if (lst.size == 0) -1 else -lst.size)))
851      }
852
853      it("should throw an assertion error when list size doesn't match and used in a logical-and expression") {
854
855        val caught1 = intercept[TestFailedException] {
856          List(1, 2) should { have size (5) and (have size (2 - 1)) }
857        }
858        assert(caught1.getMessage === "List(1, 2) did not have size 5")
859
860        val caught2 = intercept[TestFailedException] {
861          List(1, 2) should ((have size (5)) and (have size (2 - 1)))
862        }
863        assert(caught2.getMessage === "List(1, 2) did not have size 5")
864
865        val caught3 = intercept[TestFailedException] {
866          List(1, 2) should (have size (5) and have size (2 - 1))
867        }
868        assert(caught3.getMessage === "List(1, 2) did not have size 5")
869      }
870
871      it("should throw an assertion error when list size doesn't match and used in a logical-or expression") {
872
873        val caught1 = intercept[TestFailedException] {
874          List(1, 2) should { have size (55) or (have size (22)) }
875        }
876        assert(caught1.getMessage === "List(1, 2) did not have size 55, and List(1, 2) did not have size 22")
877
878        val caught2 = intercept[TestFailedException] {
879          List(1, 2) should ((have size (55)) or (have size (22)))
880        }
881        assert(caught2.getMessage === "List(1, 2) did not have size 55, and List(1, 2) did not have size 22")
882
883        val caught3 = intercept[TestFailedException] {
884          List(1, 2) should (have size (55) or have size (22))
885        }
886        assert(caught3.getMessage === "List(1, 2) did not have size 55, and List(1, 2) did not have size 22")
887      }
888
889      it("should throw an assertion error when list size matches and used in a logical-and expression with not") {
890
891        val caught1 = intercept[TestFailedException] {
892          List(1, 2) should { not { have size (3) } and not { have size (2) }}
893        }
894        assert(caught1.getMessage === "List(1, 2) did not have size 3, but List(1, 2) had size 2")
895
896        val caught2 = intercept[TestFailedException] {
897          List(1, 2) should ((not have size (3)) and (not have size (2)))
898        }
899        assert(caught2.getMessage === "List(1, 2) did not have size 3, but List(1, 2) had size 2")
900
901        val caught3 = intercept[TestFailedException] {
902          List(1, 2) should (not have size (3) and not have size (2))
903        }
904        assert(caught3.getMessage === "List(1, 2) did not have size 3, but List(1, 2) had size 2")
905      }
906
907      it("should throw an assertion error when list size matches and used in a logical-or expression with not") {
908
909        val caught1 = intercept[TestFailedException] {
910          List(1, 2) should { not { have size (2) } or not { have size (2) }}
911        }
912        assert(caught1.getMessage === "List(1, 2) had size 2, and List(1, 2) had size 2")
913
914        val caught2 = intercept[TestFailedException] {
915          List(1, 2) should ((not have size (2)) or (not have size (2)))
916        }
917        assert(caught2.getMessage === "List(1, 2) had size 2, and List(1, 2) had size 2")
918
919        val caught3 = intercept[TestFailedException] {
920          List(1, 2) should (not have size (2) or not have size (2))
921        }
922        assert(caught3.getMessage === "List(1, 2) had size 2, and List(1, 2) had size 2")
923      }
924    }
925
926    describe("on java.util.List") {
927
928      val javaList: java.util.List[Int] = new java.util.ArrayList
929      javaList.add(1)
930      javaList.add(2)
931
932      it("should do nothing if list size matches specified size") {
933        javaList should have size (2)
934        // check((lst: java.util.List[Int]) => returnsNormally(lst should have size (lst.size)))
935      }
936
937      it("should do nothing if list size does not match and used with should not") {
938        javaList should not { have size (3) }
939        javaList should not have size (3)
940        // check((lst: List[Int], i: Int) => i != lst.size ==> returnsNormally(lst should not { have size (i) }))
941      }
942
943      it("should do nothing when list size matches and used in a logical-and expression") {
944        javaList should { have size (2) and (have size (3 - 1)) }
945        javaList should ((have size (2)) and (have size (3 - 1)))
946        javaList should (have size (2) and have size (3 - 1))
947      }
948
949      it("should do nothing when list size matches and used in a logical-or expression") {
950        javaList should { have size (77) or (have size (3 - 1)) }
951        javaList should ((have size (77)) or (have size (3 - 1)))
952        javaList should (have size (77) or have size (3 - 1))
953      }
954
955      it("should do nothing when list size doesn't match and used in a logical-and expression with not") {
956        javaList should { not { have size (5) } and not { have size (3) }}
957        javaList should ((not have size (5)) and (not have size (3)))
958        javaList should (not have size (5) and not have size (3))
959      }
960
961      it("should do nothing when list size doesn't match and used in a logical-or expression with not") {
962        javaList should { not { have size (2) } or not { have size (3) }}
963        javaList should ((not have size (2)) or (not have size (3)))
964        javaList should (not have size (2) or not have size (3))
965      }
966
967      it("should throw TestFailedException if list size does not match specified size") {
968        val caught1 = intercept[TestFailedException] {
969          javaList should have size (3)
970        }
971        assert(caught1.getMessage === "[1, 2] did not have size 3")
972        // check((lst: List[String]) => throwsTestFailedException(lst should have size (lst.size + 1)))
973      }
974
975      it("should throw TestFailedException with normal error message if specified size is negative") {
976        val caught1 = intercept[TestFailedException] {
977          javaList should have size (-2)
978        }
979        assert(caught1.getMessage === "[1, 2] did not have size -2")
980        // check((lst: List[Int]) => throwsTestFailedException(lst should have size (if (lst.size == 0) -1 else -lst.size)))
981      }
982
983      it("should throw an assertion error when list size doesn't match and used in a logical-and expression") {
984
985        val caught1 = intercept[TestFailedException] {
986          javaList should { have size (5) and (have size (2 - 1)) }
987        }
988        assert(caught1.getMessage === "[1, 2] did not have size 5")
989
990        val caught2 = intercept[TestFailedException] {
991          javaList should ((have size (5)) and (have size (2 - 1)))
992        }
993        assert(caught2.getMessage === "[1, 2] did not have size 5")
994
995        val caught3 = intercept[TestFailedException] {
996          javaList should (have size (5) and have size (2 - 1))
997        }
998        assert(caught3.getMessage === "[1, 2] did not have size 5")
999      }
1000
1001      it("should throw an assertion error when list size doesn't match and used in a logical-or expression") {
1002
1003        val caught1 = intercept[TestFailedException] {
1004          javaList should { have size (55) or (have size (22)) }
1005        }
1006        assert(caught1.getMessage === "[1, 2] did not have size 55, and [1, 2] did not have size 22")
1007
1008        val caught2 = intercept[TestFailedException] {
1009          javaList should ((have size (55)) or (have size (22)))
1010        }
1011        assert(caught2.getMessage === "[1, 2] did not have size 55, and [1, 2] did not have size 22")
1012
1013        val caught3 = intercept[TestFailedException] {
1014          javaList should (have size (55) or have size (22))
1015        }
1016        assert(caught3.getMessage === "[1, 2] did not have size 55, and [1, 2] did not have size 22")
1017      }
1018
1019      it("should throw an assertion error when list size matches and used in a logical-and expression with not") {
1020
1021        val caught1 = intercept[TestFailedException] {
1022          javaList should { not { have size (3) } and not { have size (2) }}
1023        }
1024        assert(caught1.getMessage === "[1, 2] did not have size 3, but [1, 2] had size 2")
1025
1026        val caught2 = intercept[TestFailedException] {
1027          javaList should ((not have size (3)) and (not have size (2)))
1028        }
1029        assert(caught2.getMessage === "[1, 2] did not have size 3, but [1, 2] had size 2")
1030
1031        val caught3 = intercept[TestFailedException] {
1032          javaList should (not have size (3) and not have size (2))
1033        }
1034        assert(caught3.getMessage === "[1, 2] did not have size 3, but [1, 2] had size 2")
1035      }
1036
1037      it("should throw an assertion error when list size matches and used in a logical-or expression with not") {
1038
1039        val caught1 = intercept[TestFailedException] {
1040          javaList should { not { have size (2) } or not { have size (2) }}
1041        }
1042        assert(caught1.getMessage === "[1, 2] had size 2, and [1, 2] had size 2")
1043
1044        val caught2 = intercept[TestFailedException] {
1045          javaList should ((not have size (2)) or (not have size (2)))
1046        }
1047        assert(caught2.getMessage === "[1, 2] had size 2, and [1, 2] had size 2")
1048
1049        val caught3 = intercept[TestFailedException] {
1050          javaList should (not have size (2) or not have size (2))
1051        }
1052        assert(caught3.getMessage === "[1, 2] had size 2, and [1, 2] had size 2")
1053      }
1054    }
1055
1056    describe("on scala.collection.immutable.Map") {
1057
1058      it("should do nothing if set size matches specified size") {
1059        Map("one" -> 1, "two" -> 2) should have size (2)
1060        Map(1 -> "one", 2 -> "two") should have size (2)
1061        // check((set: Map[Int]) => returnsNormally(set should have size (set.size)))
1062      }
1063
1064      it("should do nothing if set size does not match and used with should not") {
1065        Map("one" -> 1, "two" -> 2) should not { have size (3) }
1066        Map("one" -> 1, "two" -> 2) should not have size (3)
1067        // check((set: Map[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
1068      }
1069
1070      it("should do nothing when set size matches and used in a logical-and expression") {
1071        Map("one" -> 1, "two" -> 2) should { have size (2) and (have size (3 - 1)) }
1072        Map("one" -> 1, "two" -> 2) should ((have size (2)) and (have size (3 - 1)))
1073        Map("one" -> 1, "two" -> 2) should (have size (2) and have size (3 - 1))
1074      }
1075
1076      it("should do nothing when set size matches and used in a logical-or expression") {
1077        Map("one" -> 1, "two" -> 2) should { have size (77) or (have size (3 - 1)) }
1078        Map("one" -> 1, "two" -> 2) should ((have size (77)) or (have size (3 - 1)))
1079        Map("one" -> 1, "two" -> 2) should (have size (77) or have size (3 - 1))
1080      }
1081
1082      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
1083        Map("one" -> 1, "two" -> 2) should { not { have size (5) } and not { have size (3) }}
1084        Map("one" -> 1, "two" -> 2) should ((not have size (5)) and (not have size (3)))
1085        Map("one" -> 1, "two" -> 2) should (not have size (5) and not have size (3))
1086      }
1087
1088      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
1089        Map("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (3) }}
1090        Map("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (3)))
1091        Map("one" -> 1, "two" -> 2) should (not have size (2) or not have size (3))
1092      }
1093
1094      it("should throw TestFailedException if set size does not match specified size") {
1095        val caught1 = intercept[TestFailedException] {
1096          Map("one" -> 1, "two" -> 2) should have size (3)
1097        }
1098        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3")
1099        // check((set: Map[String]) => throwsTestFailedException(set should have size (set.size + 1)))
1100      }
1101
1102      it("should throw TestFailedException with normal error message if specified size is negative") {
1103        val caught1 = intercept[TestFailedException] {
1104          Map("one" -> 1, "two" -> 2) should have size (-2)
1105        }
1106        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size -2")
1107        // check((set: Map[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
1108      }
1109
1110      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
1111
1112        val caught1 = intercept[TestFailedException] {
1113          Map("one" -> 1, "two" -> 2) should { have size (5) and (have size (2 - 1)) }
1114        }
1115        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1116
1117        val caught2 = intercept[TestFailedException] {
1118          Map("one" -> 1, "two" -> 2) should ((have size (5)) and (have size (2 - 1)))
1119        }
1120        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1121
1122        val caught3 = intercept[TestFailedException] {
1123          Map("one" -> 1, "two" -> 2) should (have size (5) and have size (2 - 1))
1124        }
1125        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1126      }
1127
1128      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
1129
1130        val caught1 = intercept[TestFailedException] {
1131          Map("one" -> 1, "two" -> 2) should { have size (55) or (have size (22)) }
1132        }
1133        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1134
1135        val caught2 = intercept[TestFailedException] {
1136          Map("one" -> 1, "two" -> 2) should ((have size (55)) or (have size (22)))
1137        }
1138        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1139
1140        val caught3 = intercept[TestFailedException] {
1141          Map("one" -> 1, "two" -> 2) should (have size (55) or have size (22))
1142        }
1143        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1144      }
1145
1146      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
1147
1148        val caught1 = intercept[TestFailedException] {
1149          Map("one" -> 1, "two" -> 2) should { not { have size (3) } and not { have size (2) }}
1150        }
1151        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1152
1153        val caught2 = intercept[TestFailedException] {
1154          Map("one" -> 1, "two" -> 2) should ((not have size (3)) and (not have size (2)))
1155        }
1156        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1157
1158        val caught3 = intercept[TestFailedException] {
1159          Map("one" -> 1, "two" -> 2) should (not have size (3) and not have size (2))
1160        }
1161        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1162      }
1163
1164      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
1165
1166        val caught1 = intercept[TestFailedException] {
1167          Map("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (2) }}
1168        }
1169        assert(caught1.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1170
1171        val caught2 = intercept[TestFailedException] {
1172          Map("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (2)))
1173        }
1174        assert(caught2.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1175
1176        val caught3 = intercept[TestFailedException] {
1177          Map("one" -> 1, "two" -> 2) should (not have size (2) or not have size (2))
1178        }
1179        assert(caught3.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1180      }
1181    }
1182
1183    describe("on scala.collection.mutable.Map") {
1184
1185      import scala.collection.mutable
1186
1187      it("should do nothing if set size matches specified size") {
1188        mutable.Map("one" -> 1, "two" -> 2) should have size (2)
1189        mutable.Map(1 -> "one", 2 -> "two") should have size (2)
1190        // check((set: Map[Int]) => returnsNormally(set should have size (set.size)))
1191      }
1192
1193      it("should do nothing if set size does not match and used with should not") {
1194        mutable.Map("one" -> 1, "two" -> 2) should not { have size (3) }
1195        mutable.Map("one" -> 1, "two" -> 2) should not have size (3)
1196        // check((set: Map[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
1197      }
1198
1199      it("should do nothing when set size matches and used in a logical-and expression") {
1200        mutable.Map("one" -> 1, "two" -> 2) should { have size (2) and (have size (3 - 1)) }
1201        mutable.Map("one" -> 1, "two" -> 2) should ((have size (2)) and (have size (3 - 1)))
1202        mutable.Map("one" -> 1, "two" -> 2) should (have size (2) and have size (3 - 1))
1203      }
1204
1205      it("should do nothing when set size matches and used in a logical-or expression") {
1206        mutable.Map("one" -> 1, "two" -> 2) should { have size (77) or (have size (3 - 1)) }
1207        mutable.Map("one" -> 1, "two" -> 2) should ((have size (77)) or (have size (3 - 1)))
1208        mutable.Map("one" -> 1, "two" -> 2) should (have size (77) or have size (3 - 1))
1209      }
1210
1211      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
1212        mutable.Map("one" -> 1, "two" -> 2) should { not { have size (5) } and not { have size (3) }}
1213        mutable.Map("one" -> 1, "two" -> 2) should ((not have size (5)) and (not have size (3)))
1214        mutable.Map("one" -> 1, "two" -> 2) should (not have size (5) and not have size (3))
1215      }
1216
1217      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
1218        mutable.Map("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (3) }}
1219        mutable.Map("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (3)))
1220        mutable.Map("one" -> 1, "two" -> 2) should (not have size (2) or not have size (3))
1221      }
1222
1223      it("should throw TestFailedException if set size does not match specified size") {
1224        val caught1 = intercept[TestFailedException] {
1225          mutable.Map("one" -> 1, "two" -> 2) should have size (3)
1226        }
1227        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3")
1228        // check((set: Map[String]) => throwsTestFailedException(set should have size (set.size + 1)))
1229      }
1230
1231      it("should throw TestFailedException with normal error message if specified size is negative") {
1232        val caught1 = intercept[TestFailedException] {
1233          mutable.Map("one" -> 1, "two" -> 2) should have size (-2)
1234        }
1235        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size -2")
1236        // check((set: Map[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
1237      }
1238
1239      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
1240
1241        val caught1 = intercept[TestFailedException] {
1242          mutable.Map("one" -> 1, "two" -> 2) should { have size (5) and (have size (2 - 1)) }
1243        }
1244        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1245
1246        val caught2 = intercept[TestFailedException] {
1247          mutable.Map("one" -> 1, "two" -> 2) should ((have size (5)) and (have size (2 - 1)))
1248        }
1249        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1250
1251        val caught3 = intercept[TestFailedException] {
1252          mutable.Map("one" -> 1, "two" -> 2) should (have size (5) and have size (2 - 1))
1253        }
1254        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1255      }
1256
1257      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
1258
1259        val caught1 = intercept[TestFailedException] {
1260          mutable.Map("one" -> 1, "two" -> 2) should { have size (55) or (have size (22)) }
1261        }
1262        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1263
1264        val caught2 = intercept[TestFailedException] {
1265          mutable.Map("one" -> 1, "two" -> 2) should ((have size (55)) or (have size (22)))
1266        }
1267        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1268
1269        val caught3 = intercept[TestFailedException] {
1270          mutable.Map("one" -> 1, "two" -> 2) should (have size (55) or have size (22))
1271        }
1272        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1273      }
1274
1275      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
1276
1277        val caught1 = intercept[TestFailedException] {
1278          mutable.Map("one" -> 1, "two" -> 2) should { not { have size (3) } and not { have size (2) }}
1279        }
1280        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1281
1282        val caught2 = intercept[TestFailedException] {
1283          mutable.Map("one" -> 1, "two" -> 2) should ((not have size (3)) and (not have size (2)))
1284        }
1285        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1286
1287        val caught3 = intercept[TestFailedException] {
1288          mutable.Map("one" -> 1, "two" -> 2) should (not have size (3) and not have size (2))
1289        }
1290        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1291      }
1292
1293      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
1294
1295        val caught1 = intercept[TestFailedException] {
1296          mutable.Map("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (2) }}
1297        }
1298        assert(caught1.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1299
1300        val caught2 = intercept[TestFailedException] {
1301          mutable.Map("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (2)))
1302        }
1303        assert(caught2.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1304
1305        val caught3 = intercept[TestFailedException] {
1306          mutable.Map("one" -> 1, "two" -> 2) should (not have size (2) or not have size (2))
1307        }
1308        assert(caught3.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1309      }
1310    }
1311
1312    describe("on scala.collection.Map") {
1313
1314      val map: scala.collection.Map[String, Int] = Map("one" -> 1, "two" -> 2)
1315
1316      it("should do nothing if set size matches specified size") {
1317        map should have size (2)
1318        Map(1 -> "one", 2 -> "two") should have size (2)
1319        // check((set: Map[Int]) => returnsNormally(set should have size (set.size)))
1320      }
1321
1322      it("should do nothing if set size does not match and used with should not") {
1323        map should not { have size (3) }
1324        map should not have size (3)
1325        // check((set: Map[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
1326      }
1327
1328      it("should do nothing when set size matches and used in a logical-and expression") {
1329        map should { have size (2) and (have size (3 - 1)) }
1330        map should ((have size (2)) and (have size (3 - 1)))
1331        map should (have size (2) and have size (3 - 1))
1332      }
1333
1334      it("should do nothing when set size matches and used in a logical-or expression") {
1335        map should { have size (77) or (have size (3 - 1)) }
1336        map should ((have size (77)) or (have size (3 - 1)))
1337        map should (have size (77) or have size (3 - 1))
1338      }
1339
1340      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
1341        map should { not { have size (5) } and not { have size (3) }}
1342        map should ((not have size (5)) and (not have size (3)))
1343        map should (not have size (5) and not have size (3))
1344      }
1345
1346      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
1347        map should { not { have size (2) } or not { have size (3) }}
1348        map should ((not have size (2)) or (not have size (3)))
1349        map should (not have size (2) or not have size (3))
1350      }
1351
1352      it("should throw TestFailedException if set size does not match specified size") {
1353        val caught1 = intercept[TestFailedException] {
1354          map should have size (3)
1355        }
1356        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3")
1357        // check((set: Map[String]) => throwsTestFailedException(set should have size (set.size + 1)))
1358      }
1359
1360      it("should throw TestFailedException with normal error message if specified size is negative") {
1361        val caught1 = intercept[TestFailedException] {
1362          map should have size (-2)
1363        }
1364        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size -2")
1365        // check((set: Map[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
1366      }
1367
1368      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
1369
1370        val caught1 = intercept[TestFailedException] {
1371          map should { have size (5) and (have size (2 - 1)) }
1372        }
1373        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1374
1375        val caught2 = intercept[TestFailedException] {
1376          map should ((have size (5)) and (have size (2 - 1)))
1377        }
1378        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1379
1380        val caught3 = intercept[TestFailedException] {
1381          map should (have size (5) and have size (2 - 1))
1382        }
1383        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1384      }
1385
1386      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
1387
1388        val caught1 = intercept[TestFailedException] {
1389          map should { have size (55) or (have size (22)) }
1390        }
1391        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1392
1393        val caught2 = intercept[TestFailedException] {
1394          map should ((have size (55)) or (have size (22)))
1395        }
1396        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1397
1398        val caught3 = intercept[TestFailedException] {
1399          map should (have size (55) or have size (22))
1400        }
1401        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1402      }
1403
1404      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
1405
1406        val caught1 = intercept[TestFailedException] {
1407          map should { not { have size (3) } and not { have size (2) }}
1408        }
1409        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1410
1411        val caught2 = intercept[TestFailedException] {
1412          map should ((not have size (3)) and (not have size (2)))
1413        }
1414        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1415
1416        val caught3 = intercept[TestFailedException] {
1417          map should (not have size (3) and not have size (2))
1418        }
1419        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1420      }
1421
1422      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
1423
1424        val caught1 = intercept[TestFailedException] {
1425          map should { not { have size (2) } or not { have size (2) }}
1426        }
1427        assert(caught1.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1428
1429        val caught2 = intercept[TestFailedException] {
1430          map should ((not have size (2)) or (not have size (2)))
1431        }
1432        assert(caught2.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1433
1434        val caught3 = intercept[TestFailedException] {
1435          map should (not have size (2) or not have size (2))
1436        }
1437        assert(caught3.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1438      }
1439    }
1440
1441    describe("on scala.collection.immutable.HashMap") {
1442
1443      import scala.collection.immutable.HashMap
1444
1445      it("should do nothing if set size matches specified size") {
1446        HashMap("one" -> 1, "two" -> 2) should have size (2)
1447        HashMap(1 -> "one", 2 -> "two") should have size (2)
1448        // check((set: Map[Int]) => returnsNormally(set should have size (set.size)))
1449      }
1450
1451      it("should do nothing if set size does not match and used with should not") {
1452        HashMap("one" -> 1, "two" -> 2) should not { have size (3) }
1453        HashMap("one" -> 1, "two" -> 2) should not have size (3)
1454        // check((set: Map[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
1455      }
1456
1457      it("should do nothing when set size matches and used in a logical-and expression") {
1458        HashMap("one" -> 1, "two" -> 2) should { have size (2) and (have size (3 - 1)) }
1459        HashMap("one" -> 1, "two" -> 2) should ((have size (2)) and (have size (3 - 1)))
1460        HashMap("one" -> 1, "two" -> 2) should (have size (2) and have size (3 - 1))
1461      }
1462
1463      it("should do nothing when set size matches and used in a logical-or expression") {
1464        HashMap("one" -> 1, "two" -> 2) should { have size (77) or (have size (3 - 1)) }
1465        HashMap("one" -> 1, "two" -> 2) should ((have size (77)) or (have size (3 - 1)))
1466        HashMap("one" -> 1, "two" -> 2) should (have size (77) or have size (3 - 1))
1467      }
1468
1469      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
1470        HashMap("one" -> 1, "two" -> 2) should { not { have size (5) } and not { have size (3) }}
1471        HashMap("one" -> 1, "two" -> 2) should ((not have size (5)) and (not have size (3)))
1472        HashMap("one" -> 1, "two" -> 2) should (not have size (5) and not have size (3))
1473      }
1474
1475      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
1476        HashMap("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (3) }}
1477        HashMap("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (3)))
1478        HashMap("one" -> 1, "two" -> 2) should (not have size (2) or not have size (3))
1479      }
1480
1481      it("should throw TestFailedException if set size does not match specified size") {
1482        val caught1 = intercept[TestFailedException] {
1483          HashMap("one" -> 1, "two" -> 2) should have size (3)
1484        }
1485        assert(caught1.getMessage startsWith "Map(")
1486        assert(caught1.getMessage endsWith ") did not have size 3")
1487        // check((set: Map[String]) => throwsTestFailedException(set should have size (set.size + 1)))
1488      }
1489
1490      it("should throw TestFailedException with normal error message if specified size is negative") {
1491        val caught1 = intercept[TestFailedException] {
1492          HashMap("one" -> 1, "two" -> 2) should have size (-2)
1493        }
1494        assert(caught1.getMessage startsWith "Map(")
1495        assert(caught1.getMessage endsWith ") did not have size -2")
1496        // check((set: Map[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
1497      }
1498
1499      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
1500
1501        val caught1 = intercept[TestFailedException] {
1502          HashMap("one" -> 1, "two" -> 2) should { have size (5) and (have size (2 - 1)) }
1503        }
1504        assert(caught1.getMessage startsWith "Map(")
1505        assert(caught1.getMessage endsWith ") did not have size 5")
1506
1507        val caught2 = intercept[TestFailedException] {
1508          HashMap("one" -> 1, "two" -> 2) should ((have size (5)) and (have size (2 - 1)))
1509        }
1510        assert(caught2.getMessage startsWith "Map(")
1511        assert(caught2.getMessage endsWith ") did not have size 5")
1512
1513        val caught3 = intercept[TestFailedException] {
1514          HashMap("one" -> 1, "two" -> 2) should (have size (5) and have size (2 - 1))
1515        }
1516        assert(caught3.getMessage startsWith "Map(")
1517        assert(caught3.getMessage endsWith ") did not have size 5")
1518      }
1519
1520      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
1521
1522        val caught1 = intercept[TestFailedException] {
1523          HashMap("one" -> 1, "two" -> 2) should { have size (55) or (have size (22)) }
1524        }
1525        assert(caught1.getMessage startsWith "Map(")
1526        assert(caught1.getMessage contains ") did not have size 55, and Map(")
1527        assert(caught1.getMessage endsWith ") did not have size 22")
1528
1529        val caught2 = intercept[TestFailedException] {
1530          HashMap("one" -> 1, "two" -> 2) should ((have size (55)) or (have size (22)))
1531        }
1532        assert(caught2.getMessage startsWith "Map(")
1533        assert(caught2.getMessage contains ") did not have size 55, and Map(")
1534        assert(caught2.getMessage endsWith ") did not have size 22")
1535
1536        val caught3 = intercept[TestFailedException] {
1537          HashMap("one" -> 1, "two" -> 2) should (have size (55) or have size (22))
1538        }
1539        assert(caught3.getMessage startsWith "Map(")
1540        assert(caught3.getMessage contains ") did not have size 55, and Map(")
1541        assert(caught3.getMessage endsWith ") did not have size 22")
1542      }
1543
1544      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
1545
1546        val caught1 = intercept[TestFailedException] {
1547          HashMap("one" -> 1, "two" -> 2) should { not { have size (3) } and not { have size (2) }}
1548        }
1549        assert(caught1.getMessage startsWith "Map(")
1550        assert(caught1.getMessage contains ") did not have size 3, but Map(")
1551        assert(caught1.getMessage endsWith ") had size 2")
1552
1553        val caught2 = intercept[TestFailedException] {
1554          HashMap("one" -> 1, "two" -> 2) should ((not have size (3)) and (not have size (2)))
1555        }
1556        assert(caught2.getMessage startsWith "Map(")
1557        assert(caught2.getMessage contains ") did not have size 3, but Map(")
1558        assert(caught2.getMessage endsWith ") had size 2")
1559
1560        val caught3 = intercept[TestFailedException] {
1561          HashMap("one" -> 1, "two" -> 2) should (not have size (3) and not have size (2))
1562        }
1563        assert(caught3.getMessage startsWith "Map(")
1564        assert(caught3.getMessage contains ") did not have size 3, but Map(")
1565        assert(caught3.getMessage endsWith ") had size 2")
1566      }
1567
1568      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
1569
1570        val caught1 = intercept[TestFailedException] {
1571          HashMap("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (2) }}
1572        }
1573        assert(caught1.getMessage startsWith "Map(")
1574        assert(caught1.getMessage contains ") had size 2, and Map(")
1575        assert(caught1.getMessage endsWith ") had size 2")
1576
1577        val caught2 = intercept[TestFailedException] {
1578          HashMap("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (2)))
1579        }
1580        assert(caught2.getMessage startsWith "Map(")
1581        assert(caught2.getMessage contains ") had size 2, and Map(")
1582        assert(caught2.getMessage endsWith ") had size 2")
1583
1584        val caught3 = intercept[TestFailedException] {
1585          HashMap("one" -> 1, "two" -> 2) should (not have size (2) or not have size (2))
1586        }
1587        assert(caught3.getMessage startsWith "Map(")
1588        assert(caught3.getMessage contains ") had size 2, and Map(")
1589        assert(caught3.getMessage endsWith ") had size 2")
1590      }
1591    }
1592
1593    describe("on scala.collection.mutable.HashMap") {
1594
1595      import scala.collection.mutable
1596
1597      it("should do nothing if set size matches specified size") {
1598        mutable.HashMap("one" -> 1, "two" -> 2) should have size (2)
1599        mutable.HashMap(1 -> "one", 2 -> "two") should have size (2)
1600        // check((set: Map[Int]) => returnsNormally(set should have size (set.size)))
1601      }
1602
1603      it("should do nothing if set size does not match and used with should not") {
1604        mutable.HashMap("one" -> 1, "two" -> 2) should not { have size (3) }
1605        mutable.HashMap("one" -> 1, "two" -> 2) should not have size (3)
1606        // check((set: Map[Int], i: Int) => i != set.size ==> returnsNormally(set should not { have size (i) }))
1607      }
1608
1609      it("should do nothing when set size matches and used in a logical-and expression") {
1610        mutable.HashMap("one" -> 1, "two" -> 2) should { have size (2) and (have size (3 - 1)) }
1611        mutable.HashMap("one" -> 1, "two" -> 2) should ((have size (2)) and (have size (3 - 1)))
1612        mutable.HashMap("one" -> 1, "two" -> 2) should (have size (2) and have size (3 - 1))
1613      }
1614
1615      it("should do nothing when set size matches and used in a logical-or expression") {
1616        mutable.HashMap("one" -> 1, "two" -> 2) should { have size (77) or (have size (3 - 1)) }
1617        mutable.HashMap("one" -> 1, "two" -> 2) should ((have size (77)) or (have size (3 - 1)))
1618        mutable.HashMap("one" -> 1, "two" -> 2) should (have size (77) or have size (3 - 1))
1619      }
1620
1621      it("should do nothing when set size doesn't match and used in a logical-and expression with not") {
1622        mutable.HashMap("one" -> 1, "two" -> 2) should { not { have size (5) } and not { have size (3) }}
1623        mutable.HashMap("one" -> 1, "two" -> 2) should ((not have size (5)) and (not have size (3)))
1624        mutable.HashMap("one" -> 1, "two" -> 2) should (not have size (5) and not have size (3))
1625      }
1626
1627      it("should do nothing when set size doesn't match and used in a logical-or expression with not") {
1628        mutable.HashMap("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (3) }}
1629        mutable.HashMap("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (3)))
1630        mutable.HashMap("one" -> 1, "two" -> 2) should (not have size (2) or not have size (3))
1631      }
1632
1633      it("should throw TestFailedException if set size does not match specified size") {
1634        val caught1 = intercept[TestFailedException] {
1635          mutable.HashMap("one" -> 1, "two" -> 2) should have size (3)
1636        }
1637        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3")
1638        // check((set: Map[String]) => throwsTestFailedException(set should have size (set.size + 1)))
1639      }
1640
1641      it("should throw TestFailedException with normal error message if specified size is negative") {
1642        val caught1 = intercept[TestFailedException] {
1643          mutable.HashMap("one" -> 1, "two" -> 2) should have size (-2)
1644        }
1645        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size -2")
1646        // check((set: Map[Int]) => throwsTestFailedException(set should have size (if (set.size == 0) -1 else -set.size)))
1647      }
1648
1649      it("should throw an assertion error when set size doesn't match and used in a logical-and expression") {
1650
1651        val caught1 = intercept[TestFailedException] {
1652          mutable.HashMap("one" -> 1, "two" -> 2) should { have size (5) and (have size (2 - 1)) }
1653        }
1654        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1655
1656        val caught2 = intercept[TestFailedException] {
1657          mutable.HashMap("one" -> 1, "two" -> 2) should ((have size (5)) and (have size (2 - 1)))
1658        }
1659        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1660
1661        val caught3 = intercept[TestFailedException] {
1662          mutable.HashMap("one" -> 1, "two" -> 2) should (have size (5) and have size (2 - 1))
1663        }
1664        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 5")
1665      }
1666
1667      it("should throw an assertion error when set size doesn't match and used in a logical-or expression") {
1668
1669        val caught1 = intercept[TestFailedException] {
1670          mutable.HashMap("one" -> 1, "two" -> 2) should { have size (55) or (have size (22)) }
1671        }
1672        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1673
1674        val caught2 = intercept[TestFailedException] {
1675          mutable.HashMap("one" -> 1, "two" -> 2) should ((have size (55)) or (have size (22)))
1676        }
1677        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1678
1679        val caught3 = intercept[TestFailedException] {
1680          mutable.HashMap("one" -> 1, "two" -> 2) should (have size (55) or have size (22))
1681        }
1682        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 55, and Map(one -> 1, two -> 2) did not have size 22")
1683      }
1684
1685      it("should throw an assertion error when set size matches and used in a logical-and expression with not") {
1686
1687        val caught1 = intercept[TestFailedException] {
1688          mutable.HashMap("one" -> 1, "two" -> 2) should { not { have size (3) } and not { have size (2) }}
1689        }
1690        assert(caught1.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1691
1692        val caught2 = intercept[TestFailedException] {
1693          mutable.HashMap("one" -> 1, "two" -> 2) should ((not have size (3)) and (not have size (2)))
1694        }
1695        assert(caught2.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1696
1697        val caught3 = intercept[TestFailedException] {
1698          mutable.HashMap("one" -> 1, "two" -> 2) should (not have size (3) and not have size (2))
1699        }
1700        assert(caught3.getMessage === "Map(one -> 1, two -> 2) did not have size 3, but Map(one -> 1, two -> 2) had size 2")
1701      }
1702
1703      it("should throw an assertion error when set size matches and used in a logical-or expression with not") {
1704
1705        val caught1 = intercept[TestFailedException] {
1706          mutable.HashMap("one" -> 1, "two" -> 2) should { not { have size (2) } or not { have size (2) }}
1707        }
1708        assert(caught1.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1709
1710        val caught2 = intercept[TestFailedException] {
1711          mutable.HashMap("one" -> 1, "two" -> 2) should ((not have size (2)) or (not have size (2)))
1712        }
1713        assert(caught2.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1714
1715        val caught3 = intercept[TestFailedException] {
1716          mutable.HashMap("one" -> 1, "two" -> 2) should (not have size (2) or not have size (2))
1717        }
1718        assert(caught3.getMessage === "Map(one -> 1, two -> 2) had size 2, and Map(one -> 1, two -> 2) had size 2")
1719      }
1720    }
1721
1722    describe("on java.util.Set") {
1723
1724      val javaSet: java.util.Set[Int] = new java.util.HashSet
1725      javaSet.add(1)
1726      javaSet.add(2)
1727
1728      it("should do nothing if list size matches specified size") {
1729        javaSet should have size (2)
1730        // check((lst: java.util.List[Int]) => returnsNormally(lst should have size (lst.size)))
1731      }
1732
1733      it("should do nothing if list size does not match and used with should not") {
1734        javaSet should not { have size (3) }
1735        javaSet should not have size (3)
1736        // check((lst: List[Int], i: Int) => i != lst.size ==> returnsNormally(lst should not { have size (i) }))
1737      }
1738
1739      it("should do nothing when list size matches and used in a logical-and expression") {
1740        javaSet should { have size (2) and (have size (3 - 1)) }
1741        javaSet should ((have size (2)) and (have size (3 - 1)))
1742        javaSet should (have size (2) and have size (3 - 1))
1743      }
1744
1745      it("should do nothing when list size matches and used in a logical-or expression") {
1746        javaSet should { have size (77) or (have size (3 - 1)) }
1747        javaSet should ((have size (77)) or (have size (3 - 1)))
1748        javaSet should (have size (77) or have size (3 - 1))
1749      }
1750
1751      it("should do nothing when list size doesn't match and used in a logical-and expression with not") {
1752        javaSet should { not { have size (5) } and not { have size (3) }}
1753        javaSet should ((not have size (5)) and (not have size (3)))
1754        javaSet should (not have size (5) and not have size (3))
1755      }
1756
1757      it("should do nothing when list size doesn't match and used in a logical-or expression with not") {
1758        javaSet should { not { have size (2) } or not { have size (3) }}
1759        javaSet should ((not have size (2)) or (not have size (3)))
1760        javaSet should (not have size (2) or not have size (3))
1761      }
1762
1763      it("should throw TestFailedException if list size does not match specified size") {
1764        val caught1 = intercept[TestFailedException] {
1765          javaSet should have size (3)
1766        }
1767        caught1.getMessage should (be === "[2, 1] did not have size 3" or
1768          be === "[1, 2] did not have size 3")
1769      }
1770
1771      it("should throw TestFailedException with normal error message if specified size is negative") {
1772        val caught1 = intercept[TestFailedException] {
1773          javaSet should have size (-2)
1774        }
1775        caught1.getMessage should (be === "[2, 1] did not have size -2" or
1776          be === "[1, 2] did not have size -2")
1777      }
1778
1779      it("should throw an assertion error when list size doesn't match and used in a logical-and expression") {
1780
1781        val caught1 = intercept[TestFailedException] {
1782          javaSet should { have size (5) and (have size (2 - 1)) }
1783        }
1784        caught1.getMessage should (be === "[2, 1] did not have size 5" or
1785          be === "[1, 2] did not have size 5")
1786
1787        val caught2 = intercept[TestFailedException] {
1788          javaSet should ((have size (5)) and (have size (2 - 1)))
1789        }
1790        caught2.getMessage should (be === "[2, 1] did not have size 5" or
1791          be === "[1, 2] did not have size 5")
1792
1793        val caught3 = intercept[TestFailedException] {
1794          javaSet should (have size (5) and have size (2 - 1))
1795        }
1796        caught3.getMessage should (be === "[2, 1] did not have size 5" or
1797          be === "[1, 2] did not have size 5")
1798      }
1799
1800      it("should throw an assertion error when list size doesn't match and used in a logical-or expression") {
1801
1802        val caught1 = intercept[TestFailedException] {
1803          javaSet should { have size (55) or (have size (22)) }
1804        }
1805        caught1.getMessage should (be === "[2, 1] did not have size 55, and [2, 1] did not have size 22" or
1806          be === "[1, 2] did not have size 55, and [1, 2] did not have size 22")
1807
1808        val caught2 = intercept[TestFailedException] {
1809          javaSet should ((have size (55)) or (have size (22)))
1810        }
1811        caught2.getMessage should (be === "[2, 1] did not have size 55, and [2, 1] did not have size 22" or
1812          be === "[1, 2] did not have size 55, and [1, 2] did not have size 22")
1813
1814        val caught3 = intercept[TestFailedException] {
1815          javaSet should (have size (55) or have size (22))
1816        }
1817        caught3.getMessage should (be === "[2, 1] did not have size 55, and [2, 1] did not have size 22" or
1818          be === "[1, 2] did not have size 55, and [1, 2] did not have size 22")
1819      }
1820
1821      it("should throw an assertion error when list size matches and used in a logical-and expression with not") {
1822
1823        val caught1 = intercept[TestFailedException] {
1824          javaSet should { not { have size (3) } and not { have size (2) }}
1825        }
1826        caught1.getMessage should (be === "[2, 1] did not have size 3, but [2, 1] had size 2" or
1827          be === "[1, 2] did not have size 3, but [1, 2] had size 2")
1828
1829        val caught2 = intercept[TestFailedException] {
1830          javaSet should ((not have size (3)) and (not have size (2)))
1831        }
1832        caught2.getMessage should (be === "[2, 1] did not have size 3, but [2, 1] had size 2" or
1833          be === "[1, 2] did not have size 3, but [1, 2] had size 2")
1834
1835        val caught3 = intercept[TestFailedException] {
1836          javaSet should (not have size (3) and not have size (2))
1837        }
1838        caught3.getMessage should (be === "[2, 1] did not have size 3, but [2, 1] had size 2" or
1839          be === "[1, 2] did not have size 3, but [1, 2] had size 2")
1840      }
1841
1842      it("should throw an assertion error when list size matches and used in a logical-or expression with not") {
1843
1844        val caught1 = intercept[TestFailedException] {
1845          javaSet should { not { have size (2) } or not { have size (2) }}
1846        }
1847        caught1.getMessage should (be === "[2, 1] had size 2, and [2, 1] had size 2" or
1848          be === "[1, 2] had size 2, and [1, 2] had size 2")
1849
1850        val caught2 = intercept[TestFailedException] {
1851          javaSet should ((not have size (2)) or (not have size (2)))
1852        }
1853        caught2.getMessage should (be === "[2, 1] had size 2, and [2, 1] had size 2" or
1854          be === "[1, 2] had size 2, and [1, 2] had size 2")
1855
1856        val caught3 = intercept[TestFailedException] {
1857          javaSet should (not have size (2) or not have size (2))
1858        }
1859        caught3.getMessage should (be === "[2, 1] had size 2, and [2, 1] had size 2" or
1860          be === "[1, 2] had size 2, and [1, 2] had size 2")
1861      }
1862    }
1863
1864    describe("on java.util.Map") {
1865
1866      val javaMap: java.util.Map[String, Int] = new java.util.HashMap
1867      javaMap.put("one",1)
1868      javaMap.put("two", 2)
1869
1870      it("should do nothing if list size matches specified size") {
1871        javaMap should have size (2)
1872        // check((lst: java.util.List[Int]) => returnsNormally(lst should have size (lst.size)))
1873      }
1874
1875      it("should do nothing if list size does not match and used with should not") {
1876        javaMap should not { have size (3) }
1877        // check((lst: List[Int], i: Int) => i != lst.size ==> returnsNormally(lst should not { have size (i) }))
1878      }
1879
1880      it("should do nothing when list size matches and used in a logical-and expression") {
1881        javaMap should { have size (2) and (have size (3 - 1)) }
1882        javaMap should ((have size (2)) and (have size (3 - 1)))
1883        javaMap should (have size (2) and have size (3 - 1))
1884      }
1885
1886      it("should do nothing when list size matches and used in a logical-or expression") {
1887        javaMap should { have size (77) or (have size (3 - 1)) }
1888        javaMap should ((have size (77)) or (have size (3 - 1)))
1889        javaMap should (have size (77) or have size (3 - 1))
1890      }
1891
1892      it("should do nothing when list size doesn't match and used in a logical-and expression with not") {
1893        javaMap should { not { have size (5) } and not { have size (3) }}
1894        javaMap should ((not have size (5)) and (not have size (3)))
1895        javaMap should (not have size (5) and not have size (3))
1896      }
1897
1898      it("should do nothing when list size doesn't match and used in a logical-or expression with not") {
1899        javaMap should { not { have size (2) } or not { have size (3) }}
1900        javaMap should ((not have size (2)) or (not have size (3)))
1901        javaMap should (not have size (2) or not have size (3))
1902      }
1903
1904      it("should throw TestFailedException if list size does not match specified size") {
1905        val caught1 = intercept[TestFailedException] {
1906          javaMap should have size (3)
1907        }
1908        caught1.getMessage should (be === "{one=1, two=2} did not have size 3" or
1909          be === "{two=2, one=1} did not have size 3")
1910      }
1911
1912      it("should throw TestFailedException with normal error message if specified size is negative") {
1913        val caught1 = intercept[TestFailedException] {
1914          javaMap should have size (-2)
1915        }
1916        caught1.getMessage should (be === "{one=1, two=2} did not have size -2" or
1917          be === "{two=2, one=1} did not have size -2")
1918      }
1919
1920      it("should throw an assertion error when list size doesn't match and used in a logical-and expression") {
1921
1922        val caught1 = intercept[TestFailedException] {
1923          javaMap should { have size (5) and (have size (2 - 1)) }
1924        }
1925        caught1.getMessage should (be === "{one=1, two=2} did not have size 5" or
1926          be === "{two=2, one=1} did not have size 5")
1927
1928        val caught2 = intercept[TestFailedException] {
1929          javaMap should ((have size (5)) and (have size (2 - 1)))
1930        }
1931        caught2.getMessage should (be === "{one=1, two=2} did not have size 5" or
1932          be === "{two=2, one=1} did not have size 5")
1933
1934        val caught3 = intercept[TestFailedException] {
1935          javaMap should (have size (5) and have size (2 - 1))
1936        }
1937        caught3.getMessage should (be === "{one=1, two=2} did not have size 5" or
1938          be === "{two=2, one=1} did not have size 5")
1939      }
1940
1941      it("should throw an assertion error when list size doesn't match and used in a logical-or expression") {
1942
1943        val caught1 = intercept[TestFailedException] {
1944          javaMap should { have size (55) or (have size (22)) }
1945        }
1946        caught1.getMessage should (be === "{one=1, two=2} did not have size 55, and {one=1, two=2} did not have size 22" or
1947          be === "{two=2, one=1} did not have size 55, and {two=2, one=1} did not have size 22")
1948
1949        val caught2 = intercept[TestFailedException] {
1950          javaMap should ((have size (55)) or (have size (22)))
1951        }
1952        caught2.getMessage should (be === "{one=1, two=2} did not have size 55, and {one=1, two=2} did not have size 22" or
1953          be === "{two=2, one=1} did not have size 55, and {two=2, one=1} did not have size 22")
1954
1955        val caught3 = intercept[TestFailedException] {
1956          javaMap should (have size (55) or have size (22))
1957        }
1958        caught3.getMessage should (be === "{one=1, two=2} did not have size 55, and {one=1, two=2} did not have size 22" or
1959          be === "{two=2, one=1} did not have size 55, and {two=2, one=1} did not have size 22")
1960      }
1961
1962      it("should throw an assertion error when list size matches and used in a logical-and expression with not") {
1963
1964        val caught1 = intercept[TestFailedException] {
1965          javaMap should { not { have size (3) } and not { have size (2) }}
1966        }
1967        caught1.getMessage should (be === "{one=1, two=2} did not have size 3, but {one=1, two=2} had size 2" or
1968          be === "{two=2, one=1} did not have size 3, but {two=2, one=1} had size 2")
1969
1970        val caught2 = intercept[TestFailedException] {
1971          javaMap should ((not have size (3)) and (not have size (2)))
1972        }
1973        caught2.getMessage should (be === "{one=1, two=2} did not have size 3, but {one=1, two=2} had size 2" or
1974          be === "{two=2, one=1} did not have size 3, but {two=2, one=1} had size 2")
1975
1976        val caught3 = intercept[TestFailedException] {
1977          javaMap should (not have size (3) and not have size (2))
1978        }
1979        caught3.getMessage should (be === "{one=1, two=2} did not have size 3, but {one=1, two=2} had size 2" or
1980          be === "{two=2, one=1} did not have size 3, but {two=2, one=1} had size 2")
1981      }
1982
1983      it("should throw an assertion error when list size matches and used in a logical-or expression with not") {
1984
1985        val caught1 = intercept[TestFailedException] {
1986          javaMap should { not { have size (2) } or not { have size (2) }}
1987        }
1988        caught1.getMessage should (be === "{one=1, two=2} had size 2, and {one=1, two=2} had size 2" or
1989          be === "{two=2, one=1} had size 2, and {two=2, one=1} had size 2")
1990
1991        val caught2 = intercept[TestFailedException] {
1992          javaMap should ((not have size (2)) or (not have size (2)))
1993        }
1994        caught2.getMessage should (be === "{one=1, two=2} had size 2, and {one=1, two=2} had size 2" or
1995          be === "{two=2, one=1} had size 2, and {two=2, one=1} had size 2")
1996
1997        val caught3 = intercept[TestFailedException] {
1998          javaMap should (not have size (2) or not have size (2))
1999        }
2000        caught3.getMessage should (be === "{one=1, two=2} had size 2, and {one=1, two=2} had size 2" or
2001          be === "{two=2, one=1} had size 2, and {two=2, one=1} had size 2")
2002      }
2003    }
2004
2005    // I repeat these with copy and paste, becuase I need to test that each static structural type works, and
2006    // that makes it hard to pass them to a common "behaves like" method
2007    describe("on an arbitrary object that has an empty-paren Int size method") {
2008
2009      class Sizey(len: Int) {
2010        def size(): Int = len
2011        override def toString = "sizey"
2012      }
2013      val obj = new Sizey(2)
2014
2015      it("should do nothing if object size matches specified size") {
2016        obj should have size (2)
2017        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2018      }
2019
2020      it("should do nothing if object size does not match and used with should not") {
2021        obj should not { have size (3) }
2022        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2023      }
2024
2025      it("should do nothing when object size matches and used in a logical-and expression") {
2026        obj should { have size (2) and (have size (3 - 1)) }
2027        obj should ((have size (2)) and (have size (3 - 1)))
2028        obj should (have size (2) and have size (3 - 1))
2029      }
2030
2031      it("should do nothing when object size matches and used in a logical-or expression") {
2032        obj should { have size (77) or (have size (3 - 1)) }
2033        obj should ((have size (77)) or (have size (3 - 1)))
2034        obj should (have size (77) or have size (3 - 1))
2035      }
2036
2037      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2038        obj should { not { have size (5) } and not { have size (3) }}
2039        obj should ((not have size (5)) and (not have size (3)))
2040        obj should (not have size (5) and not have size (3))
2041      }
2042
2043      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2044        obj should { not { have size (2) } or not { have size (3) }}
2045        obj should ((not have size (2)) or (not have size (3)))
2046        obj should (not have size (2) or not have size (3))
2047      }
2048
2049      it("should throw TestFailedException if object size does not match specified size") {
2050        val caught1 = intercept[TestFailedException] {
2051          obj should have size (3)
2052        }
2053        assert(caught1.getMessage === "sizey did not have size 3")
2054        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2055      }
2056
2057      it("should throw TestFailedException with normal error message if specified size is negative") {
2058        val caught1 = intercept[TestFailedException] {
2059          obj should have size (-2)
2060        }
2061        assert(caught1.getMessage === "sizey did not have size -2")
2062        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2063      }
2064
2065      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2066
2067        val caught1 = intercept[TestFailedException] {
2068          obj should { have size (5) and (have size (2 - 1)) }
2069        }
2070        assert(caught1.getMessage === "sizey did not have size 5")
2071
2072        val caught2 = intercept[TestFailedException] {
2073          obj should ((have size (5)) and (have size (2 - 1)))
2074        }
2075        assert(caught2.getMessage === "sizey did not have size 5")
2076
2077        val caught3 = intercept[TestFailedException] {
2078          obj should (have size (5) and have size (2 - 1))
2079        }
2080        assert(caught3.getMessage === "sizey did not have size 5")
2081      }
2082
2083      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
2084
2085        val caught1 = intercept[TestFailedException] {
2086          obj should { have size (55) or (have size (22)) }
2087        }
2088        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2089
2090        val caught2 = intercept[TestFailedException] {
2091          obj should ((have size (55)) or (have size (22)))
2092        }
2093        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2094
2095        val caught3 = intercept[TestFailedException] {
2096          obj should (have size (55) or have size (22))
2097        }
2098        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2099      }
2100
2101      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
2102
2103        val caught1 = intercept[TestFailedException] {
2104          obj should { not { have size (3) } and not { have size (2) }}
2105        }
2106        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
2107
2108        val caught2 = intercept[TestFailedException] {
2109          obj should ((not have size (3)) and (not have size (2)))
2110        }
2111        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
2112
2113        val caught3 = intercept[TestFailedException] {
2114          obj should (not have size (3) and not have size (2))
2115        }
2116        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
2117      }
2118
2119      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
2120
2121        val caught1 = intercept[TestFailedException] {
2122          obj should { not { have size (2) } or not { have size (2) }}
2123        }
2124        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
2125
2126        val caught2 = intercept[TestFailedException] {
2127          obj should ((not have size (2)) or (not have size (2)))
2128        }
2129        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
2130
2131        val caught3 = intercept[TestFailedException] {
2132          obj should (not have size (2) or not have size (2))
2133        }
2134        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
2135      }
2136    }
2137
2138    describe("on an arbitrary object that has a parameterless Int size method") {
2139
2140      class Sizey(len: Int) {
2141        def size: Int = len  // The only difference between the previous is the structure of this member
2142        override def toString = "sizey"
2143      }
2144      val obj = new Sizey(2)
2145
2146      it("should do nothing if object size matches specified size") {
2147        obj should have size (2)
2148        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2149      }
2150
2151      it("should do nothing if object size does not match and used with should not") {
2152        obj should not { have size (3) }
2153        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2154      }
2155
2156      it("should do nothing when object size matches and used in a logical-and expression") {
2157        obj should { have size (2) and (have size (3 - 1)) }
2158        obj should ((have size (2)) and (have size (3 - 1)))
2159        obj should (have size (2) and have size (3 - 1))
2160      }
2161
2162      it("should do nothing when object size matches and used in a logical-or expression") {
2163        obj should { have size (77) or (have size (3 - 1)) }
2164        obj should ((have size (77)) or (have size (3 - 1)))
2165        obj should (have size (77) or have size (3 - 1))
2166      }
2167
2168      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2169        obj should { not { have size (5) } and not { have size (3) }}
2170        obj should ((not have size (5)) and (not have size (3)))
2171        obj should (not have size (5) and not have size (3))
2172      }
2173
2174      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2175        obj should { not { have size (2) } or not { have size (3) }}
2176        obj should ((not have size (2)) or (not have size (3)))
2177        obj should (not have size (2) or not have size (3))
2178      }
2179
2180      it("should throw TestFailedException if object size does not match specified size") {
2181        val caught1 = intercept[TestFailedException] {
2182          obj should have size (3)
2183        }
2184        assert(caught1.getMessage === "sizey did not have size 3")
2185        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2186      }
2187
2188      it("should throw TestFailedException with normal error message if specified size is negative") {
2189        val caught1 = intercept[TestFailedException] {
2190          obj should have size (-2)
2191        }
2192        assert(caught1.getMessage === "sizey did not have size -2")
2193        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2194      }
2195
2196      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2197
2198        val caught1 = intercept[TestFailedException] {
2199          obj should { have size (5) and (have size (2 - 1)) }
2200        }
2201        assert(caught1.getMessage === "sizey did not have size 5")
2202
2203        val caught2 = intercept[TestFailedException] {
2204          obj should ((have size (5)) and (have size (2 - 1)))
2205        }
2206        assert(caught2.getMessage === "sizey did not have size 5")
2207
2208        val caught3 = intercept[TestFailedException] {
2209          obj should (have size (5) and have size (2 - 1))
2210        }
2211        assert(caught3.getMessage === "sizey did not have size 5")
2212      }
2213
2214      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
2215
2216        val caught1 = intercept[TestFailedException] {
2217          obj should { have size (55) or (have size (22)) }
2218        }
2219        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2220
2221        val caught2 = intercept[TestFailedException] {
2222          obj should ((have size (55)) or (have size (22)))
2223        }
2224        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2225
2226        val caught3 = intercept[TestFailedException] {
2227          obj should (have size (55) or have size (22))
2228        }
2229        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2230      }
2231
2232      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
2233
2234        val caught1 = intercept[TestFailedException] {
2235          obj should { not { have size (3) } and not { have size (2) }}
2236        }
2237        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
2238
2239        val caught2 = intercept[TestFailedException] {
2240          obj should ((not have size (3)) and (not have size (2)))
2241        }
2242        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
2243
2244        val caught3 = intercept[TestFailedException] {
2245          obj should (not have size (3) and not have size (2))
2246        }
2247        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
2248      }
2249
2250      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
2251
2252        val caught1 = intercept[TestFailedException] {
2253          obj should { not { have size (2) } or not { have size (2) }}
2254        }
2255        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
2256
2257        val caught2 = intercept[TestFailedException] {
2258          obj should ((not have size (2)) or (not have size (2)))
2259        }
2260        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
2261
2262        val caught3 = intercept[TestFailedException] {
2263          obj should (not have size (2) or not have size (2))
2264        }
2265        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
2266      }
2267    }
2268
2269    describe("on an arbitrary object that has a Int size field") {
2270
2271      class Sizey(len: Int) {
2272        val size: Int = len // The only difference between the previous is the structure of this member
2273        override def toString = "sizey"
2274      }
2275      val obj = new Sizey(2)
2276
2277      it("should do nothing if object size matches specified size") {
2278        obj should have size (2)
2279        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2280      }
2281
2282      it("should do nothing if object size does not match and used with should not") {
2283        obj should not { have size (3) }
2284        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2285      }
2286
2287      it("should do nothing when object size matches and used in a logical-and expression") {
2288        obj should { have size (2) and (have size (3 - 1)) }
2289        obj should ((have size (2)) and (have size (3 - 1)))
2290        obj should (have size (2) and have size (3 - 1))
2291      }
2292
2293      it("should do nothing when object size matches and used in a logical-or expression") {
2294        obj should { have size (77) or (have size (3 - 1)) }
2295        obj should ((have size (77)) or (have size (3 - 1)))
2296        obj should (have size (77) or have size (3 - 1))
2297      }
2298
2299      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2300        obj should { not { have size (5) } and not { have size (3) }}
2301        obj should ((not have size (5)) and (not have size (3)))
2302        obj should (not have size (5) and not have size (3))
2303      }
2304
2305      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2306        obj should { not { have size (2) } or not { have size (3) }}
2307        obj should ((not have size (2)) or (not have size (3)))
2308        obj should (not have size (2) or not have size (3))
2309      }
2310
2311      it("should throw TestFailedException if object size does not match specified size") {
2312        val caught1 = intercept[TestFailedException] {
2313          obj should have size (3)
2314        }
2315        assert(caught1.getMessage === "sizey did not have size 3")
2316        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2317      }
2318
2319      it("should throw TestFailedException with normal error message if specified size is negative") {
2320        val caught1 = intercept[TestFailedException] {
2321          obj should have size (-2)
2322        }
2323        assert(caught1.getMessage === "sizey did not have size -2")
2324        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2325      }
2326
2327      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2328
2329        val caught1 = intercept[TestFailedException] {
2330          obj should { have size (5) and (have size (2 - 1)) }
2331        }
2332        assert(caught1.getMessage === "sizey did not have size 5")
2333
2334        val caught2 = intercept[TestFailedException] {
2335          obj should ((have size (5)) and (have size (2 - 1)))
2336        }
2337        assert(caught2.getMessage === "sizey did not have size 5")
2338
2339        val caught3 = intercept[TestFailedException] {
2340          obj should (have size (5) and have size (2 - 1))
2341        }
2342        assert(caught3.getMessage === "sizey did not have size 5")
2343      }
2344
2345      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
2346
2347        val caught1 = intercept[TestFailedException] {
2348          obj should { have size (55) or (have size (22)) }
2349        }
2350        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2351
2352        val caught2 = intercept[TestFailedException] {
2353          obj should ((have size (55)) or (have size (22)))
2354        }
2355        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2356
2357        val caught3 = intercept[TestFailedException] {
2358          obj should (have size (55) or have size (22))
2359        }
2360        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2361      }
2362
2363      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
2364
2365        val caught1 = intercept[TestFailedException] {
2366          obj should { not { have size (3) } and not { have size (2) }}
2367        }
2368        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
2369
2370        val caught2 = intercept[TestFailedException] {
2371          obj should ((not have size (3)) and (not have size (2)))
2372        }
2373        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
2374
2375        val caught3 = intercept[TestFailedException] {
2376          obj should (not have size (3) and not have size (2))
2377        }
2378        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
2379      }
2380
2381      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
2382
2383        val caught1 = intercept[TestFailedException] {
2384          obj should { not { have size (2) } or not { have size (2) }}
2385        }
2386        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
2387
2388        val caught2 = intercept[TestFailedException] {
2389          obj should ((not have size (2)) or (not have size (2)))
2390        }
2391        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
2392
2393        val caught3 = intercept[TestFailedException] {
2394          obj should (not have size (2) or not have size (2))
2395        }
2396        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
2397      }
2398    }
2399
2400    describe("on an arbitrary object that has an empty-paren Int getSize method") {
2401
2402      class Sizey(len: Int) {
2403        def getSize(): Int = len  // The only difference between the previous is the structure of this member
2404        override def toString = "sizey"
2405      }
2406      val obj = new Sizey(2)
2407
2408      it("should do nothing if object size matches specified size") {
2409        obj should have size (2)
2410        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2411      }
2412
2413      it("should do nothing if object size does not match and used with should not") {
2414        obj should not { have size (3) }
2415        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2416      }
2417
2418      it("should do nothing when object size matches and used in a logical-and expression") {
2419        obj should { have size (2) and (have size (3 - 1)) }
2420        obj should ((have size (2)) and (have size (3 - 1)))
2421        obj should (have size (2) and have size (3 - 1))
2422      }
2423
2424      it("should do nothing when object size matches and used in a logical-or expression") {
2425        obj should { have size (77) or (have size (3 - 1)) }
2426        obj should ((have size (77)) or (have size (3 - 1)))
2427        obj should (have size (77) or have size (3 - 1))
2428      }
2429
2430      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2431        obj should { not { have size (5) } and not { have size (3) }}
2432        obj should ((not have size (5)) and (not have size (3)))
2433        obj should (not have size (5) and not have size (3))
2434      }
2435
2436      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2437        obj should { not { have size (2) } or not { have size (3) }}
2438        obj should ((not have size (2)) or (not have size (3)))
2439        obj should (not have size (2) or not have size (3))
2440      }
2441
2442      it("should throw TestFailedException if object size does not match specified size") {
2443        val caught1 = intercept[TestFailedException] {
2444          obj should have size (3)
2445        }
2446        assert(caught1.getMessage === "sizey did not have size 3")
2447        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2448      }
2449
2450      it("should throw TestFailedException with normal error message if specified size is negative") {
2451        val caught1 = intercept[TestFailedException] {
2452          obj should have size (-2)
2453        }
2454        assert(caught1.getMessage === "sizey did not have size -2")
2455        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2456      }
2457
2458      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2459
2460        val caught1 = intercept[TestFailedException] {
2461          obj should { have size (5) and (have size (2 - 1)) }
2462        }
2463        assert(caught1.getMessage === "sizey did not have size 5")
2464
2465        val caught2 = intercept[TestFailedException] {
2466          obj should ((have size (5)) and (have size (2 - 1)))
2467        }
2468        assert(caught2.getMessage === "sizey did not have size 5")
2469
2470        val caught3 = intercept[TestFailedException] {
2471          obj should (have size (5) and have size (2 - 1))
2472        }
2473        assert(caught3.getMessage === "sizey did not have size 5")
2474      }
2475
2476      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
2477
2478        val caught1 = intercept[TestFailedException] {
2479          obj should { have size (55) or (have size (22)) }
2480        }
2481        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2482
2483        val caught2 = intercept[TestFailedException] {
2484          obj should ((have size (55)) or (have size (22)))
2485        }
2486        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2487
2488        val caught3 = intercept[TestFailedException] {
2489          obj should (have size (55) or have size (22))
2490        }
2491        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2492      }
2493
2494      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
2495
2496        val caught1 = intercept[TestFailedException] {
2497          obj should { not { have size (3) } and not { have size (2) }}
2498        }
2499        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
2500
2501        val caught2 = intercept[TestFailedException] {
2502          obj should ((not have size (3)) and (not have size (2)))
2503        }
2504        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
2505
2506        val caught3 = intercept[TestFailedException] {
2507          obj should (not have size (3) and not have size (2))
2508        }
2509        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
2510      }
2511
2512      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
2513
2514        val caught1 = intercept[TestFailedException] {
2515          obj should { not { have size (2) } or not { have size (2) }}
2516        }
2517        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
2518
2519        val caught2 = intercept[TestFailedException] {
2520          obj should ((not have size (2)) or (not have size (2)))
2521        }
2522        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
2523
2524        val caught3 = intercept[TestFailedException] {
2525          obj should (not have size (2) or not have size (2))
2526        }
2527        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
2528      }
2529    }
2530
2531    describe("on an arbitrary object that has a parameterless Int getSize method") {
2532
2533      class Sizey(len: Int) {
2534        def getSize: Int = len  // The only difference between the previous is the structure of this member
2535        override def toString = "sizey"
2536      }
2537      val obj = new Sizey(2)
2538
2539      it("should do nothing if object size matches specified size") {
2540        obj should have size (2)
2541        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2542      }
2543
2544      it("should do nothing if object size does not match and used with should not") {
2545        obj should not { have size (3) }
2546        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2547      }
2548
2549      it("should do nothing when object size matches and used in a logical-and expression") {
2550        obj should { have size (2) and (have size (3 - 1)) }
2551        obj should ((have size (2)) and (have size (3 - 1)))
2552        obj should (have size (2) and have size (3 - 1))
2553      }
2554
2555      it("should do nothing when object size matches and used in a logical-or expression") {
2556        obj should { have size (77) or (have size (3 - 1)) }
2557        obj should ((have size (77)) or (have size (3 - 1)))
2558        obj should (have size (77) or have size (3 - 1))
2559      }
2560
2561      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2562        obj should { not { have size (5) } and not { have size (3) }}
2563        obj should ((not have size (5)) and (not have size (3)))
2564        obj should (not have size (5) and not have size (3))
2565      }
2566
2567      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2568        obj should { not { have size (2) } or not { have size (3) }}
2569        obj should ((not have size (2)) or (not have size (3)))
2570        obj should (not have size (2) or not have size (3))
2571      }
2572
2573      it("should throw TestFailedException if object size does not match specified size") {
2574        val caught1 = intercept[TestFailedException] {
2575          obj should have size (3)
2576        }
2577        assert(caught1.getMessage === "sizey did not have size 3")
2578        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2579      }
2580
2581      it("should throw TestFailedException with normal error message if specified size is negative") {
2582        val caught1 = intercept[TestFailedException] {
2583          obj should have size (-2)
2584        }
2585        assert(caught1.getMessage === "sizey did not have size -2")
2586        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2587      }
2588
2589      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2590
2591        val caught1 = intercept[TestFailedException] {
2592          obj should { have size (5) and (have size (2 - 1)) }
2593        }
2594        assert(caught1.getMessage === "sizey did not have size 5")
2595
2596        val caught2 = intercept[TestFailedException] {
2597          obj should ((have size (5)) and (have size (2 - 1)))
2598        }
2599        assert(caught2.getMessage === "sizey did not have size 5")
2600
2601        val caught3 = intercept[TestFailedException] {
2602          obj should (have size (5) and have size (2 - 1))
2603        }
2604        assert(caught3.getMessage === "sizey did not have size 5")
2605      }
2606
2607      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
2608
2609        val caught1 = intercept[TestFailedException] {
2610          obj should { have size (55) or (have size (22)) }
2611        }
2612        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2613
2614        val caught2 = intercept[TestFailedException] {
2615          obj should ((have size (55)) or (have size (22)))
2616        }
2617        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2618
2619        val caught3 = intercept[TestFailedException] {
2620          obj should (have size (55) or have size (22))
2621        }
2622        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2623      }
2624
2625      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
2626
2627        val caught1 = intercept[TestFailedException] {
2628          obj should { not { have size (3) } and not { have size (2) }}
2629        }
2630        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
2631
2632        val caught2 = intercept[TestFailedException] {
2633          obj should ((not have size (3)) and (not have size (2)))
2634        }
2635        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
2636
2637        val caught3 = intercept[TestFailedException] {
2638          obj should (not have size (3) and not have size (2))
2639        }
2640        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
2641      }
2642
2643      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
2644
2645        val caught1 = intercept[TestFailedException] {
2646          obj should { not { have size (2) } or not { have size (2) }}
2647        }
2648        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
2649
2650        val caught2 = intercept[TestFailedException] {
2651          obj should ((not have size (2)) or (not have size (2)))
2652        }
2653        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
2654
2655        val caught3 = intercept[TestFailedException] {
2656          obj should (not have size (2) or not have size (2))
2657        }
2658        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
2659      }
2660    }
2661
2662    describe("on an arbitrary object that has an Int getSize field") {
2663
2664      class Sizey(len: Int) {
2665        val getSize: Int = len // The only difference between the previous is the structure of this member
2666        override def toString = "sizey"
2667      }
2668      val obj = new Sizey(2)
2669
2670      it("should do nothing if object size matches specified size") {
2671        obj should have size (2)
2672        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2673      }
2674
2675      it("should do nothing if object size does not match and used with should not") {
2676        obj should not { have size (3) }
2677        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2678      }
2679
2680      it("should do nothing when object size matches and used in a logical-and expression") {
2681        obj should { have size (2) and (have size (3 - 1)) }
2682        obj should ((have size (2)) and (have size (3 - 1)))
2683        obj should (have size (2) and have size (3 - 1))
2684      }
2685
2686      it("should do nothing when object size matches and used in a logical-or expression") {
2687        obj should { have size (77) or (have size (3 - 1)) }
2688        obj should ((have size (77)) or (have size (3 - 1)))
2689        obj should (have size (77) or have size (3 - 1))
2690      }
2691
2692      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2693        obj should { not { have size (5) } and not { have size (3) }}
2694        obj should ((not have size (5)) and (not have size (3)))
2695        obj should (not have size (5) and not have size (3))
2696      }
2697
2698      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2699        obj should { not { have size (2) } or not { have size (3) }}
2700        obj should ((not have size (2)) or (not have size (3)))
2701        obj should (not have size (2) or not have size (3))
2702      }
2703
2704      it("should throw TestFailedException if object size does not match specified size") {
2705        val caught1 = intercept[TestFailedException] {
2706          obj should have size (3)
2707        }
2708        assert(caught1.getMessage === "sizey did not have size 3")
2709        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2710      }
2711
2712      it("should throw TestFailedException with normal error message if specified size is negative") {
2713        val caught1 = intercept[TestFailedException] {
2714          obj should have size (-2)
2715        }
2716        assert(caught1.getMessage === "sizey did not have size -2")
2717        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2718      }
2719
2720      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2721
2722        val caught1 = intercept[TestFailedException] {
2723          obj should { have size (5) and (have size (2 - 1)) }
2724        }
2725        assert(caught1.getMessage === "sizey did not have size 5")
2726
2727        val caught2 = intercept[TestFailedException] {
2728          obj should ((have size (5)) and (have size (2 - 1)))
2729        }
2730        assert(caught2.getMessage === "sizey did not have size 5")
2731
2732        val caught3 = intercept[TestFailedException] {
2733          obj should (have size (5) and have size (2 - 1))
2734        }
2735        assert(caught3.getMessage === "sizey did not have size 5")
2736      }
2737
2738      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
2739
2740        val caught1 = intercept[TestFailedException] {
2741          obj should { have size (55) or (have size (22)) }
2742        }
2743        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2744
2745        val caught2 = intercept[TestFailedException] {
2746          obj should ((have size (55)) or (have size (22)))
2747        }
2748        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2749
2750        val caught3 = intercept[TestFailedException] {
2751          obj should (have size (55) or have size (22))
2752        }
2753        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2754      }
2755
2756      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
2757
2758        val caught1 = intercept[TestFailedException] {
2759          obj should { not { have size (3) } and not { have size (2) }}
2760        }
2761        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
2762
2763        val caught2 = intercept[TestFailedException] {
2764          obj should ((not have size (3)) and (not have size (2)))
2765        }
2766        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
2767
2768        val caught3 = intercept[TestFailedException] {
2769          obj should (not have size (3) and not have size (2))
2770        }
2771        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
2772      }
2773
2774      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
2775
2776        val caught1 = intercept[TestFailedException] {
2777          obj should { not { have size (2) } or not { have size (2) }}
2778        }
2779        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
2780
2781        val caught2 = intercept[TestFailedException] {
2782          obj should ((not have size (2)) or (not have size (2)))
2783        }
2784        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
2785
2786        val caught3 = intercept[TestFailedException] {
2787          obj should (not have size (2) or not have size (2))
2788        }
2789        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
2790      }
2791    }
2792
2793    describe("on an arbitrary object that has an empty-paren Long size method") {
2794
2795      class Sizey(len: Long) {
2796        def size(): Long = len
2797        override def toString = "sizey"
2798      }
2799      val obj = new Sizey(2)
2800
2801      it("should do nothing if object size matches specified size") {
2802        obj should have size (2)
2803        obj should have size (2L)
2804        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2805        check((len: Long) => returnsNormally(new Sizey(len) should have size (len)))
2806      }
2807
2808      it("should do nothing if object size does not match and used with should not") {
2809        obj should not { have size (3) }
2810        obj should not { have size (3L) }
2811        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2812        check((len: Long, wrongLen: Long) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2813      }
2814
2815      it("should do nothing when object size matches and used in a logical-and expression") {
2816        obj should { have size (2) and (have size (3 - 1)) }
2817        obj should { have size (2L) and (have size (3 - 1)) }
2818        obj should ((have size (2)) and (have size (3 - 1)))
2819        obj should ((have size (2L)) and (have size (3 - 1)))
2820        obj should (have size (2) and have size (3 - 1))
2821        obj should (have size (2L) and have size (3 - 1))
2822      }
2823
2824      it("should do nothing when object size matches and used in a logical-or expression") {
2825        obj should { have size (77) or (have size (2L)) }
2826        obj should { have size (77L) or (have size (2)) }
2827      }
2828
2829      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2830        obj should { not { have size (5) } and not { have size (3) }}
2831        obj should ((not have size (5)) and (not have size (3)))
2832        obj should (not have size (5) and not have size (3))
2833      }
2834
2835      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2836        obj should { not { have size (2) } or not { have size (3) }}
2837        obj should ((not have size (2)) or (not have size (3)))
2838        obj should (not have size (2) or not have size (3))
2839      }
2840
2841      it("should throw TestFailedException if object size does not match specified size") {
2842        val caught1 = intercept[TestFailedException] {
2843          obj should have size (3)
2844        }
2845        assert(caught1.getMessage === "sizey did not have size 3")
2846        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2847      }
2848
2849      it("should throw TestFailedException with normal error message if specified size is negative") {
2850        val caught1 = intercept[TestFailedException] {
2851          obj should have size (-2)
2852        }
2853        assert(caught1.getMessage === "sizey did not have size -2")
2854        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2855      }
2856
2857      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2858
2859        val caught1 = intercept[TestFailedException] {
2860          obj should { have size (5) and (have size (2 - 1)) }
2861        }
2862        assert(caught1.getMessage === "sizey did not have size 5")
2863
2864        val caught2 = intercept[TestFailedException] {
2865          obj should ((have size (5)) and (have size (2 - 1)))
2866        }
2867        assert(caught2.getMessage === "sizey did not have size 5")
2868
2869        val caught3 = intercept[TestFailedException] {
2870          obj should (have size (5) and have size (2 - 1))
2871        }
2872        assert(caught3.getMessage === "sizey did not have size 5")
2873      }
2874
2875      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
2876
2877        val caught1 = intercept[TestFailedException] {
2878          obj should { have size (55) or (have size (22)) }
2879        }
2880        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2881
2882        val caught2 = intercept[TestFailedException] {
2883          obj should ((have size (55)) or (have size (22)))
2884        }
2885        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2886
2887        val caught3 = intercept[TestFailedException] {
2888          obj should (have size (55) or have size (22))
2889        }
2890        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
2891      }
2892
2893      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
2894
2895        val caught1 = intercept[TestFailedException] {
2896          obj should { not { have size (3) } and not { have size (2) }}
2897        }
2898        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
2899
2900        val caught2 = intercept[TestFailedException] {
2901          obj should ((not have size (3)) and (not have size (2)))
2902        }
2903        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
2904
2905        val caught3 = intercept[TestFailedException] {
2906          obj should (not have size (3) and not have size (2))
2907        }
2908        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
2909      }
2910
2911      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
2912
2913        val caught1 = intercept[TestFailedException] {
2914          obj should { not { have size (2) } or not { have size (2) }}
2915        }
2916        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
2917
2918        val caught2 = intercept[TestFailedException] {
2919          obj should ((not have size (2)) or (not have size (2)))
2920        }
2921        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
2922
2923        val caught3 = intercept[TestFailedException] {
2924          obj should (not have size (2) or not have size (2))
2925        }
2926        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
2927      }
2928    }
2929
2930    describe("on an arbitrary object that has a parameterless Long size method") {
2931
2932      class Sizey(len: Long) {
2933        def size: Long = len  // The only difference between the previous is the structure of this member
2934        override def toString = "sizey"
2935      }
2936      val obj = new Sizey(2)
2937
2938      it("should do nothing if object size matches specified size") {
2939        obj should have size (2)
2940        obj should have size (2L)
2941        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
2942        check((len: Long) => returnsNormally(new Sizey(len) should have size (len)))
2943      }
2944
2945      it("should do nothing if object size does not match and used with should not") {
2946        obj should not { have size (3) }
2947        obj should not { have size (3L) }
2948        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2949        check((len: Long, wrongLen: Long) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
2950      }
2951
2952      it("should do nothing when object size matches and used in a logical-and expression") {
2953        obj should { have size (2) and (have size (3 - 1)) }
2954        obj should ((have size (2)) and (have size (3 - 1)))
2955        obj should (have size (2) and have size (3 - 1))
2956      }
2957
2958      it("should do nothing when object size matches and used in a logical-or expression") {
2959        obj should { have size (77) or (have size (3 - 1)) }
2960        obj should ((have size (77)) or (have size (3 - 1)))
2961        obj should (have size (77) or have size (3 - 1))
2962      }
2963
2964      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
2965        obj should { not { have size (5) } and not { have size (3) }}
2966        obj should ((not have size (5)) and (not have size (3)))
2967        obj should (not have size (5) and not have size (3))
2968      }
2969
2970      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
2971        obj should { not { have size (2) } or not { have size (3) }}
2972        obj should ((not have size (2)) or (not have size (3)))
2973        obj should (not have size (2) or not have size (3))
2974      }
2975
2976      it("should throw TestFailedException if object size does not match specified size") {
2977        val caught1 = intercept[TestFailedException] {
2978          obj should have size (3)
2979        }
2980        assert(caught1.getMessage === "sizey did not have size 3")
2981        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
2982      }
2983
2984      it("should throw TestFailedException with normal error message if specified size is negative") {
2985        val caught1 = intercept[TestFailedException] {
2986          obj should have size (-2)
2987        }
2988        assert(caught1.getMessage === "sizey did not have size -2")
2989        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
2990      }
2991
2992      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
2993
2994        val caught1 = intercept[TestFailedException] {
2995          obj should { have size (5) and (have size (2 - 1)) }
2996        }
2997        assert(caught1.getMessage === "sizey did not have size 5")
2998
2999        val caught2 = intercept[TestFailedException] {
3000          obj should ((have size (5)) and (have size (2 - 1)))
3001        }
3002        assert(caught2.getMessage === "sizey did not have size 5")
3003
3004        val caught3 = intercept[TestFailedException] {
3005          obj should (have size (5) and have size (2 - 1))
3006        }
3007        assert(caught3.getMessage === "sizey did not have size 5")
3008      }
3009
3010      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
3011
3012        val caught1 = intercept[TestFailedException] {
3013          obj should { have size (55) or (have size (22)) }
3014        }
3015        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3016
3017        val caught2 = intercept[TestFailedException] {
3018          obj should ((have size (55)) or (have size (22)))
3019        }
3020        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3021
3022        val caught3 = intercept[TestFailedException] {
3023          obj should (have size (55) or have size (22))
3024        }
3025        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3026      }
3027
3028      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
3029
3030        val caught1 = intercept[TestFailedException] {
3031          obj should { not { have size (3) } and not { have size (2) }}
3032        }
3033        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
3034
3035        val caught2 = intercept[TestFailedException] {
3036          obj should ((not have size (3)) and (not have size (2)))
3037        }
3038        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
3039
3040        val caught3 = intercept[TestFailedException] {
3041          obj should (not have size (3) and not have size (2))
3042        }
3043        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
3044      }
3045
3046      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
3047
3048        val caught1 = intercept[TestFailedException] {
3049          obj should { not { have size (2) } or not { have size (2) }}
3050        }
3051        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
3052
3053        val caught2 = intercept[TestFailedException] {
3054          obj should ((not have size (2)) or (not have size (2)))
3055        }
3056        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
3057
3058        val caught3 = intercept[TestFailedException] {
3059          obj should (not have size (2) or not have size (2))
3060        }
3061        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
3062      }
3063    }
3064
3065    describe("on an arbitrary object that has a Long size field") {
3066
3067      class Sizey(len: Long) {
3068        val size: Long = len // The only difference between the previous is the structure of this member
3069        override def toString = "sizey"
3070      }
3071      val obj = new Sizey(2)
3072
3073      it("should do nothing if object size matches specified size") {
3074        obj should have size (2)
3075        obj should have size (2L)
3076        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
3077        check((len: Long) => returnsNormally(new Sizey(len) should have size (len)))
3078      }
3079
3080      it("should do nothing if object size does not match and used with should not") {
3081        obj should not { have size (3) }
3082        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
3083      }
3084
3085      it("should do nothing when object size matches and used in a logical-and expression") {
3086        obj should { have size (2) and (have size (3 - 1)) }
3087        obj should ((have size (2)) and (have size (3 - 1)))
3088        obj should (have size (2) and have size (3 - 1))
3089      }
3090
3091      it("should do nothing when object size matches and used in a logical-or expression") {
3092        obj should { have size (77) or (have size (3 - 1)) }
3093        obj should ((have size (77)) or (have size (3 - 1)))
3094        obj should (have size (77) or have size (3 - 1))
3095      }
3096
3097      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
3098        obj should { not { have size (5) } and not { have size (3) }}
3099        obj should ((not have size (5)) and (not have size (3)))
3100        obj should (not have size (5) and not have size (3))
3101      }
3102
3103      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
3104        obj should { not { have size (2) } or not { have size (3) }}
3105        obj should ((not have size (2)) or (not have size (3)))
3106        obj should (not have size (2) or not have size (3))
3107      }
3108
3109      it("should throw TestFailedException if object size does not match specified size") {
3110        val caught1 = intercept[TestFailedException] {
3111          obj should have size (3)
3112        }
3113        assert(caught1.getMessage === "sizey did not have size 3")
3114        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
3115      }
3116
3117      it("should throw TestFailedException with normal error message if specified size is negative") {
3118        val caught1 = intercept[TestFailedException] {
3119          obj should have size (-2)
3120        }
3121        assert(caught1.getMessage === "sizey did not have size -2")
3122        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
3123      }
3124
3125      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
3126
3127        val caught1 = intercept[TestFailedException] {
3128          obj should { have size (5) and (have size (2 - 1)) }
3129        }
3130        assert(caught1.getMessage === "sizey did not have size 5")
3131
3132        val caught2 = intercept[TestFailedException] {
3133          obj should ((have size (5)) and (have size (2 - 1)))
3134        }
3135        assert(caught2.getMessage === "sizey did not have size 5")
3136
3137        val caught3 = intercept[TestFailedException] {
3138          obj should (have size (5) and have size (2 - 1))
3139        }
3140        assert(caught3.getMessage === "sizey did not have size 5")
3141      }
3142
3143      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
3144
3145        val caught1 = intercept[TestFailedException] {
3146          obj should { have size (55) or (have size (22)) }
3147        }
3148        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3149
3150        val caught2 = intercept[TestFailedException] {
3151          obj should ((have size (55)) or (have size (22)))
3152        }
3153        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3154
3155        val caught3 = intercept[TestFailedException] {
3156          obj should (have size (55) or have size (22))
3157        }
3158        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3159      }
3160
3161      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
3162
3163        val caught1 = intercept[TestFailedException] {
3164          obj should { not { have size (3) } and not { have size (2) }}
3165        }
3166        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
3167
3168        val caught2 = intercept[TestFailedException] {
3169          obj should ((not have size (3)) and (not have size (2)))
3170        }
3171        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
3172
3173        val caught3 = intercept[TestFailedException] {
3174          obj should (not have size (3) and not have size (2))
3175        }
3176        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
3177      }
3178
3179      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
3180
3181        val caught1 = intercept[TestFailedException] {
3182          obj should { not { have size (2) } or not { have size (2) }}
3183        }
3184        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
3185
3186        val caught2 = intercept[TestFailedException] {
3187          obj should ((not have size (2)) or (not have size (2)))
3188        }
3189        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
3190
3191        val caught3 = intercept[TestFailedException] {
3192          obj should (not have size (2) or not have size (2))
3193        }
3194        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
3195      }
3196    }
3197
3198    describe("on an arbitrary object that has an empty-paren Long getSize method") {
3199
3200      class Sizey(len: Long) {
3201        def getSize(): Long = len  // The only difference between the previous is the structure of this member
3202        override def toString = "sizey"
3203      }
3204      val obj = new Sizey(2)
3205
3206      it("should do nothing if object size matches specified size") {
3207        obj should have size (2)
3208        obj should have size (2L)
3209        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
3210        check((len: Long) => returnsNormally(new Sizey(len) should have size (len)))
3211      }
3212
3213      it("should do nothing if object size does not match and used with should not") {
3214        obj should not { have size (3) }
3215        obj should not { have size (3) }
3216        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
3217        check((len: Long, wrongLen: Long) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
3218      }
3219
3220      it("should do nothing when object size matches and used in a logical-and expression") {
3221        obj should { have size (2) and (have size (3 - 1)) }
3222        obj should ((have size (2)) and (have size (3 - 1)))
3223        obj should (have size (2) and have size (3 - 1))
3224      }
3225
3226      it("should do nothing when object size matches and used in a logical-or expression") {
3227        obj should { have size (77) or (have size (3 - 1)) }
3228        obj should ((have size (77)) or (have size (3 - 1)))
3229        obj should (have size (77) or have size (3 - 1))
3230      }
3231
3232      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
3233        obj should { not { have size (5) } and not { have size (3) }}
3234        obj should ((not have size (5)) and (not have size (3)))
3235        obj should (not have size (5) and not have size (3))
3236      }
3237
3238      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
3239        obj should { not { have size (2) } or not { have size (3) }}
3240        obj should ((not have size (2)) or (not have size (3)))
3241        obj should (not have size (2) or not have size (3))
3242      }
3243
3244      it("should throw TestFailedException if object size does not match specified size") {
3245        val caught1 = intercept[TestFailedException] {
3246          obj should have size (3)
3247        }
3248        assert(caught1.getMessage === "sizey did not have size 3")
3249        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
3250      }
3251
3252      it("should throw TestFailedException with normal error message if specified size is negative") {
3253        val caught1 = intercept[TestFailedException] {
3254          obj should have size (-2)
3255        }
3256        assert(caught1.getMessage === "sizey did not have size -2")
3257        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
3258      }
3259
3260      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
3261
3262        val caught1 = intercept[TestFailedException] {
3263          obj should { have size (5) and (have size (2 - 1)) }
3264        }
3265        assert(caught1.getMessage === "sizey did not have size 5")
3266
3267        val caught2 = intercept[TestFailedException] {
3268          obj should ((have size (5)) and (have size (2 - 1)))
3269        }
3270        assert(caught2.getMessage === "sizey did not have size 5")
3271
3272        val caught3 = intercept[TestFailedException] {
3273          obj should (have size (5) and have size (2 - 1))
3274        }
3275        assert(caught3.getMessage === "sizey did not have size 5")
3276      }
3277
3278      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
3279
3280        val caught1 = intercept[TestFailedException] {
3281          obj should { have size (55) or (have size (22)) }
3282        }
3283        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3284
3285        val caught2 = intercept[TestFailedException] {
3286          obj should ((have size (55)) or (have size (22)))
3287        }
3288        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3289
3290        val caught3 = intercept[TestFailedException] {
3291          obj should (have size (55) or have size (22))
3292        }
3293        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3294      }
3295
3296      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
3297
3298        val caught1 = intercept[TestFailedException] {
3299          obj should { not { have size (3) } and not { have size (2) }}
3300        }
3301        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
3302
3303        val caught2 = intercept[TestFailedException] {
3304          obj should ((not have size (3)) and (not have size (2)))
3305        }
3306        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
3307
3308        val caught3 = intercept[TestFailedException] {
3309          obj should (not have size (3) and not have size (2))
3310        }
3311        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
3312      }
3313
3314      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
3315
3316        val caught1 = intercept[TestFailedException] {
3317          obj should { not { have size (2) } or not { have size (2) }}
3318        }
3319        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
3320
3321        val caught2 = intercept[TestFailedException] {
3322          obj should ((not have size (2)) or (not have size (2)))
3323        }
3324        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
3325
3326        val caught3 = intercept[TestFailedException] {
3327          obj should (not have size (2) or not have size (2))
3328        }
3329        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
3330      }
3331    }
3332
3333    describe("on an arbitrary object that has a parameterless Long getSize method") {
3334
3335      class Sizey(len: Long) {
3336        def getSize: Long = len  // The only difference between the previous is the structure of this member
3337        override def toString = "sizey"
3338      }
3339      val obj = new Sizey(2)
3340
3341      it("should do nothing if object size matches specified size") {
3342        obj should have size (2)
3343        obj should have size (2L)
3344        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
3345        check((len: Long) => returnsNormally(new Sizey(len) should have size (len)))
3346      }
3347
3348      it("should do nothing if object size does not match and used with should not") {
3349        obj should not { have size (3) }
3350        obj should not { have size (3L) }
3351        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
3352        check((len: Long, wrongLen: Long) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
3353      }
3354
3355      it("should do nothing when object size matches and used in a logical-and expression") {
3356        obj should { have size (2) and (have size (3 - 1)) }
3357        obj should ((have size (2)) and (have size (3 - 1)))
3358        obj should (have size (2) and have size (3 - 1))
3359      }
3360
3361      it("should do nothing when object size matches and used in a logical-or expression") {
3362        obj should { have size (77) or (have size (3 - 1)) }
3363        obj should ((have size (77)) or (have size (3 - 1)))
3364        obj should (have size (77) or have size (3 - 1))
3365      }
3366
3367      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
3368        obj should { not { have size (5) } and not { have size (3) }}
3369        obj should ((not have size (5)) and (not have size (3)))
3370        obj should (not have size (5) and not have size (3))
3371      }
3372
3373      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
3374        obj should { not { have size (2) } or not { have size (3) }}
3375        obj should ((not have size (2)) or (not have size (3)))
3376        obj should (not have size (2) or not have size (3))
3377      }
3378
3379      it("should throw TestFailedException if object size does not match specified size") {
3380        val caught1 = intercept[TestFailedException] {
3381          obj should have size (3)
3382        }
3383        assert(caught1.getMessage === "sizey did not have size 3")
3384        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
3385      }
3386
3387      it("should throw TestFailedException with normal error message if specified size is negative") {
3388        val caught1 = intercept[TestFailedException] {
3389          obj should have size (-2)
3390        }
3391        assert(caught1.getMessage === "sizey did not have size -2")
3392        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
3393      }
3394
3395      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
3396
3397        val caught1 = intercept[TestFailedException] {
3398          obj should { have size (5) and (have size (2 - 1)) }
3399        }
3400        assert(caught1.getMessage === "sizey did not have size 5")
3401
3402        val caught2 = intercept[TestFailedException] {
3403          obj should ((have size (5)) and (have size (2 - 1)))
3404        }
3405        assert(caught2.getMessage === "sizey did not have size 5")
3406
3407        val caught3 = intercept[TestFailedException] {
3408          obj should (have size (5) and have size (2 - 1))
3409        }
3410        assert(caught3.getMessage === "sizey did not have size 5")
3411      }
3412
3413      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
3414
3415        val caught1 = intercept[TestFailedException] {
3416          obj should { have size (55) or (have size (22)) }
3417        }
3418        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3419
3420        val caught2 = intercept[TestFailedException] {
3421          obj should ((have size (55)) or (have size (22)))
3422        }
3423        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3424
3425        val caught3 = intercept[TestFailedException] {
3426          obj should (have size (55) or have size (22))
3427        }
3428        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3429      }
3430
3431      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
3432
3433        val caught1 = intercept[TestFailedException] {
3434          obj should { not { have size (3) } and not { have size (2) }}
3435        }
3436        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
3437
3438        val caught2 = intercept[TestFailedException] {
3439          obj should ((not have size (3)) and (not have size (2)))
3440        }
3441        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
3442
3443        val caught3 = intercept[TestFailedException] {
3444          obj should (not have size (3) and not have size (2))
3445        }
3446        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
3447      }
3448
3449      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
3450
3451        val caught1 = intercept[TestFailedException] {
3452          obj should { not { have size (2) } or not { have size (2) }}
3453        }
3454        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
3455
3456        val caught2 = intercept[TestFailedException] {
3457          obj should ((not have size (2)) or (not have size (2)))
3458        }
3459        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
3460
3461        val caught3 = intercept[TestFailedException] {
3462          obj should (not have size (2) or not have size (2))
3463        }
3464        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
3465      }
3466    }
3467
3468    describe("on an arbitrary object that has a Long getSize field") {
3469
3470      class Sizey(len: Long) {
3471        val getSize: Long = len // The only difference between the previous is the structure of this member
3472        override def toString = "sizey"
3473      }
3474      val obj = new Sizey(2)
3475
3476      it("should do nothing if object size matches specified size") {
3477        obj should have size (2)
3478        obj should have size (2L)
3479        check((len: Int) => returnsNormally(new Sizey(len) should have size (len)))
3480        check((len: Long) => returnsNormally(new Sizey(len) should have size (len)))
3481      }
3482
3483      it("should do nothing if object size does not match and used with should not") {
3484        obj should not { have size (3) }
3485        obj should not have size (3L)
3486        check((len: Int, wrongLen: Int) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
3487        check((len: Long, wrongLen: Long) => len != wrongLen ==> returnsNormally(new Sizey(len) should not { have size (wrongLen) }))
3488      }
3489
3490      it("should do nothing when object size matches and used in a logical-and expression") {
3491        obj should { have size (2) and (have size (3 - 1)) }
3492        obj should ((have size (2)) and (have size (3 - 1)))
3493        obj should (have size (2) and have size (3 - 1))
3494      }
3495
3496      it("should do nothing when object size matches and used in a logical-or expression") {
3497        obj should { have size (77) or (have size (3 - 1)) }
3498        obj should ((have size (77)) or (have size (3 - 1)))
3499        obj should (have size (77) or have size (3 - 1))
3500      }
3501
3502      it("should do nothing when object size doesn't match and used in a logical-and expression with not") {
3503        obj should { not { have size (5) } and not { have size (3) }}
3504        obj should ((not have size (5)) and (not have size (3)))
3505        obj should (not have size (5) and not have size (3))
3506      }
3507
3508      it("should do nothing when object size doesn't match and used in a logical-or expression with not") {
3509        obj should { not { have size (2) } or not { have size (3) }}
3510        obj should ((not have size (2)) or (not have size (3)))
3511        obj should (not have size (2) or not have size (3))
3512      }
3513
3514      it("should throw TestFailedException if object size does not match specified size") {
3515        val caught1 = intercept[TestFailedException] {
3516          obj should have size (3)
3517        }
3518        assert(caught1.getMessage === "sizey did not have size 3")
3519        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (len + 1)))
3520      }
3521
3522      it("should throw TestFailedException with normal error message if specified size is negative") {
3523        val caught1 = intercept[TestFailedException] {
3524          obj should have size (-2)
3525        }
3526        assert(caught1.getMessage === "sizey did not have size -2")
3527        check((len: Int) => throwsTestFailedException(new Sizey(len) should have size (if ((len == 0) || (len == MIN_VALUE)) -1 else -len)))
3528      }
3529
3530      it("should throw an assertion error when object size doesn't match and used in a logical-and expression") {
3531
3532        val caught1 = intercept[TestFailedException] {
3533          obj should { have size (5) and (have size (2 - 1)) }
3534        }
3535        assert(caught1.getMessage === "sizey did not have size 5")
3536
3537        val caught2 = intercept[TestFailedException] {
3538          obj should ((have size (5)) and (have size (2 - 1)))
3539        }
3540        assert(caught2.getMessage === "sizey did not have size 5")
3541
3542        val caught3 = intercept[TestFailedException] {
3543          obj should (have size (5) and have size (2 - 1))
3544        }
3545        assert(caught3.getMessage === "sizey did not have size 5")
3546      }
3547
3548      it("should throw an assertion error when object size doesn't match and used in a logical-or expression") {
3549
3550        val caught1 = intercept[TestFailedException] {
3551          obj should { have size (55) or (have size (22)) }
3552        }
3553        assert(caught1.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3554
3555        val caught2 = intercept[TestFailedException] {
3556          obj should ((have size (55)) or (have size (22)))
3557        }
3558        assert(caught2.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3559
3560        val caught3 = intercept[TestFailedException] {
3561          obj should (have size (55) or have size (22))
3562        }
3563        assert(caught3.getMessage === "sizey did not have size 55, and sizey did not have size 22")
3564      }
3565
3566      it("should throw an assertion error when object size matches and used in a logical-and expression with not") {
3567
3568        val caught1 = intercept[TestFailedException] {
3569          obj should { not { have size (3) } and not { have size (2) }}
3570        }
3571        assert(caught1.getMessage === "sizey did not have size 3, but sizey had size 2")
3572
3573        val caught2 = intercept[TestFailedException] {
3574          obj should ((not have size (3)) and (not have size (2)))
3575        }
3576        assert(caught2.getMessage === "sizey did not have size 3, but sizey had size 2")
3577
3578        val caught3 = intercept[TestFailedException] {
3579          obj should (not have size (3) and not have size (2))
3580        }
3581        assert(caught3.getMessage === "sizey did not have size 3, but sizey had size 2")
3582      }
3583
3584      it("should throw an assertion error when object size matches and used in a logical-or expression with not") {
3585
3586        val caught1 = intercept[TestFailedException] {
3587          obj should { not { have size (2) } or not { have size (2) }}
3588        }
3589        assert(caught1.getMessage === "sizey had size 2, and sizey had size 2")
3590
3591        val caught2 = intercept[TestFailedException] {
3592          obj should ((not have size (2)) or (not have size (2)))
3593        }
3594        assert(caught2.getMessage === "sizey had size 2, and sizey had size 2")
3595
3596        val caught3 = intercept[TestFailedException] {
3597          obj should (not have size (2) or not have size (2))
3598        }
3599        assert(caught3.getMessage === "sizey had size 2, and sizey had size 2")
3600      }
3601    }
3602
3603    it("should give an TestFailedException with an arbitrary object that has no size member in an and expression") {
3604      class HasNoSize {
3605        val sizeiness: Int = 2
3606      }
3607      val hasNoSize = new HasNoSize
3608      val caught1 = intercept[TestFailedException] {
3609        hasNoSize should { have size (2) and equal (hasNoSize) }
3610      }
3611      val expectedMessage = "have size (2) used with an object that had no public field or method named size or getSize"
3612      assert(caught1.getMessage === expectedMessage)
3613      val caught2 = intercept[TestFailedException] {
3614        hasNoSize should not { have size (2) and equal (hasNoSize) }
3615      }
3616      assert(caught2.getMessage === expectedMessage)
3617    }
3618
3619    it("should the Scala-style method on an arbitrary object that has multiple members with a valid sizes structure") {
3620      class Sizey(len: Int) {
3621        def getSize: Int = len + 1
3622        def size: Int = len
3623        override def toString = "sizey"
3624      }
3625      val obj = new Sizey(2)
3626      val sizeMatcher = have size (2)
3627      sizeMatcher.apply(obj)
3628
3629      class IntAndLong(intLen: Int, longLen: Long) {
3630        def getSize: Int = intLen
3631        def size: Long = longLen
3632        override def toString = "sizey"
3633      }
3634      val obj2 = new IntAndLong(3, 2)
3635      val sizeMatcher2 = have size (2)
3636      sizeMatcher2.apply(obj)
3637    }
3638  }
3639}
3640