834 |
|
} |
835 |
|
} |
836 |
|
|
837 |
+ |
/** |
838 |
+ |
* toString indicates current completion state |
839 |
+ |
*/ |
840 |
+ |
public void testToString_incomplete() { |
841 |
+ |
FutureTask<String> f = new FutureTask<String>(() -> ""); |
842 |
+ |
assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); |
843 |
+ |
if (testImplementationDetails) |
844 |
+ |
assertTrue(f.toString().startsWith( |
845 |
+ |
identityString(f) + "[Not completed, task =")); |
846 |
+ |
} |
847 |
+ |
|
848 |
+ |
public void testToString_normal() { |
849 |
+ |
FutureTask<String> f = new FutureTask<String>(() -> ""); |
850 |
+ |
f.run(); |
851 |
+ |
assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); |
852 |
+ |
if (testImplementationDetails) |
853 |
+ |
assertEquals(identityString(f) + "[Completed normally]", |
854 |
+ |
f.toString()); |
855 |
+ |
} |
856 |
+ |
|
857 |
+ |
public void testToString_exception() { |
858 |
+ |
FutureTask<String> f = new FutureTask<String>( |
859 |
+ |
() -> { throw new ArithmeticException(); }); |
860 |
+ |
f.run(); |
861 |
+ |
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
862 |
+ |
if (testImplementationDetails) |
863 |
+ |
assertTrue(f.toString().startsWith( |
864 |
+ |
identityString(f) + "[Completed exceptionally: ")); |
865 |
+ |
} |
866 |
+ |
|
867 |
+ |
public void testToString_cancelled() { |
868 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
869 |
+ |
FutureTask<String> f = new FutureTask<String>(() -> ""); |
870 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
871 |
+ |
assertTrue(f.toString().matches(".*\\[.*Cancelled.*\\]")); |
872 |
+ |
if (testImplementationDetails) |
873 |
+ |
assertEquals(identityString(f) + "[Cancelled]", |
874 |
+ |
f.toString()); |
875 |
+ |
} |
876 |
+ |
} |
877 |
+ |
|
878 |
|
} |