ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/AbstractMap/Equals.java
Revision: 1.1
Committed: Tue Sep 1 01:23:06 2009 UTC (14 years, 9 months ago) by jsr166
Branch: MAIN
Log Message:
import tests from openjdk

File Contents

# User Rev Content
1 jsr166 1.1 /*
2     * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
3     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4     *
5     * This code is free software; you can redistribute it and/or modify it
6     * under the terms of the GNU General Public License version 2 only, as
7     * published by the Free Software Foundation.
8     *
9     * This code is distributed in the hope that it will be useful, but WITHOUT
10     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12     * version 2 for more details (a copy is included in the LICENSE file that
13     * accompanied this code).
14     *
15     * You should have received a copy of the GNU General Public License version
16     * 2 along with this work; if not, write to the Free Software Foundation,
17     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18     *
19     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20     * CA 95054 USA or visit www.sun.com if you need additional information or
21     * have any questions.
22     */
23    
24     import java.util.*;
25    
26     /**
27     * @test
28     * @bug 4503672
29     * @summary AbstractMap.equals and AbstractSet.equals are fragile: they
30     * throw exceptions when they should return false.
31     * @author Josh Bloch
32     */
33     public class Equals {
34     public static void main(String[] args) {
35     Map m = new HashMap();
36     m.put(null, "");
37     Map h = new Hashtable();
38     h.put("", "");
39     if (m.equals(h))
40     throw new RuntimeException("1");
41    
42     Map m1 = new TreeMap();
43     m1.put(new Integer(42), "The Answer");
44     Map m2 = new TreeMap();
45     m2.put("The Answer", new Integer(42));
46     if (m1.equals(m2))
47     throw new RuntimeException("3");
48    
49     Set s1 = new TreeSet();
50     s1.add(new Integer(666));
51     Set s2 = new TreeSet();
52     s2.add("Great googly moogly!");
53     if (s1.equals(s2))
54     throw new RuntimeException("2");
55     }
56     }