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

spy() serializable support #537

Open
2 of 5 tasks
miaekim opened this issue Aug 8, 2016 · 5 comments
Open
2 of 5 tasks

spy() serializable support #537

miaekim opened this issue Aug 8, 2016 · 5 comments

Comments

@miaekim
Copy link

miaekim commented Aug 8, 2016

check that

  • The mockito message in the stacktrace have useful information, but it didn't help
  • The problematic code (if that's possible) is copied here;
    Note that some configuration are impossible to mock via Mockito
  • Provide versions (mockito / jdk / os / any other relevant information)
  • Provide a Short, Self Contained, Correct (Compilable), Example of the issue
    (same as any question on stackoverflow.com)
  • Read the contributing guide

This is an issue for the latest version. Support serializable() for the mock() is a great feature!
According to the source code. spy also uses mock()
Why don't you support mockSetting argument for spy() like below code snippet? Is there any problem when it comes to call .serializable() with .spiedInstance()

    public static <T> T spy(T object, MockSettings mockSettings) {
        return MOCKITO_CORE.mock((Class<T>) object.getClass(), mockSettings.withSettings()
                .spiedInstance(object)
                .defaultAnswer(CALLS_REAL_METHODS));
    }

val spyMyObject = spy(myObject, witSettings.serializable())
@bric3
Copy link
Contributor

bric3 commented Aug 13, 2016

Interesting idea.

@sanjutoyou
Copy link

Its a much needed feature for classes using spark and other related frameworks.

@LouHubiao
Copy link

mock(class,
withSettings()
.serializable()
.spiedInstance(object)
.defaultAnswer(CALLS_REAL_METHODS));

@paweljanikowski
Copy link

I have faced the same situation.
We need serializable spy!

@eximius313
Copy link

Dear @bric3,
I think that if the subject of spy or mock method implements Serializable, then Mockito should return serializable instance with no exceptions and current behavior should be treated as a bug!

While this:

mock(class,
withSettings()
.serializable()
.spiedInstance(object)
.defaultAnswer(CALLS_REAL_METHODS));

indeed works, it should be treated only as a workaround until the framework fixes it's behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants