DataAccess { public RegistrationRecord fetchByUserName(String name, final boolean onlyValidated) { name = name == null ? "" : name.trim(); if(name.isEmpty()) { logger.severe(String.format("Fetching by name, but empty name [%s]", name)); throw new IllegalArgumentException("name cannot be null"); } String sql = "select * from mobile.user_phone_binding where user_id = ?"; if (onlyValidated) { sql += " and in_validation = false"; } try { return dataAccess.queryForObject(sql, new RowMapper<RegistrationRecord>() { public RegistrationRecord mapRow(ResultSet rs, int rowNum) throws SQLException { return new RegistrationRecord( rs.getInt("pkey"), rs.getString("user_id"), rs.getString("phone_number"), rs.getString("validation_code"), rs.getBoolean("in_validation") ); } }, name); } catch(EmptyResultDataAccessException e) { return null; } } DataAccess(final JdbcTemplate t); void update(final RegistrationRecord toUpdate); RegistrationRecord fetchByUserName(String name, final boolean onlyValidated);  }
@Test public void testNoSuchRow() { DataAccess d = new DataAccess(getTemplate()); RegistrationRecord r = d.fetchByUserName("no such user", false); assertNull(r); }