【6.x】将Opt的ofTry捕获范围从Exception提升到Throwable

This commit is contained in:
臧臧
2022-12-06 14:13:48 +08:00
parent 7354e9c5af
commit 0bc8ce836a
2 changed files with 14 additions and 9 deletions

View File

@@ -171,6 +171,10 @@ public class OptTest {
// 你可以在里面写一长串调用链 list.get(0).getUser().getId()
return list.get(0);
}).exceptionOrElse("hutool");
Assert.assertTrue(Opt.ofTry(() -> {
throw new AssertionError("");
}).getThrowable() instanceof AssertionError);
Assert.assertEquals(npe, npeSituation);
Assert.assertEquals(indexOut, indexOutSituation);
Assert.assertEquals("hutool", npe);
@@ -186,8 +190,8 @@ public class OptTest {
}
});
Assert.assertTrue(
(i % 2 == 0 && opt.getException() instanceof IllegalStateException) ||
(i % 2 != 0 && opt.getException() instanceof NullPointerException)
(i % 2 == 0 && opt.getThrowable() instanceof IllegalStateException) ||
(i % 2 != 0 && opt.getThrowable() instanceof NullPointerException)
);
});
}