Created
October 24, 2019 15:41
-
-
Save jeriley/b85cb1c7bf80bf3760caf8103c696614 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
@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