jmockit单元测试中的IllegalArgumentException

时间:2017-06-06 12:40:23

标签: java unit-testing jmockit

我在IllegalArgumentException方法中获得了@BeforeMethod。我是新手使用jmockit所以我不确定注释。我试过切换注释但似乎没有什么可以摆脱错误。

测试类:

public class CSVResultHandlerTest {

CSVResultHandler csvResultHandler;//Not using @Tested since it's not an empty constructor

@Injectable
CSVConfig csvConfig;

private final static Logger logger = LoggerFactory.getLogger(CSVResultHandler.class);

FileDetails fileDetails;
CSVConfig.BulkDataFileConfig bulkDataFileConfig;

@BeforeMethod
public void init() throws IOException, SecurityVaultException {
    bulkDataFileConfig = CSVConfig.BulkDataFileConfig.CZ_DEF;

    fileDetails = new FileDetails();
    fileDetails.setIntervalBeginTimeStamp(Instant.parse("2017-05-06T13:13:38.611Z"));
    fileDetails.setIntervalEndTimeStamp(Instant.parse("2017-05-06T13:13:38.611Z"));
    fileDetails.setPublicationNumber(12345);
    fileDetails.setVersionNumber(1);

    csvConfig = new CSVConfig(bulkDataFileConfig, fileDetails);
    csvResultHandler = new CSVResultHandler(csvConfig);//this is the line getting the error
}

@Test
public void IOExceptionHandled() throws IOException {

    IOException e = new IOException();

    new Expectations() {{
        csvConfig.getFileUrl(); result = new IOException("Mock Exception");
    }};

    csvResultHandler.open();

    new Verifications() {{
        logger.error("Exception thrown while putting file {}",csvConfig.getFileUrl(), e);
    }};

}
}

CSVResultHandler有一个构造函数,它将CSVConfig对象作为唯一参数。我知道我错过了一些愚蠢/简单的东西,只是不确定它是什么。

堆栈跟踪:

java.lang.IllegalArgumentException: PBOX00009: Invalid vaultString format: null
    at org.jboss.security.vault.SecurityVaultUtil.getValue(SecurityVaultUtil.java:89)
    at org.jboss.security.vault.SecurityVaultUtil.getValueAsString(SecurityVaultUtil.java:107)
    at com.org.m2m.bulk.data.security.VaultUtil.getWebDavPwd(VaultUtil.java:13)
    at com.org.m2m.bulk.data.fs.BulkDataFileSystemFactory.newWebDavFileSystem(BulkDataFileSystemFactory.java:25)
    at com.org.m2m.bulk.interval.data.csv.CSVResultHandler.<init>(CSVResultHandler.java:38)
    at com.org.m2m.bulk.interval.data.csv.CSVResultHandlerTest.init(CSVResultHandlerTest.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:589)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:129)
    at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:88)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy3.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:120)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:147)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:129)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案