@Test public void itGetsEntitiesById() throws Exception { when(session.get(String.class, 200)).thenReturn("woo!"); assertThat(dao.getInstance(200), is("woo!")); verify(session).get(String.class, 200); }
@Test public void itReturnsUniqueListsFromQueries() throws Exception { when(query.list()).thenReturn(ImmutableList.of("woo")); assertThat(dao.getListFromQuery("query-name"), is((List<String>) ImmutableList.of("woo"))); verify(session).getNamedQuery("query-name"); verify(query).list(); }
@Test public void itReturnsUniqueListsFromCriteriaQueries() throws Exception { when(critera.list()).thenReturn(ImmutableList.of("woo")); assertThat(dao.getListFromCriteria(), is((List<String>) ImmutableList.of("woo"))); verify(session).createCriteria(String.class); verify(critera).list(); }
@Test public void itReturnsUniqueResultsFromQueries() throws Exception { when(query.uniqueResult()).thenReturn("woo"); assertThat(dao.getUniqueResultFromQuery("query-name"), is("woo")); verify(session).getNamedQuery("query-name"); verify(query).uniqueResult(); }
@Test public void itReturnsUniqueResultsFromCriteriaQueries() throws Exception { when(critera.uniqueResult()).thenReturn("woo"); assertThat(dao.getUniqueResultFromCriteria(), is("woo")); verify(session).createCriteria(String.class); verify(critera).uniqueResult(); }
@Test public void itHasAnEntityClass() throws Exception { assertThat(dao.getEntityClass(), is(sameInstance(String.class))); }
@Test public void itGetsASessionFromTheInjectedProvider() throws Exception { assertThat(dao.getSession(), is(sameInstance(session))); }
@Test public void itPersistsEntities() throws Exception { assertThat(dao.save("woo"), is("woo")); verify(session).saveOrUpdate("woo"); }
@Test public void itCreatesNewCriteraQueries() throws Exception { assertThat(dao.getCriteria(), is(critera)); verify(session).createCriteria(String.class); }
@Test public void itGetsNamedQueries() throws Exception { assertThat(dao.getNamedQuery("query-name"), is(query)); verify(session).getNamedQuery("query-name"); }