1 |
|
/* |
2 |
< |
* Written by members of JCP JSR-166 Expert Group and released to the |
3 |
< |
* public domain. Use, modify, and redistribute this code in any way |
4 |
< |
* without acknowledgement. Other contributors include Andrew Wright, |
5 |
< |
* Jeffrey Hayes, Pat Fischer, Mike Judd. |
2 |
> |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
> |
* Expert Group and released to the public domain, as explained at |
4 |
> |
* http://creativecommons.org/licenses/publicdomain |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
|
21 |
|
} |
22 |
|
|
23 |
|
/** |
24 |
< |
* |
24 |
> |
* convert correctly converts sample values across the four units |
25 |
|
*/ |
26 |
|
public void testConvert() { |
27 |
|
for (long t = 0; t < 10; ++t) { |
77 |
|
} |
78 |
|
|
79 |
|
/** |
80 |
< |
* |
80 |
> |
* toNanos correctly converts sample values in different units to |
81 |
> |
* nanoseconds |
82 |
|
*/ |
83 |
|
public void testToNanos() { |
84 |
|
for (long t = 0; t < 10; ++t) { |
95 |
|
} |
96 |
|
|
97 |
|
/** |
98 |
< |
* |
98 |
> |
* toMicros correctly converts sample values in different units to |
99 |
> |
* microseconds |
100 |
|
*/ |
101 |
|
public void testToMicros() { |
102 |
|
for (long t = 0; t < 10; ++t) { |
113 |
|
} |
114 |
|
|
115 |
|
/** |
116 |
< |
* |
116 |
> |
* toMillis correctly converts sample values in different units to |
117 |
> |
* milliseconds |
118 |
|
*/ |
119 |
|
public void testToMillis() { |
120 |
|
for (long t = 0; t < 10; ++t) { |
131 |
|
} |
132 |
|
|
133 |
|
/** |
134 |
< |
* |
134 |
> |
* toSeconds correctly converts sample values in different units to |
135 |
> |
* seconds |
136 |
|
*/ |
137 |
|
public void testToSeconds() { |
138 |
|
for (long t = 0; t < 10; ++t) { |
150 |
|
|
151 |
|
|
152 |
|
/** |
153 |
< |
* |
153 |
> |
* convert saturates positive too-large values to Long.MAX_VALUE |
154 |
> |
* and negative to LONG.MIN_VALUE |
155 |
|
*/ |
156 |
|
public void testConvertSaturate() { |
157 |
|
assertEquals(Long.MAX_VALUE, |
160 |
|
assertEquals(Long.MIN_VALUE, |
161 |
|
TimeUnit.NANOSECONDS.convert(-Long.MAX_VALUE / 4, |
162 |
|
TimeUnit.SECONDS)); |
157 |
– |
|
163 |
|
} |
164 |
|
|
165 |
|
/** |
166 |
< |
* |
166 |
> |
* toNanos saturates positive too-large values to Long.MAX_VALUE |
167 |
> |
* and negative to LONG.MIN_VALUE |
168 |
|
*/ |
169 |
|
public void testToNanosSaturate() { |
170 |
|
assertEquals(Long.MAX_VALUE, |
171 |
|
TimeUnit.MILLISECONDS.toNanos(Long.MAX_VALUE / 2)); |
172 |
|
assertEquals(Long.MIN_VALUE, |
173 |
|
TimeUnit.MILLISECONDS.toNanos(-Long.MAX_VALUE / 3)); |
168 |
– |
|
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
/** |
178 |
< |
* |
178 |
> |
* toString returns string containing commn name of unit |
179 |
|
*/ |
180 |
|
public void testToString() { |
181 |
|
String s = TimeUnit.SECONDS.toString(); |
187 |
|
* Timed wait without holding lock throws |
188 |
|
* IllegalMonitorStateException |
189 |
|
*/ |
185 |
– |
/** |
186 |
– |
* |
187 |
– |
*/ |
190 |
|
public void testTimedWait_IllegalMonitorException() { |
191 |
|
//created a new thread with anonymous runnable |
192 |
|
|
217 |
|
} |
218 |
|
|
219 |
|
/** |
220 |
< |
* timedWait will throw InterruptedException. |
219 |
< |
* Thread t waits on timedWait while the main thread interrupts it. |
220 |
< |
* Note: This does not throw IllegalMonitorException since timeWait |
221 |
< |
* is synchronized on o |
222 |
< |
*/ |
223 |
< |
/** |
224 |
< |
* |
220 |
> |
* timedWait throws InterruptedException when interrupted |
221 |
|
*/ |
222 |
|
public void testTimedWait() { |
223 |
|
Thread t = new Thread(new Runnable() { |
249 |
|
|
250 |
|
|
251 |
|
/** |
252 |
< |
* timedJoin will throw InterruptedException. |
257 |
< |
* Thread t waits on timedJoin while the main thread interrupts it. |
258 |
< |
*/ |
259 |
< |
/** |
260 |
< |
* |
252 |
> |
* timedJoin throws InterruptedException when interrupted |
253 |
|
*/ |
254 |
|
public void testTimedJoin() { |
255 |
|
Thread t = new Thread(new Runnable() { |
281 |
|
} |
282 |
|
|
283 |
|
/** |
284 |
< |
* timedSleep will throw InterruptedException. |
293 |
< |
* Thread t waits on timedSleep while the main thread interrupts it. |
294 |
< |
*/ |
295 |
< |
/** |
296 |
< |
* |
284 |
> |
* timedSleep throws InterruptedException when interrupted |
285 |
|
*/ |
286 |
|
public void testTimedSleep() { |
287 |
|
//created a new thread with anonymous runnable |
307 |
|
} |
308 |
|
|
309 |
|
/** |
310 |
< |
* |
310 |
> |
* a deserialized serialized unit is equal |
311 |
|
*/ |
312 |
|
public void testSerialization() { |
313 |
|
TimeUnit q = TimeUnit.MILLISECONDS; |