Created
June 4, 2012 18:15
-
-
Save sebastianbenz/2869959 to your computer and use it in GitHub Desktop.
Using Mockito in Jnario
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 demo | |
import static org.mockito.Mockito.* | |
import static org.mockito.MockitoAnnotations.* | |
import java.util.List | |
import org.mockito.Mock | |
import org.jnario.runner.CreateWith | |
describe "Mockito"{ | |
describe "standard"{ | |
val mock = mock(typeof(List)) | |
fact mock should not be null | |
} | |
describe "annotation"{ | |
@Mock List mock | |
before initMocks(this) | |
fact mock should not be null | |
} | |
@CreateWith(typeof(MockitoInstantiator)) | |
describe "instantiator"{ | |
@Mock List mock | |
fact mock should not be null | |
} | |
} |
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 demo; | |
import org.jnario.runner.SimpleSpecCreator; | |
import org.mockito.MockitoAnnotations; | |
public class MockitoInstantiator extends SimpleSpecCreator { | |
@Override | |
public <T> T createSpec(Class<T> klass) { | |
T test = super.createSpec(klass); | |
MockitoAnnotations.initMocks(test); | |
return test; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment