SqlReporter implements Reporter { @Override public void store(Report report) { Session session = sessionFactory.openSession(); session.beginTransaction(); session.save(new SqlReport(report)); session.getTransaction().commit(); session.close(); } SqlReporter(SessionFactory sessionFactory); @Override void store(Report report); @Override Report[] retrieve(ReportQuery query);  }
@Test public void testStore() throws ClassNotFoundException, SQLException { Request req = new Request("What is today's date?", "abcdef"); Agent agent = mock(Agent.class); when(agent.getName()).thenReturn("date"); Report r = new Report(req); Date d = new Date(); r.setTimestamp(d); r.setAgent(agent); r.setRouteTime(30, 47); r.setAgentTime(78, 450000); r.setResponse(new Response("yesterday")); Reporter reporter = new SqlReporter(sessionFactory); reporter.store(r); Class.forName("org.h2.Driver"); Connection conn = DriverManager.getConnection("jdbc:h2:mem:sql_reporter"); String selectQuery = "SELECT * FROM report"; PreparedStatement stmt = conn.prepareStatement(selectQuery); ResultSet rs = stmt.executeQuery(); rs.next(); assertEquals(d, rs.getTimestamp("timestamp")); assertEquals("date", rs.getString("agentName")); assertEquals("abcdef", rs.getString("requestId")); assertEquals("What is today's date?", rs.getString("requestText")); assertEquals("yesterday", rs.getString("responseText")); assertEquals(ResponseStatus.Code.SUCCESS.getValue(), rs.getInt("responseCode")); assertEquals(17, rs.getLong("routeTime")); assertEquals(449922, rs.getLong("agentTime")); assertFalse(rs.next()); stmt.close(); conn.close(); }