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.5 by jsr166, Sun Oct 11 00:58:42 2015 UTC vs.
Revision 1.8 by jsr166, Mon Jan 8 03:12:03 2018 UTC

# Line 26 | Line 26
26     @summary Test for an illegalargumentexception on loadFactor
27   */
28  
29 < 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 34 | 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 <     }
133 <
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