Create a gist now

Instantly share code, notes, and snippets.

Using Mockito in Jnario
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
}
}
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