mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8186265: Make toString() methods of "task" objects more useful
Reviewed-by: martin, psandoz, rriggs, dholmes, darcy
This commit is contained in:
parent
2ea646cc20
commit
229cce5f44
10 changed files with 240 additions and 23 deletions
|
@ -86,7 +86,7 @@ public class CompletableFutureTest extends JSR166TestCase {
|
|||
void checkIncomplete(CompletableFuture<?> f) {
|
||||
assertFalse(f.isDone());
|
||||
assertFalse(f.isCancelled());
|
||||
assertTrue(f.toString().contains("Not completed"));
|
||||
assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
|
||||
try {
|
||||
assertNull(f.getNow(null));
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
|
@ -109,7 +109,7 @@ public class CompletableFutureTest extends JSR166TestCase {
|
|||
assertTrue(f.isDone());
|
||||
assertFalse(f.isCancelled());
|
||||
assertFalse(f.isCompletedExceptionally());
|
||||
assertTrue(f.toString().contains("[Completed normally]"));
|
||||
assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,7 +165,7 @@ public class CompletableFutureTest extends JSR166TestCase {
|
|||
assertFalse(f.isCancelled());
|
||||
assertTrue(f.isDone());
|
||||
assertTrue(f.isCompletedExceptionally());
|
||||
assertTrue(f.toString().contains("[Completed exceptionally]"));
|
||||
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
|
||||
}
|
||||
|
||||
void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
|
||||
|
@ -220,7 +220,7 @@ public class CompletableFutureTest extends JSR166TestCase {
|
|||
assertTrue(f.isDone());
|
||||
assertTrue(f.isCompletedExceptionally());
|
||||
assertTrue(f.isCancelled());
|
||||
assertTrue(f.toString().contains("[Completed exceptionally]"));
|
||||
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -356,23 +356,40 @@ public class CompletableFutureTest extends JSR166TestCase {
|
|||
/**
|
||||
* toString indicates current completion state
|
||||
*/
|
||||
public void testToString() {
|
||||
CompletableFuture<String> f;
|
||||
|
||||
f = new CompletableFuture<String>();
|
||||
assertTrue(f.toString().contains("[Not completed]"));
|
||||
public void testToString_incomplete() {
|
||||
CompletableFuture<String> f = new CompletableFuture<String>();
|
||||
assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
|
||||
if (testImplementationDetails)
|
||||
assertEquals(identityString(f) + "[Not completed]",
|
||||
f.toString());
|
||||
}
|
||||
|
||||
public void testToString_normal() {
|
||||
CompletableFuture<String> f = new CompletableFuture<String>();
|
||||
assertTrue(f.complete("foo"));
|
||||
assertTrue(f.toString().contains("[Completed normally]"));
|
||||
assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
|
||||
if (testImplementationDetails)
|
||||
assertEquals(identityString(f) + "[Completed normally]",
|
||||
f.toString());
|
||||
}
|
||||
|
||||
f = new CompletableFuture<String>();
|
||||
public void testToString_exception() {
|
||||
CompletableFuture<String> f = new CompletableFuture<String>();
|
||||
assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
|
||||
assertTrue(f.toString().contains("[Completed exceptionally]"));
|
||||
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
|
||||
if (testImplementationDetails)
|
||||
assertTrue(f.toString().startsWith(
|
||||
identityString(f) + "[Completed exceptionally: "));
|
||||
}
|
||||
|
||||
public void testToString_cancelled() {
|
||||
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
|
||||
f = new CompletableFuture<String>();
|
||||
CompletableFuture<String> f = new CompletableFuture<String>();
|
||||
assertTrue(f.cancel(mayInterruptIfRunning));
|
||||
assertTrue(f.toString().contains("[Completed exceptionally]"));
|
||||
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
|
||||
if (testImplementationDetails)
|
||||
assertTrue(f.toString().startsWith(
|
||||
identityString(f) + "[Completed exceptionally: "));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue