ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Hashtable/IllegalLoadFactor.java
(Generate patch)

Comparing jsr166/src/test/jtreg/util/Hashtable/IllegalLoadFactor.java (file contents):
Revision 1.1 by jsr166, Tue Sep 1 01:25:04 2009 UTC vs.
Revision 1.8 by jsr166, Mon Jan 8 03:12:03 2018 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright 1997-1998 Sun Microsystems, Inc.  All Rights Reserved.
2 > * Copyright (c) 1997, 1998, Oracle and/or its affiliates. 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
# Line 16 | Line 16
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.
19 > * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 > * or visit www.oracle.com if you need additional information or have any
21 > * questions.
22   */
23  
24   /* @test
# Line 26 | Line 26
26     @summary Test for an illegalargumentexception on loadFactor
27   */
28  
29 <
30 <
31 < import java.util.*;
29 > import java.util.HashMap;
30 > import java.util.HashSet;
31 > import java.util.Hashtable;
32 > import java.util.Map;
33 > import java.util.Set;
34 > import java.util.WeakHashMap;
35  
36   /**
37   * This class tests to see if creating a hash table with an
# Line 36 | Line 39 | import java.util.*;
39   */
40   public class IllegalLoadFactor {
41  
42 <      public static void main(String argv[]) throws Exception {
43 <          boolean testSucceeded = false;
44 <          try{
45 <              // this should generate an IllegalArgumentException
46 <              Hashtable bad1 = new Hashtable(100, -3);
47 <          }
48 <          catch (IllegalArgumentException e1) {
49 <              testSucceeded = true;
50 <          }
51 <          if(!testSucceeded)
52 <              throw new Exception("Hashtable, negative load factor");
53 <
54 <          testSucceeded = false;
55 <          try{
56 <              // this should generate an IllegalArgumentException
57 <              Hashtable bad1 = new Hashtable(100, Float.NaN);
58 <          }
59 <          catch (IllegalArgumentException e1) {
60 <              testSucceeded = true;
61 <          }
62 <          if(!testSucceeded)
63 <              throw new Exception("Hashtable, NaN load factor");
64 <
65 <          testSucceeded = false;
66 <          try{
67 <              // this should generate an IllegalArgumentException
68 <              HashMap bad1 = new HashMap(100, -3);
69 <          }
70 <          catch (IllegalArgumentException e1) {
71 <              testSucceeded = true;
72 <          }
73 <          if(!testSucceeded)
74 <              throw new Exception("HashMap, negative load factor");
75 <
76 <          testSucceeded = false;
77 <          try{
78 <              // this should generate an IllegalArgumentException
79 <              HashMap bad1 = new HashMap(100, Float.NaN);
80 <          }
81 <          catch (IllegalArgumentException e1) {
82 <              testSucceeded = true;
83 <          }
84 <          if(!testSucceeded)
85 <              throw new Exception("HashMap, NaN load factor");
86 <
87 <
88 <          testSucceeded = false;
89 <          try{
90 <              // this should generate an IllegalArgumentException
91 <              HashSet bad1 = new HashSet(100, -3);
92 <          }
93 <          catch (IllegalArgumentException e1) {
94 <              testSucceeded = true;
95 <          }
96 <          if(!testSucceeded)
97 <              throw new Exception("HashSet, negative load factor");
98 <
99 <          testSucceeded = false;
100 <          try{
101 <              // this should generate an IllegalArgumentException
102 <              HashSet bad1 = new HashSet(100, Float.NaN);
103 <          }
104 <          catch (IllegalArgumentException e1) {
105 <              testSucceeded = true;
106 <          }
107 <          if(!testSucceeded)
108 <              throw new Exception("HashSet, NaN load factor");
109 <
110 <          testSucceeded = false;
111 <          try{
112 <              // this should generate an IllegalArgumentException
113 <              WeakHashMap bad1 = new WeakHashMap(100, -3);
114 <          }
115 <          catch (IllegalArgumentException e1) {
116 <              testSucceeded = true;
117 <          }
118 <          if(!testSucceeded)
119 <              throw new Exception("WeakHashMap, negative load factor");
120 <
121 <          testSucceeded = false;
122 <          try{
123 <              // this should generate an IllegalArgumentException
124 <              WeakHashMap bad1 = new WeakHashMap(100, Float.NaN);
125 <          }
126 <          catch (IllegalArgumentException e1) {
127 <              testSucceeded = true;
128 <          }
129 <          if(!testSucceeded)
130 <              throw new Exception("WeakHashMap, NaN load factor");
131 <
132 <          // Make sure that legal creates don't throw exceptions
133 <          Map goodMap = new Hashtable(100, .69f);
134 <          goodMap = new HashMap(100, .69f);
135 <          Set goodSet = new HashSet(100, .69f);
136 <          goodMap = new WeakHashMap(100, .69f);
137 <     }
135 <
42 >    public static void main(String[] args) throws Exception {
43 >        boolean testSucceeded = false;
44 >        try {
45 >            // this should generate an IllegalArgumentException
46 >            Hashtable bad1 = new Hashtable(100, -3);
47 >        }
48 >        catch (IllegalArgumentException e1) {
49 >            testSucceeded = true;
50 >        }
51 >        if (!testSucceeded)
52 >            throw new Exception("Hashtable, negative load factor");
53 >
54 >        testSucceeded = false;
55 >        try {
56 >            // this should generate an IllegalArgumentException
57 >            Hashtable bad1 = new Hashtable(100, Float.NaN);
58 >        }
59 >        catch (IllegalArgumentException e1) {
60 >            testSucceeded = true;
61 >        }
62 >        if (!testSucceeded)
63 >            throw new Exception("Hashtable, NaN load factor");
64 >
65 >        testSucceeded = false;
66 >        try {
67 >            // this should generate an IllegalArgumentException
68 >            HashMap bad1 = new HashMap(100, -3);
69 >        }
70 >        catch (IllegalArgumentException e1) {
71 >            testSucceeded = true;
72 >        }
73 >        if (!testSucceeded)
74 >            throw new Exception("HashMap, negative load factor");
75 >
76 >        testSucceeded = false;
77 >        try {
78 >            // this should generate an IllegalArgumentException
79 >            HashMap bad1 = new HashMap(100, Float.NaN);
80 >        }
81 >        catch (IllegalArgumentException e1) {
82 >            testSucceeded = true;
83 >        }
84 >        if (!testSucceeded)
85 >            throw new Exception("HashMap, NaN load factor");
86 >
87 >
88 >        testSucceeded = false;
89 >        try {
90 >            // this should generate an IllegalArgumentException
91 >            HashSet bad1 = new HashSet(100, -3);
92 >        }
93 >        catch (IllegalArgumentException e1) {
94 >            testSucceeded = true;
95 >        }
96 >        if (!testSucceeded)
97 >            throw new Exception("HashSet, negative load factor");
98 >
99 >        testSucceeded = false;
100 >        try {
101 >            // this should generate an IllegalArgumentException
102 >            HashSet bad1 = new HashSet(100, Float.NaN);
103 >        }
104 >        catch (IllegalArgumentException e1) {
105 >            testSucceeded = true;
106 >        }
107 >        if (!testSucceeded)
108 >            throw new Exception("HashSet, NaN load factor");
109 >
110 >        testSucceeded = false;
111 >        try {
112 >            // this should generate an IllegalArgumentException
113 >            WeakHashMap bad1 = new WeakHashMap(100, -3);
114 >        }
115 >        catch (IllegalArgumentException e1) {
116 >            testSucceeded = true;
117 >        }
118 >        if (!testSucceeded)
119 >            throw new Exception("WeakHashMap, negative load factor");
120 >
121 >        testSucceeded = false;
122 >        try {
123 >            // this should generate an IllegalArgumentException
124 >            WeakHashMap bad1 = new WeakHashMap(100, Float.NaN);
125 >        }
126 >        catch (IllegalArgumentException e1) {
127 >            testSucceeded = true;
128 >        }
129 >        if (!testSucceeded)
130 >            throw new Exception("WeakHashMap, NaN load factor");
131 >
132 >        // Make sure that legal creates don't throw exceptions
133 >        Map goodMap = new Hashtable(100, .69f);
134 >        goodMap = new HashMap(100, .69f);
135 >        Set goodSet = new HashSet(100, .69f);
136 >        goodMap = new WeakHashMap(100, .69f);
137 >    }
138   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines