qdrzwd / dexmaker Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/dexmaker
Automatically exported from code.google.com/p/dexmaker
What steps will reproduce the problem?
1. spend 20 years trying very hard to ignore Java
2. a friend needs an app - get on board Android - it rocks
3. Try to mock a stinkin' Activity in a unit test
What is the expected output? What do you see instead?
mock(MainActivity.class) & spy(activity) both crash
The sordid, agonizing details are here: http://stackoverflow.com/questions/19407513/mockitoexception-failed-to-mock-class-com-example-example-test-mainactivity
aaand here: https://groups.google.com/d/msg/mockito/7GcAjTn4F2Y/IKsOTfgQrYMJ
It's all just standard Android 4.3 stuff.
Yes, I set the dexmaker.dexcache property to various /sdcard locations, _with_ write permission, etc
The system hangs up for a long time, then spews:
10-18 14:08:00.780: E/dalvikvm(1664): Could not find class 'android.app.LoaderManagerImpl', referenced from method MainActivity_Proxy.getLoaderManager
10-18 14:08:01.089: E/dalvikvm(1664): Could not find class 'android.app.Activity$NonConfigurationInstances', referenced from method MainActivity_Proxy.retainNonConfigurationInstances
What version of the product are you using? On what operating system?
When I DL Paul Butcher's example from http://paulbutcher.com/2012/05/15/mockito-on-android-step-by-step/ , it works correctly. Then when I generate a new app (in 2.2 or 4.3, with the older JARs or the latest jar), they all exhibit the same bug.
Please provide any additional information below.
I also tried Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
And I debugged into the source through Mockito into the first Dexmaker call, where the crash occurs, but I can't see it's source yet. I will try building Dexmaker next...
Original issue reported on code.google.com by [email protected]
on 18 Oct 2013 at 7:39
What steps will reproduce the problem?
1. try to use dexmaker and mockito via maven
2.
3.
What is the expected output? What do you see instead?
dexmaker will do its magic and cglib will not be used
What version of the product are you using? On what operating system?
0.9 (without the -mockito since it has a "strange" dependency to mockito core
1.9.8)
Please provide any additional information below.
On intellij 11 and maven compiling agains android 4.1.x.x.
Maven:
<dependency>
<groupId>com.google.dexmaker</groupId>
<artifactId>dexmaker</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
Since the it will not work if I use the dexmaker-mockito.
The dependency to mockito 1.9.8 core does not work. Shouldnt the dependency
point to mockito 1.9.5 now? Then I guess I would only have to include that
(dexmaker-moito with "correct" dependency) into my pom?
Or Have I misunderstood the whole thing? Do I really need to go the lib path
with jars + manual handling of maven artefacts etc..?
I have followed the guide on
http://www.paulbutcher.com/2012/05/mockito-on-android-step-by-step/
and it works. Now when all the updated releases are here and in the maven repos
(http://search.maven.org/#artifactdetails%7Corg.mockito%7Cmockito-all%7C1.9.5%7C
jar) I was hoping that this should just work ...
The stacktrace:
java.lang.ExceptionInInitializerError
at
org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImpo
sterizer.java:85)
at
org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposteri
zer.java:62)
at
org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposteri
zer.java:56)
at
org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:23)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
at com.bacana.test.LoginActivityTest.testMockitoMock(LoginActivityTest.java:47)
at java.lang.reflect.Method.invokeNative(Native Method)
at
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTes
tCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:54
5)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
Caused by: java.lang.VerifyError: org/mockito/cglib/core/ReflectUtils
at
org.mockito.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:167)
at
org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrateg
y.java:25)
at
org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java
:217)
at org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)
at org.mockito.cglib.proxy.Enhancer.<clinit>(Enhancer.java:70)
Original issue reported on code.google.com by [email protected]
on 15 Oct 2012 at 6:40
What steps will reproduce the problem?
1. Old version at http://search.maven.org/ - version 0.9 not the 1.0
2.
3.
What is the expected output? What do you see instead?
To get the latest version - 1.0
What version of the product are you using? On what operating system?
Please provide any additional information below.
<dependency>
<groupId>com.google.dexmaker</groupId>
<artifactId>dexmaker-mockito</artifactId>
<version>1.0</version>
</dependency>
Is the dependency I'm trying with.
Is there an eta when the new release will be up?
Regards
Niclas
Original issue reported on code.google.com by [email protected]
on 30 Oct 2012 at 7:55
What steps will reproduce the problem?
public class SimpleClass {
}
public class Test extends Instrumentation {
public void testSimpleProxy() throws IOException {
ProxyBuilder.forClass(SimpleClass.class)
.dexCache(getInstrumentation().getTargetContext().getDir("dx", Context.MODE_PRIVATE))
.handler(new SomeInvocationHandler())
.build();
}
}
What is the expected output? What do you see instead?
Using adb logcat, I'd expect no errors. The logs will, however, include errors
like:
D/dalvikvm( 4555): DEX prep '/data/data/test/app_dx/Generated-360119027.jar':
unzip in 0ms, rewrite 58ms
I/dalvikvm( 4555): DexOpt: illegal method access (call
Ljava/lang/Object;.internalClone (Ljava/lang/Cloneable;)Ljava/lang/Object; from
LSimpleClass_Proxy;)
I/dalvikvm( 4555): Could not find method test.SimpleClass.internalClone,
referenced from method SimpleClass_Proxy.internalClone
W/dalvikvm( 4555): VFY: unable to resolve virtual method 15:
Ltest/SimpleClass;.internalClone (Ljava/lang/Cloneable;)Ljava/lang/Object;
D/dalvikvm( 4555): VFY: replacing opcode 0x6f at 0x0019
I/dalvikvm( 4555): DexOpt: illegal method access (call
Ljava/lang/Object;.internalClone (Ljava/lang/Cloneable;)Ljava/lang/Object; from
LSimpleClass_Proxy;)
I/dalvikvm( 4555): Could not find method test.SimpleClass.internalClone,
referenced from method SimpleClass_Proxy.super$internalClone$java_lang_Object
W/dalvikvm( 4555): VFY: unable to resolve virtual method 15:
Ltest/SimpleClass;.internalClone (Ljava/lang/Cloneable;)Ljava/lang/Object;
D/dalvikvm( 4555): VFY: replacing opcode 0x6f at 0x0000
What's more, these errors will be repeated for every private or package-visible
method on the proxied class (or its superclasses). The ".internalClone" method
listed here (and for every created proxy) is a private method defined on
java.lang.Object, so is reported for every mock and proxy.
Please provide any additional information below.
I don't think this actually poses a functional problem, but I wanted to report
it in case it can be easily fixed. These errors obviously become quite verbose
and can get in the way of reading logcat.
The cause is the code generated in ProxyBuilder, which follows the prototype:
* public int doSomething(Bar param0, int param1) {
* if ($__handler == null) {
* return super.doSomething(param0, param1);
* }
* return __handler.invoke(this, __methodArray[4],
* new Object[] { param0, Integer.valueOf(param1) });
* }
If the "doSomething" method is private or package-visible, then the call to
super.doSomething is inaccessible from the generated proxy class. VFY spots
this and removes the super call.
Is it possible to remove the proxy method altogether for private methods? I may
be missing something, but I can't see how these should ever be called. DexMaker
Issue 24 (https://code.google.com/p/dexmaker/issues/detail?id=24) appears to be
a patch to do just this. I don't think the patch is quite right, however, as it
would prevent package-visible methods from being proxied/mocked as well.
For package-visible methods, we do need the proxy method, but perhaps the
"handler==null" case could just be an exception. This is a form of the general
problem that ProxyBuilder has with package-visible classes.
Original issue reported on code.google.com by [email protected]
on 15 Oct 2013 at 3:12
What steps will reproduce the problem?
1. fix dalvik to pass a null value to InvocationHandler.invoke args
2. use mockito with an interface method that takes no arguments
What is the expected output? What do you see instead?
Don't want to see IllegalArgumentException
What version of the product are you using? On what operating system?
Using from external/dexmaker in AOSP ToT
Please provide any additional information below.
Fix is trivial, just remove null check. I'm filing this for reference before
posting patch to AOSP. I'll link to the CL there when it is uploaded.
diff --git
a/src/mockito/java/com/google/dexmaker/mockito/InvocationHandlerAdapter.java
b/src/mockito/java/com/google/dexmaker/mockito/InvocationHandlerAdapter.java
index 268f2fd..2775a63 100644
--- a/src/mockito/java/com/google/dexmaker/mockito/InvocationHandlerAdapter.java
+++ b/src/mockito/java/com/google/dexmaker/mockito/InvocationHandlerAdapter.java
@@ -45,11 +45,6 @@ final class InvocationHandlerAdapter implements
InvocationHandler {
return System.identityHashCode(proxy);
}
- if (args == null) {
- throw new IllegalArgumentException();
- }
-
-
ProxiedMethod proxiedMethod = new ProxiedMethod(method);
return handler.handle(new InvocationImpl(proxy, proxiedMethod, args, SequenceNumber.next(),
proxiedMethod));
Original issue reported on code.google.com by [email protected]
on 9 Oct 2013 at 9:33
What steps will reproduce the problem?
1. Declare a method with return type A
2. In this method's body call Code.returnValue(local) where local has class
Local<B> and where B extends A
3. Generate this code with DexMaker.generate()
What is the expected output? What do you see instead?
java.lang.IllegalArgumentException: declared A but returned B
What version of the product are you using? On what operating system?
1.0
Please provide any additional information below.
This a common and valid scenario but it's impossible to generate with
dexmaker-1.0. I think this check could be disabled temporarily.
Original issue reported on code.google.com by [email protected]
on 1 Jun 2013 at 5:18
I'm having trouble running the unit tests for dexmaker currently. It would be
handy if there was a wiki article that explained how to check out the source
and set up everything in eclipse so that the unit tests can be run.
Currently, all my tests fail like this, but I have a feeling that I'm doing
something quite wrong.
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.dexmaker.DexMakerTest.getDataDirectory(DexMakerTest.java:1819)
at com.google.dexmaker.stock.ProxyBuilderTest.proxyFor(ProxyBuilderTest.java:778)
at com.google.dexmaker.stock.ProxyBuilderTest.testUnboxedResult(ProxyBuilderTest.java:417)
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 junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
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)
Caused by: java.lang.RuntimeException: Stub!
at android.os.Environment.getDataDirectory(Environment.java:6)
... 24 more
Thanks!
Original issue reported on code.google.com by [email protected]
on 22 May 2012 at 8:48
*What steps will reproduce the problem?
1. Attempt to mock OrmLiteSqliteOpenHelper
http://ormlite.com/javadoc/ormlite-android/com/j256/ormlite/android/apptools/Orm
LiteSqliteOpenHelper.html
2. Crash with a jvm error
*What is the expected output? What do you see instead?
Would expect the mock to work as long as the final method isn't called (I'm not
super familiar with mockito on normal java, so I might be mistaken?). Instead
get the following errors logged.
W/dalvikvm( 1484): Method LDatabaseHelper_Proxy;.onCreate overrides final
Lcom/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper;.onCreate
W/dalvikvm( 1484): failed creating vtable
W/dalvikvm( 1484): Link of class 'LDatabaseHelper_Proxy;' failed
I/TestRunner( 1484): java.lang.VirtualMachineError
I/TestRunner( 1484): at dalvik.system.DexFile.defineClass(Native Method)
I/TestRunner( 1484): at
dalvik.system.DexFile.loadClassBinaryName(DexFile.java:195)
I/TestRunner( 1484): at
dalvik.system.DexPathList.findClass(DexPathList.java:315)
I/TestRunner( 1484): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:58)
I/TestRunner( 1484): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
I/TestRunner( 1484): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
I/TestRunner( 1484): at
com.google.dexmaker.stock.ProxyBuilder.loadClass(ProxyBuilder.java:272)
I/TestRunner( 1484): at
com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:254)
I/TestRunner( 1484): at
com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:
51)
I/TestRunner( 1484): at
org.mockito.internal.util.MockUtil.createMock(MockUtil.java:41)
I/TestRunner( 1484): at
org.mockito.internal.MockitoCore.mock(MockitoCore.java:41)
I/TestRunner( 1484): at org.mockito.Mockito.mock(Mockito.java:1061)
I/TestRunner( 1484): at org.mockito.Mockito.mock(Mockito.java:955)
What version of the product are you using? On what operating system?
Using the code that shipped with the example you posted to the mockito mailing
list.
Please provide any additional information below.
I noticed that OrmLiteSqliteOpenHelper has two onCreate methods- one final, one
not. I tried creating a simple class with an overloaded method bar to match
this, where one bar was final and the other not. I was successfully able to
mock this test class. Not sure what the OrmLiteSqliteOpenHelper does
differently. Have you seen this sort of issue before? Let me know if you need
any more details.
Here is the code from my test class that i *was* able to mock
public final void bar(int a)
{
System.out.println("bar");
}
public void bar(String b)
{
System.out.println(b);
}
Original issue reported on code.google.com by [email protected]
on 14 May 2012 at 6:28
The following code is wrong in the Code class:
public void monitorExit(Local<?> monitor) {
addInstruction(new ThrowingInsn(Rops.MONITOR_ENTER, sourcePosition,
RegisterSpecList.make(monitor.spec()), catches));
}
"monitorExit" should add Rops.MONITOR_EXIT instruction.
Original issue reported on code.google.com by [email protected]
on 2 Dec 2014 at 8:28
java.lang.AbstractMethodError: abstract method not implemented
at com.google.dexmaker.mockito.InvocationHandlerAdapter$ProxiedMethod.isAbstract(InvocationHandlerAdapter.java)
at org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:109)
at org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:41)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:38)
at com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAdapter.java:49)
This is using mockito 1.10.17 with dexmaker 1.2.
Looks like it might be related to this mockito change:
https://github.com/mockito/mockito/commit/f7929968c7ca33cd53acd740975825866b03e8
4e
Original issue reported on code.google.com by [email protected]
on 18 Dec 2014 at 10:25
What steps will reproduce the problem?
0. Create a new android AVD for 2.3.3 and new android project with a test
project
1. Add the mockito nightly build and dexmaker's jars to test project's libs
directory
2. Write a unit test that tries to mock an object
3. Crash!
What is the expected output? What do you see instead?
Expected it to work. Got the following stack trace instead.
I/TestRunner( 445): ----- begin exception -----
I/TestRunner( 445):
I/TestRunner( 445): java.lang.AbstractMethodError: abstract method not
implemented
I/TestRunner( 445): at
com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java)
I/TestRunner( 445): at
org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
I/TestRunner( 445): at
org.mockito.internal.MockitoCore.mock(MockitoCore.java:49)
I/TestRunner( 445): at org.mockito.Mockito.mock(Mockito.java:1245)
I/TestRunner( 445): at org.mockito.Mockito.mock(Mockito.java:1139)
I/TestRunner( 445): at my test method
I/TestRunner( 445): at java.lang.reflect.Method.invokeNative(Native Method)
I/TestRunner( 445): at java.lang.reflect.Method.invoke(Method.java:507)
I/TestRunner( 445): at junit.framework.TestCase.runTest(TestCase.java:154)
I/TestRunner( 445): at junit.framework.TestCase.runBare(TestCase.java:127)
I/TestRunner( 445): at
junit.framework.TestResult$1.protect(TestResult.java:106)
I/TestRunner( 445): at
junit.framework.TestResult.runProtected(TestResult.java:124)
I/TestRunner( 445): at junit.framework.TestResult.run(TestResult.java:109)
I/TestRunner( 445): at junit.framework.TestCase.run(TestCase.java:118)
I/TestRunner( 445): at
android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
I/TestRunner( 445): at
android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
I/TestRunner( 445): at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:52
9)
I/TestRunner( 445): at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
I/TestRunner( 445): ----- end exception -----
What version of the product are you using? On what operating system?
android 2.3. I used the 3-5-2012 dexmaker build and
mockito-all-1.9.1-snapshot.jar. I'm using eclipse as my dev environment.
Below is the unit test that fails
public class ATest extends AndroidTestCase {
public void testMock(){
mock(ArrayList.class);
}
}
Original issue reported on code.google.com by [email protected]
on 11 May 2012 at 8:04
To reproduce:
public class Test extends TestCase {
// mocked objects
@Mock private LinearLayout layout;
@Override
protected void setUp() {
MockitoAnnotations.initMocks(this);
try {
super.setUp();
} catch (Exception e) {
// Ignore exception
}
}
public void testTest() {
System.out.println("Hello");
}
}
What version of the product are you using? On what operating system?
Mockito and Dexmaker from latest sources
While converting an android-mock test to use mockito + dexmaker, this line:
@Mock private LinearLayout layout;
caused:
java.lang.VirtualMachineError
at dalvik.system.DexFile.defineClass(Native Method)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:195)
at dalvik.system.DexPathList.findClass(DexPathList.java:315)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:58)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at com.google.dexmaker.stock.ProxyBuilder.loadClass(ProxyBuilder.java:273)
at com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:255)
at
com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:
54)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:49)
at org.mockito.Mockito.mock(Mockito.java:1224)
at
org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotatio
nProcessor.java:30)
at
org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotatio
nProcessor.java:16)
at
org.mockito.internal.configuration.DefaultAnnotationEngine.createMockFor(Default
AnnotationEngine.java:43)
at
org.mockito.internal.configuration.DefaultAnnotationEngine.process(DefaultAnnota
tionEngine.java:66)
at
org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentA
nnotations(InjectingAnnotationEngine.java:71)
at
org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAn
notationEngine.java:55)
at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:108)
at test.Test.setUp(Test.java:17)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:53
7)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
Perhaps these Android classes aren't meant to be mocked, but it would simplify
the conversion of tests from android-mock to Mockito + Dexmaker.
Original issue reported on code.google.com by [email protected]
on 31 May 2012 at 1:05
What steps will reproduce the problem?
1. Make a simple JUnit test with a mock(...) in the setUp (which calls into
DexMaker.generateAndLoad)
2. Run on some devices (Does repo on DROID RAZR Android 4.0.4. Does not repo on
Galaxy S3 Android 4.1.1)
3. Half the time the test will hang forever on DexFile.openDexFile.
What is the expected output? What do you see instead?
That calls into DexMaker.generateAndLoad will eventually return.
What version of the product are you using? On what operating system?
[mockito-all-1.9.5.jar, javassist-3.16.1-GA.jar, dexmaker-mockito-1.0.jar,
dexmaker-1.0.jar]
DROID RAZR 6.16.211.XT912.Verizon.en.US (Android 4.0.4)
Please provide any additional information below.
I found this Android bug, not sure if it relates.
http://code.google.com/p/android/issues/detail?id=14962
Here is a thread dump of the InstrumentationTestRunner thread that is stuck.
11 13448 vmwait 3364 776 Instr:
android.test.InstrumentationTestRunner
====
dalvik.system.DexFile openDexFile DexFile.java -2 true
dalvik.system.DexFile <init> DexFile.java 93 false
dalvik.system.DexFile loadDex DexFile.java 133 false
dalvik.system.DexPathList loadDexFile DexPathList.java 261 false
dalvik.system.DexPathList makeDexElements DexPathList.java 229
false
dalvik.system.DexPathList <init> DexPathList.java 96 false
dalvik.system.BaseDexClassLoader <init> BaseDexClassLoader.java 52
false
dalvik.system.DexClassLoader <init> DexClassLoader.java 57 false
java.lang.reflect.Constructor constructNative Constructor.java -2
true
java.lang.reflect.Constructor newInstance Constructor.java 417
false
com.google.dexmaker.DexMaker generateAndLoad DexMaker.java 382
false
com.google.dexmaker.stock.ProxyBuilder buildProxyClass ProxyBuilder.java
252 false
com.google.dexmaker.mockito.DexmakerMockMaker createMock
DexmakerMockMaker.java 56 false
org.mockito.internal.util.MockUtil createMock MockUtil.java 26
false
org.mockito.internal.MockitoCore mock MockitoCore.java 51 false
org.mockito.Mockito mock Mockito.java 1243 false
org.mockito.Mockito mock Mockito.java 1120 false
com.mystuff.android.SomeTest setUp SomeTest.java 30 false
junit.framework.TestCase runBare TestCase.java 125 false
junit.framework.TestResult$1 protect TestResult.java 106 false
junit.framework.TestResult runProtected TestResult.java 124 false
junit.framework.TestResult run TestResult.java 109 false
junit.framework.TestCase run TestCase.java 118 false
android.test.AndroidTestRunner runTest AndroidTestRunner.java 169
false
android.test.AndroidTestRunner runTest AndroidTestRunner.java 154
false
android.test.InstrumentationTestRunner onStart
InstrumentationTestRunner.java 545 false
android.app.Instrumentation$InstrumentationThread run
Instrumentation.java 1551 false
Original issue reported on code.google.com by [email protected]
on 30 Jan 2013 at 4:17
We should work with the Mockito guys to find something that doesn't require
users to manually remove dexmaker from the class paths of their Android
projects.
Original issue reported on code.google.com by [email protected]
on 2 Apr 2012 at 2:03
Stubbing a call of method without arguments with Mockito 1.9.5-rc1 fails with
IllegalArgumentException. I'm using robolectric-1.1 to run the unit test
locally.
Here's code I'm using to verify this:
interface Foo {
String noArgs();
}
@Test
public void testNoArgMethod() {
Foo mockedObject = mock(Foo.class);
when(mockedObject.toString()).thenReturn("foobar");
assertEquals(mockedObject.toString(), "foobar");
}
Test is in error state due to:
java.lang.IllegalArgumentException
at com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAdapter.java:49)
at com.seven.opencare.data.$Proxy12.toString(Unknown Source)
at NoArgMethodTest.testNoArgMethod(NoArgMethodTest.java:15)
...
According to Mockito's documentation, it is expected to get
InvocationHandler.invoke where args==null if the method being called does not
have arguments. It seems safe to remove the null check throwing the exception
from InvocationHandlerAdapter.invoke() implementation, as according to
documentation it actually isn't illegal argument.
Original issue reported on code.google.com by [email protected]
on 22 Aug 2012 at 5:37
What steps will reproduce the problem?
1. include this in pom.xml:
<!-- Mockito: mock objects -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5-rc1</version>
</dependency>
<!-- Dexmaker: API for compile time/runtime Android code generation -->
<dependency>
<groupId>com.google.dexmaker</groupId>
<artifactId>dexmaker</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>com.google.dexmaker</groupId>
<artifactId>dexmaker-mockito</artifactId>
<version>0.9</version>
</dependency>
2. Attempt to run (like mvn clean install android:deploy)
What is the expected output? What do you see instead?
Instead of working, I get that mvn couldn't find transitive dependency for
mockito-core 1.9.8, a check into the pom.xml for dexmaker-mockito confirms that
it was declaring that version of mockito as a dependency, which shouldn't make
sense, as 1.9.5-rc1 should be the highest version currently. Just changing that
version should resolve the issue.
Original issue reported on code.google.com by [email protected]
on 5 Oct 2012 at 7:48
"Private, static or final methods will always call through to the superclass as
normal."
Is it possible to provide the invocationhandler callback in the proxy for
static method? any technical limitations to acheive this?
Original issue reported on code.google.com by [email protected]
on 3 Dec 2013 at 2:49
Mockito doesn't seem to work on ART ( on L preview or Kitkat )
The same code works fine on Dalvik.
Also, see here:
http://stackoverflow.com/questions/20514588/instrumentation-result-shortmsg-java
-lang-noclassdeffounderror-running-android
and here:
https://code.google.com/p/android-developer-preview/issues/detail?id=1081
and here:
https://github.com/mockito/mockito/issues/71
java.lang.NoClassDefFoundError: org.mockito.internal.runners.RunnerImpl
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:100)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:367)
08-11 15:14:57.406 2313-2313/? W/ClassPathPackageInfoSource๏น Cannot load
class. Make sure it is in your apk. Class name:
'org.mockito.cglib.transform.AbstractTransformTask'. Message:
org.mockito.cglib.transform.AbstractTransformTask
java.lang.ClassNotFoundException: org.mockito.cglib.transform.AbstractTransformTask
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:100)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:367)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:114)
at com.americanexpress.android.acctsvcs.us.AmexInstrumentationTestRunner.onCreate(AmexInstrumentationTestRunner.java:71)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4388)
at android.app.ActivityThread.access$1500(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.mockito.cglib.transform.AbstractTransformTask" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.americanexpress.android.acctsvcs.us.debug.test-1.apk", zip file "/data/app/com.americanexpress.android.acctsvcs.us.debug-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.americanexpress.android.acctsvcs.us.debug.test-1, /data/app-lib/com.americanexpress.android.acctsvcs.us.debug-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:100)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:367)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:114)
at com.americanexpress.android.acctsvcs.us.AmexInstrumentationTestRunner.onCreate(AmexInstrumentationTestRunner.java:71)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4388)
at android.app.ActivityThread.access$1500(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
Suppressed: java.lang.NoClassDefFoundError: org.mockito.cglib.transform.AbstractProcessTask
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:222)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 29 more
Suppressed: java.lang.ClassNotFoundException: org.mockito.cglib.transform.AbstractTransformTask
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 28 more
Caused by: java.lang.NoClassDefFoundError: Class "Lorg/mockito/cglib/transform/AbstractTransformTask;" not found
... 32 more
111
Original issue reported on code.google.com by [email protected]
on 12 Aug 2014 at 4:01
We're seeing many failing Mockito tests with errors like:
java.lang.UnsupportedOperationException: Cannot allocate class [...]_Proxy
at com.google.dexmaker.mockito.UnsafeAllocator$4.newInstance(UnsafeAllocator.java:99)
at com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:60)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:32)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:55)
at org.mockito.Mockito.mock(Mockito.java:1243)
...
It seems that the internal methods used by UnsafeAllocator have changed
recently (see https://android-review.googlesource.com/#/c/52331/).
I've attached a simple fix.
Original issue reported on code.google.com by [email protected]
on 1 Mar 2013 at 4:40
Attachments:
Skip non public methods package-protected methods.
Original issue reported on code.google.com by [email protected]
on 27 May 2013 at 5:43
Attachments:
Thanks for this great job, it's helpful and I'm using it in my projects.
In this case , I need hasTypeDeclaration method to detect some TypeId has
declared:
I'm using DexMaker to create a few of new class in one DexMaker instance, some
of them extends one of them,
for example, class A and Class B are both extends Class C. when I'm creating
A, if C isn't created, I should wait C finish, and then back to go on creating
C.
so, I suggest DexMaker should add public boolean hasTypeDeclaration(TypeId<?>
type){}ใ
Original issue reported on code.google.com by [email protected]
on 29 Dec 2013 at 1:41
This issue impacts using dexmaker as a code generation library for mockito.
What steps will reproduce the problem?
1. Create a class/interface with a method foo that returns a primitive type,
i.e:
public class Foo {
public int foo() {return 0;}
}
2. Create a mock of this object, and call said method, i.e.:
Foo mock = mock(Foo.class);
mock.foo();
3. Verify the method call, i.e.:
verify(mock).foo();
What is the expected output? What do you see instead?
The last line throws a NullPointerException where it should have no output. It
appears (though I have not verified) that mockito just passes null back to the
generated class when the mock is in the verify state, and dexmaker's mock tries
to unbox it as a primitive, causing problems. In cglib, intercepting methods
with a primitive return value and returning null does not cause errors.
What version of the product are you using? On what operating system?
Android ICS on Ubuntu OS
Original issue reported on code.google.com by [email protected]
on 27 Mar 2012 at 3:04
Currently, ProxyBuilder allows you to create only one proxy at a time. From my
measurements on nexus 5, it takes around 200-300 ms to create a simple proxy
and I believe most of the time is spent on reading and writing the dex file.
Wouldn't be better if we can specify multiple classes that can be proxied
together?
Original issue reported on code.google.com by [email protected]
on 2 May 2014 at 1:08
Problem:
Mockito should be able to mock package-protected classes.
---
import static org.mockito.Mockito.*;
class A {}
public class Test {
public static void main(String[] argv) {
A a = mock(A.class);
}
}
---
What is the expected output? What do you see instead?
This code above works well on JVM, but not on Dalvik with mockito+dexmaker,
causes:
java.lang.UnsupportedOperationException: cannot proxy inaccessible class class A
at com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:257)
at
com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:
56)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
Mocking package-private classes is handy when you test them without exposing
publicly.
Otherwise you'll have to declare public every class you want to mock.
What version of the product are you using? On what operating system?
Mockito1.9.5 + Dexmaker fresh cut (6ada76ae1356), on Android 4.4.2
Original issue reported on code.google.com by [email protected]
on 23 Feb 2014 at 4:44
What steps will reproduce the problem?
1. Create a proxy class of the clipboardmanager on samsung device using
dexmaker, the one returned from getSystemService("clipboard")
we will see these dalvik optimization warnings at runtime. It appears we may be
creating proxy of private methods of ClipboardExManager class:-
05-28 19:09:17.725 25713 25713 I dalvikvm: DexOpt: illegal method access (call
Ljava/lang/Object;.internalClone (Ljava/lang/Cloneable;)Ljava/lang/Object; from
LClipboardExManager_Proxy;)
05-28 19:09:17.730 25713 25713 I dalvikvm: Could not find method
android.sec.clipboard.ClipboardExManager.internalClone, referenced from method
ClipboardExManager_Proxy.internalClone
05-28 19:09:17.730 25713 25713 W dalvikvm: VFY: unable to resolve virtual
method 60: Landroid/sec/clipboard/ClipboardExManager;.internalClone
(Ljava/lang/Cloneable;)Ljava/lang/Object;
05-28 19:09:17.730 25713 25713 D dalvikvm: VFY: replacing opcode 0x6f at 0x0019
05-28 19:09:17.730 25713 25713 I dalvikvm: DexOpt: illegal method access (call
Ljava/lang/Object;.internalClone (Ljava/lang/Cloneable;)Ljava/lang/Object; from
LClipboardExManager_Proxy;)
05-28 19:09:17.730 25713 25713 I dalvikvm: Could not find method
android.sec.clipboard.ClipboardExManager.internalClone, referenced from method
ClipboardExManager_Proxy.super$internalClone$java_lang_Object
05-28 19:09:17.730 25713 25713 W dalvikvm: VFY: unable to resolve virtual
method 60: Landroid/sec/clipboard/ClipboardExManager;.internalClone
(Ljava/lang/Cloneable;)Ljava/lang/Object;
05-28 19:09:17.730 25713 25713 D dalvikvm: VFY: replacing opcode 0x6f at 0x0000
Original issue reported on code.google.com by [email protected]
on 29 May 2014 at 10:31
This is a quick enhancement.
java.Proxy has isProxy(Class c) method.
We need a similar method for ProxyBuilder.
Original issue reported on code.google.com by [email protected]
on 24 Feb 2013 at 3:29
Currently if buildProxyClass() is used, new instances of the proxy class won't
have the handler field set, and there isn't an easy way to set it. (I imagined
the generated class would somehow be connected to the handler, probably with a
static handler field, but Jesse pointed out that this would make it impossible
to cache proxy classes.)
It seems like buildProxyClass() may not have been intended for external use, or
may have been considered experimental (the commit message says "I'm not 100%
convinced on this one yet"). But it is public and included in the latest
release, so let's make it easier to use by exposing a method to set the
invocation handler.
I also want to make it really clear in the documentation that callers of
buildProxyClass() must manually set the handler on new instances, even if a
handler() was configured (it would have no effect).
If you agree with the change, here's the commit on my clone:
https://code.google.com/r/daniel-lubarov-dexmaker/source/detail?r=7361f3db4acd18
39d166cad18fdd6b9c25bbe278
Or if it's easier, I attached a patch file.
Original issue reported on code.google.com by [email protected]
on 5 Dec 2014 at 9:13
Attachments:
Hi,
Liking the project very much so far.
However, I'm having trouble building a non-trivial class. I'd like to create a
class with a constructor accepting (for example) a String as an argument. It's
not clear how this is done:
1. Do I have to explicitly call the no-arg constructor for Object (the direct
"super")? The verifier keeps rejecting my attempts:
W/dalvikvm( 6556): VFY: invalid call to Ljava/lang/Object;.<init>
W/dalvikvm( 6556): VFY: rejecting call to Ljava/lang/Object;.<init> ()V
W/dalvikvm( 6556): VFY: rejecting opcode 0x6f at 0x0000
Anyway, here's what I'm doing. I've tried many variations of the call,
including not making the call to Object.<init>. Any insight is welcome.
TypeId<?> someClassType = TypeId.get("LSomeClass;");
TypeId<Object> objectType = TypeId.get(Object.class);
MethodId objectConstructor = objectType.getConstructor();
dexMaker.declare(someClassType, "NewClass.generated", Modifier.PUBLIC, TypeId.OBJECT);
MethodId constructor1 = fileType.getConstructor(TypeId.STRING);
Code code = dexMaker.declare(constructor1, Modifier.PUBLIC);
code.invokeSuper(objectConstructor, null, null);//?
code.returnVoid();//proper close of constructor?
MethodId newMethod = someClassType.getMethod(TypeId.VOID, "newMethod", TypeId.STRING);
code = dexMaker.declare(newMethod, Modifier.PUBLIC);
//do some stuff
code.returnVoid();
Original issue reported on code.google.com by [email protected]
on 25 Jul 2012 at 10:54
What steps will reproduce the problem?
1. proxy android.widget.BaseAdapter
2. callsuper method
3. will throw a exception
all code:
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("xxxx")) {
return null;
}
Object result = ProxyBuilder.callSuper(proxy, method, args);
System.out.println("Method: " + method.getName() + " args: "
+ Arrays.toString(args) + " result: " + result);
return result;
}
};
Object foo = ProxyBuilder.forClass(android.widget.BaseAdapter.class)
.dexCache(getInstrumentation().getTargetContext().getDir("dx", Context.MODE_PRIVATE))
.handler(handler)
.build();
foo.areAllItemsEnabled(); // will throw a exception!!
What is the expected output? What do you see instead?
can call super method except abstract method
What version of the product are you using? On what operating system?
jdk 1.6, android 4.0
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 9 Apr 2014 at 2:20
What steps will reproduce the problem?
1. Use Mockito 1.10.10, dexmaker 1.1, dexmaker-mockito 1.1 in an Android test
project, along with Android Gradle Plugin 0.14.2
2. Try to run tests
3. Get NPE
What is the expected output? What do you see instead?
- Expected output is for the tests to run correctly, instead we get an NPE:
11-14 00:14:10.856 I/TestRunner( 895): java.lang.NullPointerException
11-14 00:14:10.856 I/TestRunner( 895): at
com.google.dexmaker.mockito.DexmakerMockMaker.getInvocationHandlerAdapter(Dexmak
erMockMaker.java:83)
11-14 00:14:10.856 I/TestRunner( 895): at
com.google.dexmaker.mockito.DexmakerMockMaker.getHandler(DexmakerMockMaker.java:
78)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.util.MockUtil.isMockitoMock(MockUtil.java:73)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.util.MockUtil.isMock(MockUtil.java:65)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.configuration.injection.scanner.MockScanner.isMockOrSpy(Moc
kScanner.java:86)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.configuration.injection.scanner.MockScanner.preparedMock(Mo
ckScanner.java:72)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.configuration.injection.scanner.MockScanner.scan(MockScanne
r.java:61)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.configuration.injection.scanner.MockScanner.addPreparedMock
s(MockScanner.java:47)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.configuration.InjectingAnnotationEngine.injectMocks(Injecti
ngAnnotationEngine.java:96)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.configuration.InjectingAnnotationEngine.processInjectMocks(
InjectingAnnotationEngine.java:62)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAn
notationEngine.java:56)
11-14 00:14:10.856 I/TestRunner( 895): at
org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:108)
What version of the product are you using? On what operating system?
Ubuntu 14.04
Original issue reported on code.google.com by [email protected]
on 14 Nov 2014 at 12:21
What steps will reproduce the problem?
I'm trying to declare a public, native method:
dexMaker.declare(methodId, Modifier.PUBLIC | Modifier.NATIVE);
What is the expected output? What do you see instead?
java.lang.IllegalArgumentException: Unexpected flag: 101
DexMaker currently does not support creating native methods and thus the
pre-condition check throws the IllegalArgumentException.
What version of the product are you using? On what operating system?
dexmaker 1.0
Original issue reported on code.google.com by [email protected]
on 22 Oct 2013 at 1:15
*NOTE*: This is a parallel submission for Mockito's one, located at
http://code.google.com/p/mockito/issues/detail?id=386 - note that there is a
workaround in the comments there.
What steps will reproduce the problem?
1. Add mockito, dexmaker and dexmaker-mockito to project
2. Create a mock for SomeClass (code provided in additional information)
3. Instruct to throw SomeException when calling doSomething() method
4. Call doSomething() method
What is the expected output? What do you see instead?
Expected:
Exception is to be thrown
Instead:
Exception is thrown:
java.lang.NoClassDefFoundError: sun.reflect.ReflectionFactory
at
org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflec
tionFactoryInstantiator.java:24)
at
org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiator
Strategy.java:65)
at org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:76)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
at org.objenesis.ObjenesisHelper.newInstance(ObjenesisHelper.java:28)
at
org.mockito.internal.stubbing.answers.ThrowsExceptionClass.answer(ThrowsExceptio
nClass.java:27)
at
org.mockito.internal.stubbing.StubbedInvocationMatcher.answer(StubbedInvocationM
atcher.java:34)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:91)
at
org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:2
9)
at
org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifier
Handler.java:38)
at
com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAda
pter.java:54)
at SomeClass_Proxy.doSomething(SomeClass_Proxy.generated)
at
com.example.SomeTestCase.testDoSomethingSomeExceptionThrown(SomeTestCase.java:10
8)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:53
7)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
What version of the product are you using? On what operating system?
Mockito 1.9.5 (mockito-all version)
dexmaker 0.9
Android 4.0.1 (emulator)
JUnit3
Please provide any additional information below.
0. You guys did great job by providing Mockito to Android developers. I love it!
1. Mocking value returns and verification of methods running appears to be
working fine.
2. Some code:
public class SomeClass {
public void doSomething() throws SomeException {
}
}
public class SomeException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1544471714051523296L;
}
public class SomeTestCase extends TestCase {
public void testSendAsyncMessageMessageNotSentException() {
SomeClass someClass = Mockito.mock(SomeClass.class);
try {
Mockito.doThrow(SomeException.class).when(someClass).doSomething();
someClass.doSomething();
fail();
} catch (SomeException e1) {
//success
} catch (Exception e) {
fail();
}
}
}
Original issue reported on code.google.com by [email protected]
on 23 Oct 2012 at 10:46
In the following example, both "TestPrinter" and "Tester" are in same package
("com.example.test"). However MainActivity where the proxy generation happens
is under a different package ("com.example").
Executing the MainActivity throws an exception "java.lang.IllegalAccessError"
//TestPrinter.java
package com.example.test;
public class TestPrinter {
private static final String TAG = "TestPrinter";
//package visible method.
void method4(String arg1){
Log.i(TAG, String.format("Executing method4(%s)", arg1));
}
}
//Tester.java
package com.example.test;
public class Tester {
public void test(TestPrinter printer){
Random r = new Random();
printer.method4(UUID.randomUUID().toString());
}
}
//MainActivity.java
package com.example;
public class MainActivity extends Activity {
public static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.create_proxy).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
InvocationHandler handler = new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] objects) throws Throwable {
Log.i(TAG,
String.format("%s.%s is being invoked with argument = %s",
proxy.getClass().getSimpleName(), method.getName(), objects));
Object result = ProxyBuilder.callSuper(proxy, method, objects);
return result;
}
};
TestPrinter printer =
ProxyBuilder.forClass(TestPrinter.class)
.dexCache(getApplicationContext().getDir("dex", Context.MODE_PRIVATE))
.handler(handler)
.build();
new Tester().test(printer);
} catch (Throwable e) {
Log.e(TAG, "Error creating runtime proxy", e);
}
}
});
}
}
Original issue reported on code.google.com by [email protected]
on 1 May 2014 at 9:26
Using ProxyBuilder to subclass android.view.View produces errors because the
generated proxy overrides private and package-private methods.
IMO only public and protected methods should be proxied.
This is with today's git snapshot. The attached patch should fix the problem.
Here's a stack trace caused by ProxyBuilder trying to invoke a package-private
super method:
java.lang.IllegalAccessError: tried to access method
android.view.View.getListenerInfo:()Landroid/view/View$ListenerInfo; from class
View_Proxy
at View_Proxy.super_getListenerInfo(View_Proxy.generated)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.google.dexmaker.stock.ProxyBuilder.callSuper(ProxyBuilder.java:504)
Original issue reported on code.google.com by [email protected]
on 12 Jan 2012 at 1:38
Attachments:
I would like to load generated classes with a specific class loader to access
package private classes as well. Actually I have already done this with this
patch, so please (improve and) merge it to upstream:
https://code.google.com/r/bonifaido-dexmaker/source/diff?spec=svnf387270c41eacc7
15dff5ad310e75f11af1a7c9b&old=0bb492abaf9c930f49c8f245d86fb285c269ea83&r=f387270
c41eacc715dff5ad310e75f11af1a7c9b&format=unidiff&path=%2Fdexmaker%2Fsrc%2Fmain%2
Fjava%2Fcom%2Fgoogle%2Fdexmaker%2FDexMaker.java
I'm so sorry that there are no pull-requests here :(
Original issue reported on code.google.com by [email protected]
on 26 May 2013 at 6:49
Can you please open up the final method proxying as well in
getMethodsToProxy(...), this is useful for AOP style proxying. Since
subclassing doesnt allow overriding of final methods. Can we create
method in the proxy class of this form:-
if there is a final method of this form:-
public final void finalMethod()
{
}
can we create a method in the proxy class of this form:-
public final voidproxyFinalMethod()
{
return super.finalMethod();
}
This will be very useful in AOP style proxying where the proxies can
be generated and dumped to dex file and then woven at build time with
the target app.
Original issue reported on code.google.com by [email protected]
on 19 Sep 2012 at 4:57
What steps will reproduce the problem?
1. Android (3.0) + Mockito 1.9.1 (Snapshot) + dexmaker
2. Create Android test project and mock a object using mockito
What is the expected output? What do you see instead?
Code should work but i get an error:
java.lang.IllegalArgumentException: dexcache == null (and no default could be
found; consider setting the 'dexmaker.dexcache' system property)
at com.google.dexmaker.DexMaker.generateAndLoad(DexMaker.java:359)
at com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:252)
at
com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:
51)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:41)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:41)
at org.mockito.Mockito.mock(Mockito.java:1061)
at org.mockito.Mockito.mock(Mockito.java:955)
at
nl.wowww.hallmark.kpp.android.tablet.test.CardSelection.testMockito(CardSelectio
n.java:102)
at java.lang.reflect.Method.invokeNative(Native Method)
at
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTes
tCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:52
5)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1547)
What version of the product are you using? On what operating system?
dexmaker20120305 + android sdk r17
Original issue reported on code.google.com by [email protected]
on 23 Mar 2012 at 2:56
https://android-review.googlesource.com/#/c/67600/
Original issue reported on code.google.com by limpbizkit
on 10 Oct 2013 at 12:34
What steps will reproduce the problem?
1. Install a current build of Mockito, DexMaker.
2. Run a test which creates a mock of something in java.lang or android.os
A very simple affected test would be:
public class MockSystemInterface extends InstrumentationTestCase {
public void test() {
Mockito.mock(Comparable.class);
}
}
What is the expected output? What do you see instead?
The above test should pass. Instead, it fails with an error from inside
DexMaker:
java.lang.IllegalArgumentException: org.mockito.internal.util.MockitoMock is
not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:111)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:212)
at
com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:
49)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:32)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:55)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
at
com.google.tests.dexmaker.classloader.MockSystemInterface.test(MockSystemInterfa
ce.java:10)
at java.lang.reflect.Method.invokeNative(Native Method)
at
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:55
5)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
What version of the product are you using? On what operating system?
Current build of Mockito and DexMaker; running on emulated Android 4.2. This
does not yet affect released versions of Mockito.
Please provide any additional information below.
Mockito asks that the objects created by DexmakerMockMaker implement this
internal interface MockitoMock, which it subsequently uses to decide whether an
object is a mock or not. This change was made in December 2012, and is not yet
in any released versions Mockito. The change can be found at
https://github.com/mockito/mockito/commit/3738c13b019dcceef42884ea79f09c92b374f0
a1 .
DexmakerMockMaker creates its proxy using the ClassLoader of the Class to be
mocked. In this case, the Class to be mocked uses the system library
ClassLoader, which cannot load application classes.
I'd suggest changing DexmakerMockMaker to use the context ClassLoader instead,
which should normally have access to all the classes that the test case has
access to. I've attached a patch for this, and verified that it fixes this
particular test. However I'm having trouble running the rest of the DexMaker
tests, so I'm not sure if it might break something else.
Original issue reported on code.google.com by [email protected]
on 6 Feb 2013 at 1:59
Attachments:
1. Create a mock of a class (rather than an interface) using Mockito 1.9.5-rc1
+ DexMaker.
2. On the mock, invoke a method that returns a primitive type other than "int".
What is the expected output? What do you see instead?
EXPECTED: The method invocation succeeds and returns either a default value or
the stubbed value (e.g., set using doReturn).
ACTUAL: The method invocation throws ClassCastException: java.lang.Integer
from the byte code generated by DexMaker.
Please use labels and text to provide additional information.
What appears to happen is that org.mockito.invocation.MockHandler provided to
DexMaker's DexmakerMockMaker returns java.lang.Integer for methods that return
primitive types. The byte code generated by Mockito then (correctly) attempts
to convert this result to another class (e.g., java.lang.Long) and this fails.
SAMPLE CODE
public class A {
public long getValue() {
return 1;
}
}
A a = Mockito.mock(A.class);
System.out.println(a.getValue());
Original issue reported on code.google.com by [email protected]
on 28 Jun 2012 at 7:50
What steps will reproduce the problem?
Create a class Foo like this:
public class Foo {
public final String toString() {
return "bar";
}
}
Then (for example), try to do mock(Foo.class) with Mockito.
What is the expected output? What do you see instead?
I expect a mock object that does not mock toString(). Instead, a
java.lang.VirtualMachineError is thrown because the proxy tried to override
toString().
What version of the product are you using? On what operating system?
Latest git, compiled on Linux, running on Android 4.1.1.
Please provide any additional information below.
getMethodsToProxyRecursive() walks the class hierarchy, calling
getMethodsToProxy() for each superclass. So even though getMethodsToProxy()
doesn't add the toString() method from Foo, it finds the non-final version in
Object and adds it.
It seems to me that you could just use Class#getMethods(), rather than
recursively calling Class#getDeclaredMethods() on the inheritance graph.
Original issue reported on code.google.com by [email protected]
on 5 Aug 2012 at 8:16
What steps will reproduce the problem?
1. Install the latest DexMaker, Mockito
2. Write a class under test which has package-private methods, as follows:
----
package com.example.mockitolearning;
public class ClassWithPackagePrivate {
public ClassWithPackagePrivate() {
}
int add(int x, int y) {
return x + y;
}
}
----
3. Write a test code which belongs to the same package as follows
----
package com.example.mockitolearning; // <-- same package as class under test
import static org.mockito.Mockito.*;
import junit.framework.TestCase;
public class ClassWithPackagePrivateTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
}
public void testAdd() {
ClassWithPackagePrivate p = spy(new ClassWithPackagePrivate());
p.add(1, 2);
}
protected void tearDown() throws Exception {
super.tearDown();
}
}
----
What is the expected output? What do you see instead?
Expected: The above test should pass.
Instead: It throws IllegalAccessError. The stack trace is as follows:
----
java.lang.IllegalAccessError: tried to access method
com.example.mockitolearning.ClassWithPackagePrivate.add:(II)I from class
ClassWithPackagePrivate_Proxy
at
ClassWithPackagePrivate_Proxy.super$add$int(ClassWithPackagePrivate_Proxy.genera
ted)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.google.dexmaker.stock.ProxyBuilder.callSuper(ProxyBuilder.java:523)
at
com.google.dexmaker.mockito.InvocationHandlerAdapter$ProxiedMethod.invoke(Invoca
tionHandlerAdapter.java:98)
at
org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.jav
a:108)
at
org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.j
ava:36)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
at
org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:2
9)
at
org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifier
Handler.java:38)
at
com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAda
pter.java:54)
at ClassWithPackagePrivate_Proxy.add(ClassWithPackagePrivate_Proxy.generated)
at
com.example.mockitolearning.ClassWithPackagePrivateTest.testAdd(ClassWithPackage
PrivateTest.java:14)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:55
5)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
----
What version of the product are you using? On what operating system?
Device: Nexus7 2012 with Android 4.2.1.
Jars:
mockito-all-1.9.5.jar
dexmaker-1.0.jar
dexmaker-mockito-1.0.jar
Please provide any additional information below.
- If we don't wrap spy(...), the above test will be passed.
- If we change the modifier of "add(int x, int y)" into "protected", the test
will be passed.
Original issue reported on code.google.com by [email protected]
on 25 Sep 2013 at 11:04
As originally reported by allurefx here:
http://code.google.com/p/mockito/issues/detail?id=308#c71
I'm getting an IllegalArgumentException when running verify() on methods with
no args. Things are OK when there are args (from the
InvocationHandlerAdapter.java source, looks like invoke(Object proxy, Method
method, Object[] args) is getting a null for args). E.g.,
interface Whatever {
void doStuff();
}
public void testWhatever() {
final Whatever whateverMock = mock(Whatever.class);
whateverMock.doStuff();
verify(whateverMock).doStuff();
}
throws:
java.lang.IllegalArgumentException
at com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAdapter.java:49)
at com.sanitas.wellaho.login.$Proxy26.doStuff(Unknown Source)
at com.sanitas.wellaho.login.LoginTest.testWhatever(LoginTest.java:65)
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 junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
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)
Original issue reported on code.google.com by limpbizkit
on 29 Mar 2012 at 10:57
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.