Попытка использовать jmockit, чтобы заглушить класс javax.sql.DataSource.Есть идеи?
public class MyTest
{
@MockClass(realClass = DataSource.class)
public static class MockDataSource {
}
@Before
public void setup()
{
Mockit.setUpMocks(MockDataSource.class);
}
@Test
public void testCreateGetUpdateUser()
{
new NonStrictExpectations()
{
...
};
...
}
}
Я запускаю тест в Eclipse и получаю это
java.lang.IllegalArgumentException: Not a modifiable class: javax.sql.DataSource
at mockit.internal.RedefinitionEngine.createClassReaderForRealClass(RedefinitionEngine.java:222)
at mockit.internal.RedefinitionEngine.modifyRealClass(RedefinitionEngine.java:207)
at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:199)
at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:193)
at mockit.Mockit.setUpMocks(Mockit.java:274)
at MyTest.setup(EntityManagerUTest.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)