### Question:
JpaColumnStorage implements ColumnStorage { @Override public void storeWithTransaction(Column column) { try { persistenceManager.transaction(); final String sensorName = column.getSensor().getName(); final Sensor sensor = (Sensor) persistenceManager.pick("select s from Sensor s where s.name = ?1", sensorName); column.setSensor(sensor); store(column); persistenceManager.commit(); } catch (Exception e) { e.printStackTrace(); persistenceManager.rollback(); throw new ToolException("Database error", e, ToolException.TOOL_DB_ERROR); } } JpaColumnStorage(PersistenceManager persistenceManager); @Override Column getColumn(String columnName); @SuppressWarnings("unchecked") @Override List<Item> getAllColumns(); @Override List<Item> getAllColumnsWithTransaction(); @SuppressWarnings("unchecked") @Override List<String> getAllColumnNames(); @Override List<String> getAllColumnNamesWithTransaction(); void store(Column column); @Override void storeWithTransaction(Column column); @Override void deleteAll();  }### Answer:
@Test public void testStoreColumnWithTransaction() { final Sensor sensor = new SensorBuilder().name("gnatz").build(); final Column column = (Column) new ColumnBuilder().name("Schneckchen").sensor(sensor).build(); columnStorage.storeWithTransaction(column); verify(persistenceManager, times(1)).transaction(); verify(persistenceManager, times(1)).persist(column); verify(persistenceManager, times(1)). pick("select s from Sensor s where s.name = ?1", "gnatz"); verify(persistenceManager, times(1)).commit(); verifyNoMoreInteractions(persistenceManager); }
@Test public void testStoreColumnWithTransaction_failure() { final Sensor sensor = new SensorBuilder().name("bah").build(); final Column column = (Column) new ColumnBuilder().name("Gansta-Rapper").sensor(sensor).build(); doThrow(new PersistenceException(null, null, null, true)).when(persistenceManager).persist(column); try { columnStorage.storeWithTransaction(column); fail("ToolException expected"); } catch (ToolException expected) { } verify(persistenceManager, times(1)).transaction(); verify(persistenceManager, times(1)).persist(column); verify(persistenceManager, times(1)). pick("select s from Sensor s where s.name = ?1", "bah"); verify(persistenceManager, times(1)).rollback(); verifyNoMoreInteractions(persistenceManager); }