从CompletionException中提取CompletableFuture

时间:2019-07-24 15:30:14

标签: java asynchronous testing future completable-future

此测试失败,因为我收到CompletionException异常,但是该方法抛出IllegalArgumentException。因此,将实际异常包装到CompletionException中。如何提取包装在CompletionException中的异常?我尝试了异常,处理等,但没有给我我想要的东西。我将异常作为java.util.concurrent.CompletionException:java.lang.IllegalArgumentException:一些消息。

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "some message")
public void someTest() {
    CompletableFuture.runAsync(() -> someMethodThrowsException()).join();
}

1 个答案:

答案 0 :(得分:2)

这是您为了获得函数抛出的原始异常而可以做的事情:

8ms to load the activator of org.eclipse.osgi_3.14.0.v20190517-1309 [0]
38ms to load and start the activator of org.eclipse.osgi_3.14.0.v20190517-1309 [0]
Time to load bundles: 23
4ms to load the activator of org.eclipse.equinox.simpleconfigurator_1.3.200.v20181101-1115 [1]
369ms to load and start the activator of org.eclipse.equinox.simpleconfigurator_1.3.200.v20181101-1115 [1]
368ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.simpleconfigurator"; type="osgi.bundle"; version:Version="1.3.200.v20181101-1115"; singleton:="true" [id=1]
369ms for total start time of osgi.identity; osgi.identity="org.eclipse.osgi"; type="osgi.bundle"; version:Version="3.14.0.v20190517-1309"; singleton:="true" [id=0]
2ms to load the activator of org.apache.felix.scr_2.1.14.v20190123-1619 [26]
12ms to load and start the activator of org.apache.felix.scr_2.1.14.v20190123-1619 [26]
12ms for total start time of osgi.identity; osgi.identity="org.apache.felix.scr"; type="osgi.bundle"; version:Version="2.1.14.v20190123-1619" [id=26]
1ms to load the activator of org.eclipse.equinox.common_3.10.400.v20190516-1504 [76]
6ms to load and start the activator of org.eclipse.equinox.common_3.10.400.v20190516-1504 [76]
6ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.common"; type="osgi.bundle"; version:Version="3.10.400.v20190516-1504"; singleton:="true" [id=76]
0ms to load the activator of org.eclipse.equinox.event_1.5.100.v20190528-1257 [78]
5ms to load and start the activator of org.eclipse.equinox.event_1.5.100.v20190528-1257 [78]
23ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.event"; type="osgi.bundle"; version:Version="1.5.100.v20190528-1257" [id=78]
0ms for total start time of osgi.identity; osgi.identity="com.ibm.icu"; type="osgi.bundle"; version:Version="64.2.0.v20190507-1337" [id=6]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.ant.core"; type="osgi.bundle"; version:Version="3.5.400.v20190510-0606"; singleton:="true" [id=31]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.compare.core"; type="osgi.bundle"; version:Version="3.6.500.v20190519-2354" [id=32]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.contenttype"; type="osgi.bundle"; version:Version="3.7.300.v20190215-2048"; singleton:="true" [id=34]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.databinding"; type="osgi.bundle"; version:Version="1.7.400.v20190513-2118" [id=35]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.databinding.property"; type="osgi.bundle"; version:Version="1.7.0.v20190510-1100" [id=38]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.expressions"; type="osgi.bundle"; version:Version="3.6.400.v20190518-1240"; singleton:="true" [id=39]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.filesystem"; type="osgi.bundle"; version:Version="1.7.400.v20190518-1151"; singleton:="true" [id=40]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.jobs"; type="osgi.bundle"; version:Version="3.10.400.v20190506-1457"; singleton:="true" [id=42]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.resources"; type="osgi.bundle"; version:Version="3.13.400.v20190505-1655"; singleton:="true" [id=43]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.variables"; type="osgi.bundle"; version:Version="3.4.500.v20190510-0549"; singleton:="true" [id=46]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.draw2d"; type="osgi.bundle"; version:Version="3.10.100.201606061308" [id=47]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.contexts"; type="osgi.bundle"; version:Version="1.8.100.v20190518-1217" [id=49]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.di"; type="osgi.bundle"; version:Version="1.7.200.v20190506-1457" [id=50]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.di.extensions"; type="osgi.bundle"; version:Version="0.15.300.v20190213-1308"; singleton:="true" [id=52]
0ms to load the activator of org.eclipse.e4.core.di_1.7.200.v20190506-1457 [50]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.di"; type="osgi.bundle"; version:Version="1.7.200.v20190506-1457" [id=50]
0ms to load the activator of org.eclipse.e4.core.di.extensions.supplier_0.15.300.v20190506-1457 [53]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.di.extensions.supplier"; type="osgi.bundle"; version:Version="0.15.300.v20190506-1457" [id=53]
19ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.di.extensions.supplier"; type="osgi.bundle"; version:Version="0.15.300.v20190506-1457" [id=53]
2ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.services"; type="osgi.bundle"; version:Version="2.1.400.v20181215-2145"; singleton:="true" [id=54]
1ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.tools.services"; type="osgi.bundle"; version:Version="4.8.200.v20181022-1512" [id=56]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.bindings"; type="osgi.bundle"; version:Version="0.12.500.v20190510-1100"; singleton:="true" [id=57]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.css.swt"; type="osgi.bundle"; version:Version="0.13.500.v20190513-2118"; singleton:="true" [id=59]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.css.swt.theme"; type="osgi.bundle"; version:Version="0.12.300.v20190510-1100"; singleton:="true" [id=60]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.di"; type="osgi.bundle"; version:Version="1.2.600.v20190510-1100" [id=61]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.model.workbench"; type="osgi.bundle"; version:Version="2.1.400.v20190513-2118"; singleton:="true" [id=62]
1ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.services"; type="osgi.bundle"; version:Version="1.3.500.v20190513-2118"; singleton:="true" [id=63]
2ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench"; type="osgi.bundle"; version:Version="1.10.0.v20190529-1505"; singleton:="true" [id=65]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench.addons.swt"; type="osgi.bundle"; version:Version="1.3.500.v20190513-2118"; singleton:="true" [id=66]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench.renderers.swt"; type="osgi.bundle"; version:Version="0.14.700.v20190517-1525"; singleton:="true" [id=67]
1ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench.swt"; type="osgi.bundle"; version:Version="0.14.600.v20190513-2118"; singleton:="true" [id=68]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.emf.common"; type="osgi.bundle"; version:Version="2.16.0.v20190528-0845"; singleton:="true" [id=70]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.emf.ecore"; type="osgi.bundle"; version:Version="2.18.0.v20190528-0845"; singleton:="true" [id=71]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.emf.ecore.change"; type="osgi.bundle"; version:Version="2.14.0.v20190528-0725"; singleton:="true" [id=72]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.emf.ecore.xmi"; type="osgi.bundle"; version:Version="2.16.0.v20190528-0725"; singleton:="true" [id=73]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.app"; type="osgi.bundle"; version:Version="1.4.200.v20190516-1504"; singleton:="true" [id=74]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.bidi"; type="osgi.bundle"; version:Version="1.2.0.v20190514-1046"; singleton:="true" [id=75]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.preferences"; type="osgi.bundle"; version:Version="3.7.400.v20190516-1504"; singleton:="true" [id=81]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.registry"; type="osgi.bundle"; version:Version="3.8.400.v20190516-1504"; singleton:="true" [id=83]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.util"; type="osgi.bundle"; version:Version="1.1.200.v20181008-1820" [id=86]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.help"; type="osgi.bundle"; version:Version="3.8.400.v20190423-0921"; singleton:="true" [id=89]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.team.core"; type="osgi.bundle"; version:Version="3.8.600.v20190519-2354"; singleton:="true" [id=103]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.ui"; type="osgi.bundle"; version:Version="3.113.0.v20190513-2118"; singleton:="true" [id=105]
1ms for total start time of osgi.identity; osgi.identity="org.eclipse.ui.workbench"; type="osgi.bundle"; version:Version="3.115.0.v20190521-1602"; singleton:="true" [id=106]
1ms to load the activator of org.eclipse.equinox.registry_3.8.400.v20190516-1504 [83]
154ms to load and start the activator of org.eclipse.equinox.registry_3.8.400.v20190516-1504 [83]
154ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.registry"; type="osgi.bundle"; version:Version="3.8.400.v20190516-1504"; singleton:="true" [id=83]
0ms to load the activator of org.eclipse.equinox.preferences_3.7.400.v20190516-1504 [81]
19ms to load and start the activator of org.eclipse.equinox.preferences_3.7.400.v20190516-1504 [81]
19ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.preferences"; type="osgi.bundle"; version:Version="3.7.400.v20190516-1504"; singleton:="true" [id=81]
175ms to load the activator of org.eclipse.core.runtime_3.15.300.v20190508-0543 [45]
0ms to load the activator of org.eclipse.core.contenttype_3.7.300.v20190215-2048 [34]
3ms to load and start the activator of org.eclipse.core.contenttype_3.7.300.v20190215-2048 [34]
3ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.contenttype"; type="osgi.bundle"; version:Version="3.7.300.v20190215-2048"; singleton:="true" [id=34]
0ms to load the activator of org.eclipse.core.jobs_3.10.400.v20190506-1457 [42]
20ms to load and start the activator of org.eclipse.core.jobs_3.10.400.v20190506-1457 [42]
21ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.jobs"; type="osgi.bundle"; version:Version="3.10.400.v20190506-1457"; singleton:="true" [id=42]
0ms to load the activator of org.eclipse.equinox.app_1.4.200.v20190516-1504 [74]
10ms to load and start the activator of org.eclipse.equinox.app_1.4.200.v20190516-1504 [74]
10ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.app"; type="osgi.bundle"; version:Version="1.4.200.v20190516-1504"; singleton:="true" [id=74]
218ms to load and start the activator of org.eclipse.core.runtime_3.15.300.v20190508-0543 [45]
218ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.runtime"; type="osgi.bundle"; version:Version="3.15.300.v20190508-0543"; singleton:="true" [id=45]
1ms to load the activator of org.eclipse.equinox.console_1.3.300.v20190516-1504 [77]
1ms to load the activator of org.apache.felix.gogo.runtime_1.1.0.v20180713-1646 [24]
9ms to load and start the activator of org.apache.felix.gogo.runtime_1.1.0.v20180713-1646 [24]
10ms for total start time of osgi.identity; osgi.identity="org.apache.felix.gogo.runtime"; type="osgi.bundle"; version:Version="1.1.0.v20180713-1646" [id=24]
1ms to load the activator of org.apache.felix.gogo.shell_1.1.0.v20180713-1646 [25]
8ms to load and start the activator of org.apache.felix.gogo.shell_1.1.0.v20180713-1646 [25]
8ms for total start time of osgi.identity; osgi.identity="org.apache.felix.gogo.shell"; type="osgi.bundle"; version:Version="1.1.0.v20180713-1646" [id=25]
0ms to load the activator of org.apache.felix.gogo.command_1.0.2.v20170914-1324 [23]
4ms to load and start the activator of org.apache.felix.gogo.command_1.0.2.v20170914-1324 [23]
4ms for total start time of osgi.identity; osgi.identity="org.apache.felix.gogo.command"; type="osgi.bundle"; version:Version="1.0.2.v20170914-1324" [id=23]
34ms to load and start the activator of org.eclipse.equinox.console_1.3.300.v20190516-1504 [77]
33ms for total start time of osgi.identity; osgi.identity="org.eclipse.equinox.console"; type="osgi.bundle"; version:Version="1.3.300.v20190516-1504" [id=77]
Starting application: 1090
1ms to load the activator of org.eclipse.e4.ui.workbench.swt_0.14.600.v20190513-2118 [68]
2ms to load and start the activator of org.eclipse.e4.ui.workbench.swt_0.14.600.v20190513-2118 [68]
2ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench.swt"; type="osgi.bundle"; version:Version="0.14.600.v20190513-2118"; singleton:="true" [id=68]
0ms to load the activator of org.eclipse.e4.ui.model.workbench_2.1.400.v20190513-2118 [62]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.model.workbench"; type="osgi.bundle"; version:Version="2.1.400.v20190513-2118"; singleton:="true" [id=62]
0ms to load the activator of org.eclipse.e4.core.services_2.1.400.v20181215-2145 [54]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.services"; type="osgi.bundle"; version:Version="2.1.400.v20181215-2145"; singleton:="true" [id=54]
1ms to load the activator of org.eclipse.e4.ui.workbench_1.10.0.v20190529-1505 [65]
3ms to load and start the activator of org.eclipse.e4.ui.workbench_1.10.0.v20190529-1505 [65]
2ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench"; type="osgi.bundle"; version:Version="1.10.0.v20190529-1505"; singleton:="true" [id=65]
0ms to load the activator of org.eclipse.e4.core.contexts_1.8.100.v20190518-1217 [49]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.contexts"; type="osgi.bundle"; version:Version="1.8.100.v20190518-1217" [id=49]
0ms to load the activator of org.eclipse.e4.ui.services_1.3.500.v20190513-2118 [63]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.services"; type="osgi.bundle"; version:Version="1.3.500.v20190513-2118"; singleton:="true" [id=63]
1ms to load the activator of org.eclipse.e4.tools.services_4.8.200.v20181022-1512 [56]
1ms to load and start the activator of org.eclipse.e4.tools.services_4.8.200.v20181022-1512 [56]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.tools.services"; type="osgi.bundle"; version:Version="4.8.200.v20181022-1512" [id=56]
0ms to load the activator of org.eclipse.e4.ui.di_1.2.600.v20190510-1100 [61]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.di"; type="osgi.bundle"; version:Version="1.2.600.v20190510-1100" [id=61]
0ms to load the activator of com.ibm.icu_64.2.0.v20190507-1337 [6]
0ms for total start time of osgi.identity; osgi.identity="com.ibm.icu"; type="osgi.bundle"; version:Version="64.2.0.v20190507-1337" [id=6]
57ms to load the activator of org.eclipse.emf.common_2.16.0.v20190528-0845 [70]
57ms to load and start the activator of org.eclipse.emf.common_2.16.0.v20190528-0845 [70]
57ms for total start time of osgi.identity; osgi.identity="org.eclipse.emf.common"; type="osgi.bundle"; version:Version="2.16.0.v20190528-0845"; singleton:="true" [id=70]
2ms to load the activator of org.eclipse.emf.ecore_2.18.0.v20190528-0845 [71]
20ms to load and start the activator of org.eclipse.emf.ecore_2.18.0.v20190528-0845 [71]
19ms for total start time of osgi.identity; osgi.identity="org.eclipse.emf.ecore"; type="osgi.bundle"; version:Version="2.18.0.v20190528-0845"; singleton:="true" [id=71]
1ms to load the activator of org.eclipse.emf.ecore.xmi_2.16.0.v20190528-0725 [73]
1ms to load and start the activator of org.eclipse.emf.ecore.xmi_2.16.0.v20190528-0725 [73]
1ms for total start time of osgi.identity; osgi.identity="org.eclipse.emf.ecore.xmi"; type="osgi.bundle"; version:Version="2.16.0.v20190528-0725"; singleton:="true" [id=73]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [bundleresource://3.fwk1318822808:154/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [bundleresource://3.fwk1318822808:331/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
1ms to load the activator of org.eclipse.core.resources_3.13.400.v20190505-1655 [43]
105ms to load and start the activator of org.eclipse.core.resources_3.13.400.v20190505-1655 [43]
104ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.resources"; type="osgi.bundle"; version:Version="3.13.400.v20190505-1655"; singleton:="true" [id=43]
1ms to load the activator of org.eclipse.core.filesystem_1.7.400.v20190518-1151 [40]
1ms to load and start the activator of org.eclipse.core.filesystem_1.7.400.v20190518-1151 [40]
1ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.filesystem"; type="osgi.bundle"; version:Version="1.7.400.v20190518-1151"; singleton:="true" [id=40]
0ms to load the activator of org.eclipse.e4.ui.workbench.addons.swt_1.3.500.v20190513-2118 [66]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench.addons.swt"; type="osgi.bundle"; version:Version="1.3.500.v20190513-2118"; singleton:="true" [id=66]
5ms to load the activator of org.eclipse.ui.workbench_3.115.0.v20190521-1602 [106]
1ms to load the activator of org.eclipse.ui_3.113.0.v20190513-2118 [105]
2ms to load and start the activator of org.eclipse.ui_3.113.0.v20190513-2118 [105]
2ms for total start time of osgi.identity; osgi.identity="org.eclipse.ui"; type="osgi.bundle"; version:Version="3.113.0.v20190513-2118"; singleton:="true" [id=105]
21ms to load and start the activator of org.eclipse.ui.workbench_3.115.0.v20190521-1602 [106]
20ms for total start time of osgi.identity; osgi.identity="org.eclipse.ui.workbench"; type="osgi.bundle"; version:Version="3.115.0.v20190521-1602"; singleton:="true" [id=106]
1ms to load the activator of org.eclipse.core.expressions_3.6.400.v20190518-1240 [39]
1ms to load and start the activator of org.eclipse.core.expressions_3.6.400.v20190518-1240 [39]
1ms for total start time of osgi.identity; osgi.identity="org.eclipse.core.expressions"; type="osgi.bundle"; version:Version="3.6.400.v20190518-1240"; singleton:="true" [id=39]
0ms to load the activator of org.eclipse.e4.ui.workbench.renderers.swt_0.14.700.v20190517-1525 [67]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.workbench.renderers.swt"; type="osgi.bundle"; version:Version="0.14.700.v20190517-1525"; singleton:="true" [id=67]
0ms to load the activator of org.eclipse.e4.ui.bindings_0.12.500.v20190510-1100 [57]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.bindings"; type="osgi.bundle"; version:Version="0.12.500.v20190510-1100"; singleton:="true" [id=57]
0ms to load the activator of org.eclipse.e4.core.di.extensions_0.15.300.v20190213-1308 [52]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.core.di.extensions"; type="osgi.bundle"; version:Version="0.15.300.v20190213-1308"; singleton:="true" [id=52]
0ms to load the activator of org.eclipse.e4.ui.css.swt.theme_0.12.300.v20190510-1100 [60]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.css.swt.theme"; type="osgi.bundle"; version:Version="0.12.300.v20190510-1100"; singleton:="true" [id=60]
0ms to load the activator of org.eclipse.e4.ui.css.swt_0.13.500.v20190513-2118 [59]
0ms to load and start the activator of org.eclipse.e4.ui.css.swt_0.13.500.v20190513-2118 [59]
0ms for total start time of osgi.identity; osgi.identity="org.eclipse.e4.ui.css.swt"; type="osgi.bundle"; version:Version="0.13.500.v20190513-2118"; singleton:="true" [id=59]
Application started in : 38177ms