### Question:
JpaEventRepository implements EventRepository { @Override public Event getEvent(long eventId) { Event event; Session session = getSession(); try { event = (Event) session.get(Event.class, eventId); } finally { session.close(); LOG.debug("Database session closed: " + session); } return event; } @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 callsSessionSetDefaultReadOnlyWithTrue() { context.checking(new Expectations() {{ oneOf(sessionFactory).openSession(); will(returnValue(session)); oneOf(session).setDefaultReadOnly(true); oneOf(session).get(Event.class, 1L); will(returnValue(null)); oneOf(session).close(); }}); eventRepository = new JpaEventRepository(sessionFactory, true); eventRepository.getEvent(1); context.assertIsSatisfied(); }
@Test public void callsSessionSetDefaultReadOnlyWithFalse() { context.checking(new Expectations() {{ oneOf(sessionFactory).openSession(); will(returnValue(session)); never(session).setDefaultReadOnly(true); oneOf(session).get(Event.class, 1L); will(returnValue(null)); oneOf(session).close(); }}); eventRepository = new JpaEventRepository(sessionFactory, false); eventRepository.getEvent(1); context.assertIsSatisfied(); }