1 /* Copyright (c) 2006 Mark J. Wielaard (mark@klomp.org) |
|
2 |
|
3 This file is part of Mauve. |
|
4 |
|
5 Mauve is free software; you can redistribute it and/or modify |
|
6 it under the terms of the GNU General Public License as published by |
|
7 the Free Software Foundation; either version 2, or (at your option) |
|
8 any later version. |
|
9 |
|
10 Mauve is distributed in the hope that it will be useful, |
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 GNU General Public License for more details. |
|
14 |
|
15 You should have received a copy of the GNU General Public License |
|
16 along with Mauve; see the file COPYING. If not, write to |
|
17 the Free Software Foundation, 59 Temple Place - Suite 330, |
|
18 Boston, MA 02111-1307, USA. |
|
19 */ |
|
20 |
|
21 // Tags: JDK1.2 |
|
22 |
|
23 package gnu.testlet.java.util.AbstractCollection; |
|
24 |
|
25 import gnu.testlet.Testlet; |
|
26 import gnu.testlet.TestHarness; |
|
27 |
|
28 import java.util.*; |
|
29 |
|
30 /** |
|
31 * Checks that toString() can handle collections that contain themselves. |
|
32 */ |
|
33 public class toString implements Testlet, Comparator |
|
34 { |
|
35 public void test (TestHarness harness) |
|
36 { |
|
37 testCollection(new LinkedList(), harness); |
|
38 testCollection(new ArrayList(), harness); |
|
39 testCollection(new Vector(), harness); |
|
40 testCollection(new Stack(), harness); |
|
41 testCollection(new HashSet(), harness); |
|
42 testCollection(new LinkedHashSet(), harness); |
|
43 testCollection(new TreeSet(this), harness); |
|
44 } |
|
45 |
|
46 private void testCollection(Collection c, TestHarness h) |
|
47 { |
|
48 h.checkPoint(c.getClass().getName()); |
|
49 c.add(new Integer(123)); |
|
50 c.add(c); |
|
51 c.add("abc"); |
|
52 String s = c.toString(); |
|
53 h.debug(s); |
|
54 h.check(s.indexOf("123") != -1); |
|
55 h.check(s.indexOf("abc") != -1); |
|
56 } |
|
57 |
|
58 public int compare(Object o1, Object o2) |
|
59 { |
|
60 return String.valueOf(o1).compareTo(String.valueOf(o2)); |
|
61 } |
|
62 |
|
63 public boolean equals(Object o) |
|
64 { |
|
65 return o == this; |
|
66 } |
|
67 } |
|