Skip to content

Commit 86af188

Browse files
committed
Replace assertTrue(x == null) with assertNull(x)
1 parent 7517634 commit 86af188

File tree

6 files changed

+47
-46
lines changed

6 files changed

+47
-46
lines changed

test/jdk/java/lang/Thread/BuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ private void testNoInheritedThreadLocals(Thread.Builder builder) throws Exceptio
645645

646646
AtomicBoolean done = new AtomicBoolean();
647647
Runnable task = () -> {
648-
assertTrue(INHERITED_LOCAL.get() == null);
648+
assertNull(INHERITED_LOCAL.get());
649649
done.set(true);
650650
};
651651

test/jdk/java/lang/Thread/virtual/ThreadAPI.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ void testInterrupt5() throws Exception {
877877
Thread.sleep(100); // give time for thread to block
878878
thread.interrupt();
879879
thread.join();
880-
assertTrue(exception.get() == null);
880+
assertNull(exception.get());
881881
}
882882

883883
/**
@@ -902,7 +902,7 @@ void testInterrupt6() throws Exception {
902902
awaitParked(thread);
903903
thread.interrupt();
904904
thread.join();
905-
assertTrue(exception.get() == null);
905+
assertNull(exception.get());
906906
}
907907

908908
/**
@@ -922,7 +922,7 @@ void testInterrupt7() throws Exception {
922922
awaitParked(thread);
923923
thread.interrupt();
924924
thread.join();
925-
assertTrue(exception.get() == null);
925+
assertNull(exception.get());
926926
}
927927

928928
/**
@@ -1577,7 +1577,7 @@ class FooException extends RuntimeException { }
15771577
});
15781578
thread.join();
15791579
assertTrue(exception.get() instanceof FooException);
1580-
assertTrue(thread.getUncaughtExceptionHandler() == null);
1580+
assertNull(thread.getUncaughtExceptionHandler());
15811581
}
15821582

15831583
/**
@@ -1601,7 +1601,7 @@ class FooException extends RuntimeException { }
16011601
Thread.setDefaultUncaughtExceptionHandler(savedHandler);
16021602
}
16031603
assertTrue(exception.get() instanceof FooException);
1604-
assertTrue(thread.getUncaughtExceptionHandler() == null);
1604+
assertNull(thread.getUncaughtExceptionHandler());
16051605
}
16061606

16071607
/**
@@ -1614,7 +1614,7 @@ class FooException extends RuntimeException { }
16141614
throw new FooException();
16151615
});
16161616
thread.join();
1617-
assertTrue(thread.getUncaughtExceptionHandler() == null);
1617+
assertNull(thread.getUncaughtExceptionHandler());
16181618
}
16191619

16201620
/**
@@ -2028,12 +2028,12 @@ void testGetAllStackTraces2() throws Exception {
20282028

20292029
// get stack trace for the carrier thread
20302030
StackTraceElement[] stackTrace = map.get(carrier);
2031-
assertTrue(stackTrace != null);
2031+
assertNotNull(stackTrace);
20322032
assertTrue(contains(stackTrace, "java.util.concurrent.ForkJoinPool"));
20332033
assertFalse(contains(stackTrace, "java.lang.Object.wait"));
20342034

20352035
// there should be no stack trace for the virtual thread
2036-
assertTrue(map.get(vthread) == null);
2036+
assertNull(map.get(vthread));
20372037
}
20382038
}
20392039

@@ -2057,7 +2057,7 @@ void testThreadGroup1() throws Exception {
20572057
LockSupport.unpark(thread);
20582058
thread.join();
20592059
}
2060-
assertTrue(thread.getThreadGroup() == null);
2060+
assertNull(thread.getThreadGroup());
20612061
}
20622062

20632063
/**

test/jdk/java/lang/Thread/virtual/ThreadLocals.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ThreadLocals {
4444
void testThreadLocal1() throws Exception {
4545
for (int i = 0; i < 10; i++) {
4646
VThreadRunner.run(() -> {
47-
assertTrue(LOCAL.get() == null);
47+
assertNull(LOCAL.get());
4848
Object obj = new Object();
4949
LOCAL.set(obj);
5050
assertTrue(LOCAL.get() == obj);
@@ -58,7 +58,7 @@ void testThreadLocal1() throws Exception {
5858
@Test
5959
void testThreadLocal2() throws Exception {
6060
VThreadRunner.run(() -> {
61-
assertTrue(LOCAL.get() == null);
61+
assertNull(LOCAL.get());
6262
Object obj = new Object();
6363
LOCAL.set(obj);
6464
try { Thread.sleep(100); } catch (InterruptedException e) { }
@@ -88,7 +88,7 @@ protected Object initialValue() {
8888
VThreadRunner.run(VThreadRunner.NO_THREAD_LOCALS, () -> {
8989
assertThrows(UnsupportedOperationException.class, () -> LOCAL.set(null));
9090
assertThrows(UnsupportedOperationException.class, () -> LOCAL.set(new Object()));
91-
assertTrue(LOCAL.get() == null);
91+
assertNull(LOCAL.get());
9292
LOCAL.remove(); // should not throw
9393

9494
assertThrows(UnsupportedOperationException.class, () -> LOCAL2.set(null));
@@ -98,7 +98,7 @@ protected Object initialValue() {
9898

9999
assertThrows(UnsupportedOperationException.class, () -> INHERITED_LOCAL.set(null));
100100
assertThrows(UnsupportedOperationException.class, () -> INHERITED_LOCAL.set(new Object()));
101-
assertTrue(INHERITED_LOCAL.get() == null);
101+
assertNull(INHERITED_LOCAL.get());
102102
INHERITED_LOCAL.remove(); // should not throw
103103

104104
assertThrows(UnsupportedOperationException.class, () -> INHERITED_LOCAL2.set(null));
@@ -113,24 +113,24 @@ protected Object initialValue() {
113113
*/
114114
@Test
115115
void testInheritedThreadLocal1() throws Exception {
116-
assertTrue(INHERITED_LOCAL.get() == null);
116+
assertNull(INHERITED_LOCAL.get());
117117
for (int i = 0; i < 10; i++) {
118118
VThreadRunner.run(() -> {
119-
assertTrue(INHERITED_LOCAL.get() == null);
119+
assertNull(INHERITED_LOCAL.get());
120120
Object obj = new Object();
121121
INHERITED_LOCAL.set(obj);
122122
assertTrue(INHERITED_LOCAL.get() == obj);
123123
});
124124
}
125-
assertTrue(INHERITED_LOCAL.get() == null);
125+
assertNull(INHERITED_LOCAL.get());
126126
}
127127

128128
/**
129129
* Test inheriting initial value of InheritableThreadLocal from platform thread.
130130
*/
131131
@Test
132132
void testInheritedThreadLocal2() throws Exception {
133-
assertTrue(INHERITED_LOCAL.get() == null);
133+
assertNull(INHERITED_LOCAL.get());
134134
var obj = new Object();
135135
INHERITED_LOCAL.set(obj);
136136
try {
@@ -147,7 +147,7 @@ void testInheritedThreadLocal2() throws Exception {
147147
*/
148148
@Test
149149
void testInheritedThreadLocal3() throws Exception {
150-
assertTrue(INHERITED_LOCAL.get() == null);
150+
assertNull(INHERITED_LOCAL.get());
151151
VThreadRunner.run(() -> {
152152
var obj = new Object();
153153
INHERITED_LOCAL.set(obj);
@@ -157,7 +157,7 @@ void testInheritedThreadLocal3() throws Exception {
157157
assertTrue(INHERITED_LOCAL.get() == obj);
158158

159159
});
160-
assertTrue(INHERITED_LOCAL.get() == null);
160+
assertNull(INHERITED_LOCAL.get());
161161
}
162162

163163
/**
@@ -166,13 +166,13 @@ void testInheritedThreadLocal3() throws Exception {
166166
*/
167167
@Test
168168
void testInheritedThreadLocal4() throws Exception {
169-
assertTrue(INHERITED_LOCAL.get() == null);
169+
assertNull(INHERITED_LOCAL.get());
170170
var obj = new Object();
171171
INHERITED_LOCAL.set(obj);
172172
try {
173173
int characteristics = VThreadRunner.NO_INHERIT_THREAD_LOCALS;
174174
VThreadRunner.run(characteristics, () -> {
175-
assertTrue(INHERITED_LOCAL.get() == null);
175+
assertNull(INHERITED_LOCAL.get());
176176
});
177177
} finally {
178178
INHERITED_LOCAL.remove();
@@ -185,17 +185,17 @@ void testInheritedThreadLocal4() throws Exception {
185185
*/
186186
@Test
187187
void testInheritedThreadLocal5() throws Exception {
188-
assertTrue(INHERITED_LOCAL.get() == null);
188+
assertNull(INHERITED_LOCAL.get());
189189
VThreadRunner.run(() -> {
190190
var obj = new Object();
191191
INHERITED_LOCAL.set(obj);
192192
int characteristics = VThreadRunner.NO_INHERIT_THREAD_LOCALS;
193193
VThreadRunner.run(characteristics, () -> {
194-
assertTrue(INHERITED_LOCAL.get() == null);
194+
assertNull(INHERITED_LOCAL.get());
195195
});
196196
assertTrue(INHERITED_LOCAL.get() == obj);
197197

198198
});
199-
assertTrue(INHERITED_LOCAL.get() == null);
199+
assertNull(INHERITED_LOCAL.get());
200200
}
201201
}

test/jdk/jdk/incubator/concurrent/ScopedValue/ScopeValueAPI.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void testIsBound(ThreadFactory factory) throws Exception {
176176
void testOrElse(ThreadFactory factory) throws Exception {
177177
test(factory, () -> {
178178
ScopedValue<String> name = ScopedValue.newInstance();
179-
assertTrue(name.orElse(null) == null);
179+
assertNull(name.orElse(null));
180180
assertEquals("default", name.orElse("default"));
181181

182182
// run
@@ -307,22 +307,22 @@ void testRebindingFromNull(ThreadFactory factory) throws Exception {
307307
// run
308308
ScopedValue.where(name, null, () -> {
309309
assertTrue(name.isBound());
310-
assertTrue(name.get() == null);
310+
assertNull(name.get());
311311

312312
ScopedValue.where(name, "duchess", () -> {
313313
assertTrue(name.isBound());
314314
assertTrue("duchess".equals(name.get()));
315315
});
316316

317317
assertTrue(name.isBound());
318-
assertTrue(name.get() == null);
318+
assertNull(name.get());
319319
});
320320
assertFalse(name.isBound());
321321

322322
// call
323323
ScopedValue.where(name, null, () -> {
324324
assertTrue(name.isBound());
325-
assertTrue(name.get() == null);
325+
assertNull(name.get());
326326

327327
ScopedValue.where(name, "duchess", () -> {
328328
assertTrue(name.isBound());
@@ -331,7 +331,7 @@ void testRebindingFromNull(ThreadFactory factory) throws Exception {
331331
});
332332

333333
assertTrue(name.isBound());
334-
assertTrue(name.get() == null);
334+
assertNull(name.get());
335335
return null;
336336
});
337337
assertFalse(name.isBound());
@@ -354,7 +354,7 @@ void testRebindingToNull(ThreadFactory factory) throws Exception {
354354

355355
ScopedValue.where(name, null, () -> {
356356
assertTrue(name.isBound());
357-
assertTrue(name.get() == null);
357+
assertNull(name.get());
358358
});
359359

360360
assertTrue(name.isBound());
@@ -369,7 +369,7 @@ void testRebindingToNull(ThreadFactory factory) throws Exception {
369369

370370
ScopedValue.where(name, null, () -> {
371371
assertTrue(name.isBound());
372-
assertTrue(name.get() == null);
372+
assertNull(name.get());
373373
return null;
374374
});
375375

test/jdk/jdk/incubator/concurrent/StructuredTaskScope/StructuredTaskScopeTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void testForkConfined(ThreadFactory factory) throws Exception {
160160
return null;
161161
});
162162
future2.get();
163-
assertTrue(future2.resultNow() == null);
163+
assertNull(future2.resultNow());
164164

165165
// random thread cannot fork
166166
try (var pool = Executors.newCachedThreadPool(factory)) {
@@ -528,7 +528,8 @@ void testJoinUntil1(ThreadFactory factory) throws Exception {
528528

529529
long startMillis = millisTime();
530530
scope.joinUntil(Instant.now().plusSeconds(30));
531-
assertTrue(future.isDone() && future.resultNow() == null);
531+
assertTrue(future.isDone());
532+
assertNull(future.resultNow());
532533
expectDuration(startMillis, /*min*/1900, /*max*/20_000);
533534
}
534535
}
@@ -733,7 +734,7 @@ void testShutdownConfined(ThreadFactory factory) throws Exception {
733734
return null;
734735
});
735736
future2.get();
736-
assertTrue(future2.resultNow() == null);
737+
assertNull(future2.resultNow());
737738

738739
scope2.join();
739740
scope1.join();

test/jdk/jdk/internal/misc/ThreadFlock/ThreadFlockTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ private static Stream<ThreadFactory> factories() {
8787
@Test
8888
void testName() {
8989
try (var flock = ThreadFlock.open(null)) {
90-
assertTrue(flock.name() == null);
90+
assertNull(flock.name());
9191
flock.close();
92-
assertTrue(flock.name() == null); // after close
92+
assertNull(flock.name()); // after close
9393
}
9494
try (var flock = ThreadFlock.open("fetcher")) {
9595
assertEquals("fetcher", flock.name());
@@ -168,7 +168,7 @@ void testThreads(ThreadFactory factory) {
168168
flock.close();
169169
}
170170
assertTrue(flock.threads().count() == 0);
171-
assertTrue(exception.get() == null);
171+
assertNull(exception.get());
172172
}
173173

174174
/**
@@ -372,7 +372,7 @@ private void testStartConfined(ThreadFlock flock,
372372
thread.join();
373373
Throwable cause = exception.get();
374374
if (flock.containsThread(thread)) {
375-
assertTrue(cause == null);
375+
assertNull(cause);
376376
} else {
377377
assertTrue(cause instanceof WrongThreadException);
378378
}
@@ -582,7 +582,7 @@ void testInterruptAwaitAll1(ThreadFactory factory) {
582582
}
583583

584584
// thread should not have throw any exception
585-
assertTrue(exception.get() == null);
585+
assertNull(exception.get());
586586
}
587587

588588
/**
@@ -634,7 +634,7 @@ void testInterruptAwaitAll2(ThreadFactory factory) {
634634
}
635635

636636
// thread should not have throw any exception
637-
assertTrue(exception.get() == null);
637+
assertNull(exception.get());
638638
}
639639

640640
/**
@@ -791,7 +791,7 @@ private void testWakeupConfined(ThreadFlock flock,
791791
thread.join();
792792
Throwable cause = exception.get();
793793
if (flock.containsThread(thread)) {
794-
assertTrue(cause == null);
794+
assertNull(cause);
795795
} else {
796796
assertTrue(cause instanceof WrongThreadException);
797797
}
@@ -831,7 +831,7 @@ void testCloseWithThreads(ThreadFactory factory) {
831831
}
832832
assertTrue(flock.isClosed());
833833
assertTrue(flock.threads().count() == 0);
834-
assertTrue(exception.get() == null); // no exception thrown
834+
assertNull(exception.get()); // no exception thrown
835835
}
836836

837837
/**
@@ -908,7 +908,7 @@ void testInterruptClose1(ThreadFactory factory) {
908908
} finally {
909909
assertTrue(Thread.interrupted()); // clear interrupt
910910
}
911-
assertTrue(exception.get() == null);
911+
assertNull(exception.get());
912912
}
913913

914914
/**
@@ -932,7 +932,7 @@ void testInterruptClose2(ThreadFactory factory) {
932932
} finally {
933933
assertTrue(Thread.interrupted()); // clear interrupt
934934
}
935-
assertTrue(exception.get() == null);
935+
assertNull(exception.get());
936936
}
937937

938938
/**
@@ -982,7 +982,7 @@ private void testShutdownConfined(ThreadFlock flock,
982982
thread.join();
983983
Throwable cause = exception.get();
984984
if (flock.containsThread(thread)) {
985-
assertTrue(cause == null);
985+
assertNull(cause);
986986
} else {
987987
assertTrue(cause instanceof WrongThreadException);
988988
}

0 commit comments

Comments
 (0)