столкнулся с проблемой @RunWith (PowerMockRunner.class)
в следующих версиях я использую
powermock-core-1.6.6
powermock-mockito-release-full-1.4.9-full
powermock-api-mockito-1.5.1
junit-4.12
, когда я запускаю свои тестовые примеры, получаю следующие ошибки
java.lang.IllegalStateException: Failed to transform class with name com.Uid. Reason: 3
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:284)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:192)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:77)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:133)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:39)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:111)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
at javassist.bytecode.ByteArray.write16bit(ByteArray.java:40)
at javassist.bytecode.StackMapTable$Shifter.update(StackMapTable.java:744)
at
Мой тестовый класс
@PrepareForTest({UUID.class})
@RunWith(PowerMockRunner.class)
public class Uid extends AbstractMuleContextTestCase{
Sample obj=new Sample(); // created obj for actual class
@Before
public void setUp() throws Exception {
String uuidInStr = "3dd4fa6e-2899-4429-b818-d34fe8df5dd0";
PowerMockito.mockStatic(UUID.class);
PowerMockito.when(UUID.randomUUID().toString()).thenReturn(uuidInStr.toString());
}
@Test
public void runTestCases() throws Exception{
LinkedList<CaseInsensitiveHashMap> payload=new LinkedList<CaseInsensitiveHashMap>();
CaseInsensitiveHashMap map=new CaseInsensitiveHashMap();
payload.add(map);
MuleEvent event=getTestEvent(payload,muleContext);
MuleEventContext eventContext=new DefaultMuleEventContext(event);
eventContext.getMessage().setProperty("apiKey", "sdsdsa-asdas-asd-asd-asd", PropertyScope.SESSION);
eventContext.getMessage().setProperty("clientid", "client", PropertyScope.SESSION);
Assert.assertEquals("",obj.onCall(eventContext));
}
}
как решить?я делаю какие-либо ошибки в своих тестах?
есть ли решение?как я могу решить проблему?