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

Mocks not initialised correctly #89

Open
nmihalek opened this issue Dec 19, 2018 · 1 comment
Open

Mocks not initialised correctly #89

nmihalek opened this issue Dec 19, 2018 · 1 comment

Comments

@nmihalek
Copy link

Hi, first off I like your library and I find it quite useful, great job!

I have found a small bug, which has a workaround but is quite odd.

When using the library with Espresso tests, mocking methods will not work if only doAnswer(...) is used.
This applies to the mocks which are injected by Dagger.
So for example in this instance the code inside doAnswer will not be executed:

@Mock
Parser injectable;

@Test
void test() {
	doAnswer(invocation -> /*some code*/)
		.when(injectable).parse(any());

	Robolectric.setupActivity().get();
}

But if we have a simple when on the same mock, everything will work as expected:

@Mock
Parser injectable;

@Test
void test() {
	doAnswer(invocation -> /*some code*/)
		.when(injectable).parse(any());
	when(injectable.getConfig()).thenReturn("");
	
	Robolectric.setupActivity().get();
}

Any idea what is happening, and if this is a known issue?

Thanks in advance!

@fabioCollini
Copy link
Owner

Hi, I have never seen a problem like this and I can't think of any reason why it should happen :(
It's just another way of defining the mock, it shouldn't change the behaviour.
Do this always happen? Are you using Robolectric?
Thanks for your report

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

No branches or pull requests

2 participants