### Question:
JpaEventRepository implements EventRepository { @Override public List<String> getEventTypes() { Session session = getSession(); List events = null; try { Query query = session.createQuery("SELECT DISTINCT e.class AS c FROM Event e WHERE e.suppressed=false ORDER BY c"); events = query.list(); } finally { session.close(); LOG.debug("Database session closed: " + session); } return events; } @Inject  JpaEventRepository(SessionFactory sessionFactory, boolean readonly); @Override List<String> getEventTypes(); @Override void save(Event event); @Override Event getEvent(long eventId); @Override List<Event> findEventsByFromAndToAndTypeAndVesselAndArea(Date from, Date to, String type, String vessel, Double north, Double east, Double south, Double west); @Override List<Event> findEventsByFromAndTo(Date from, Date to); @Override List<Event> findRecentEvents(int numberOfEvents); @Override T findOngoingEventByVessel(int mmsi, Class<T> eventClass);  }### Answer:
@Test public void testGetEventTypes() { final ArgumentCaptor<String> queryString = ArgumentCaptor.forClass(String.class); context.checking(new Expectations() {{ oneOf(sessionFactory).openSession(); will(returnValue(session)); oneOf(session).createQuery(with(queryString.getMatcher())); will(returnValue(query)); oneOf(query).list(); oneOf(session).close(); }}); eventRepository.getEventTypes(); assertTrue(queryString.getCapturedObject().toString().matches("SELECT DISTINCT e.class AS c FROM Event e WHERE e.suppressed=false ORDER BY c")); context.assertIsSatisfied(); }