Skip to content

Instantly share code, notes, and snippets.

@sebastianbenz
Created June 4, 2012 18:15
Show Gist options
  • Save sebastianbenz/2869959 to your computer and use it in GitHub Desktop.
Save sebastianbenz/2869959 to your computer and use it in GitHub Desktop.
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