Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Calling constructor for MockUp in Test results in java.lang.VerifyError for 1.9 #25

Closed
abc2mit opened this issue Aug 4, 2014 · 1 comment
Assignees
Labels
bug

Comments

@abc2mit
Copy link

@abc2mit abc2mit commented Aug 4, 2014

Issue:
I have a mock class that extends MockUp. When running tests in JMockIt 1.9, the tests fail with java.lang.VerifyError. This is through Maven on OSX.

$ mvn --version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T09:37:52-08:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8

OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"

I rolled back JMockIt to 1.8 and the tests passed again. Also, tests seem to work in IntelliJ on 1.9 with standard configuration run. Code is below.

Created a mock class that mocks org.mongojack.DBCursor

import mockit.Mock;
import mockit.MockUp;
import org.mongojack.DBCursor;
import org.mongojack.JacksonDBCollection;

import java.util.List;

public class DBCursorMock<T> extends MockUp<DBCursor<T>> {
    private List<T> items = null;

    public DBCursorMock (List<T> items) {
        this.items = items;
    }

    @Mock
    public void $init (JacksonDBCollection<T, ?> jacksonDBCollection,
                       com.mongodb.DBCursor cursor) {

    }

    @Mock
    public List<T> toArray () {
        return items;
    }
}

Class is called in test like so:

    JacksonDBCollectionMock<User, ObjectId> collection = new JacksonDBCollectionMock<>();
    collection.setDBObjectItems(userList);
    new DBCursorMock<>(userList);

(Note: JacksonDBCollectionMock is another mock that does not have an $init method.)

Stack trace:

testGetPasscode(net.foodjudge.apiserver.db.DeviceAtomicsTest)  Time elapsed: 0.02 sec  <<< ERROR!
java.lang.VerifyError
    at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
    at net.foodjudge.mock.DBCursorMock.<init>(DBCursorMock.java:20)
    at net.foodjudge.apiserver.db.DeviceAtomicsTest.testGetPasscode(DeviceAtomicsTest.java:127)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
@rliesenfeld rliesenfeld self-assigned this Aug 4, 2014
@rliesenfeld rliesenfeld added the bug label Aug 4, 2014
@abc2mit

This comment has been minimized.

Copy link
Author

@abc2mit abc2mit commented Aug 12, 2014

That's awesome! Thanks @rliesenfeld for fixing it so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.