Created
April 11, 2012 07:49
-
-
Save clakech/2357686 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bla.web.controller; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mock; | |
import org.mockito.Spy; | |
import org.mockito.runners.MockitoJUnitRunner; | |
import com.bla.web.dto.FamilyAndItems; | |
import com.bla.web.service.FamilyServiceImpl; | |
import static org.mockito.BDDMockito.given; | |
import static org.mockito.Matchers.anyString; | |
import static org.fest.assertions.Assertions.assertThat; | |
@RunWith(MockitoJUnitRunner.class) | |
public class SpyAndMockFailTest { | |
@Mock | |
FamilyServiceImpl familyService; | |
@Spy | |
FamilyController familyController = new FamilyController(familyService); | |
@Test | |
public void shouldGetFamilyAndItems() { | |
// given | |
given(familyService.getFamilyAndItems(anyString())).willReturn(null); | |
// when | |
FamilyAndItems familyAndItems = familyController.getFamilyAndItems("id"); | |
// then | |
assertThat(familyAndItems).isEqualTo(null); | |
} | |
} |
Oh really... sh**! Tks btw
You can use Annotations together introducing @Injectmocks (see my fork : https://gist.github.com/2358140)
documentation of @Injectmocks and the way it injects @Mocks into @SPY objets or not-mockito objects http://docs.mockito.googlecode.com/hg/1.9.0/org/mockito/InjectMocks.html
Sounds great, Thank you !
I didn't know I can use those 2 annotations on the same object.
Regards,
Cyril Lakech
2012/4/11 Ludovic Meurillon <
[email protected]
… You can use Annotations together introducing @Injectmocks (see my fork :
https://gist.github.com/2358140)
documentation of @Injectmocks and the way it inject @Mocks into @SPY or
not-mockito objects
http://docs.mockito.googlecode.com/hg/1.9.0/org/mockito/InjectMocks.html
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2357686
Good to know indeed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is probably a matter of fields ordering in compiled class ; I've observed subtle changes on that topic since jdk7