Skip to content

Instantly share code, notes, and snippets.

@jeriley
Created October 24, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeriley/b85cb1c7bf80bf3760caf8103c696614 to your computer and use it in GitHub Desktop.
Save jeriley/b85cb1c7bf80bf3760caf8103c696614 to your computer and use it in GitHub Desktop.
@RunWith(MockitoJunitRunner.class)
//@ContextConfiguration({"/stuff.xml"})
public class SomeDaoTest {
@Mock
private SessionFactory factory;
@Mock
private Session session;
@Mock
private SQLQuery query;
@InjectMocks
private SomeDao dao = new new SomeDao();
ArgumentCaptor<String> theActualQuery = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> passedId = ArgumentCaptor.forClass(String.class);
@Before
public void setup(){
Mockito.when(factory.getCurrentSession()).thenReturn(session);
Mockito.when(session.createSQLQuery(theActualQuery.capture())).thenReturn(query);
dao.DoThatThing();
//grab the int
}
@Test
public void thisIsTheQuery(){
String exepectedQuery = "select id where zipcode ='10000'"
assert(expectedQuery, theActualQuery.getValue());
}
@Test
public void itCalledItOnce(){
verify(dao, Mockito.times(1)).DoThatThing(any(String.class));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment