### Question:
JpaColumnStorage implements ColumnStorage { @Override public List<Item> getAllColumnsWithTransaction() { try { persistenceManager.transaction(); final List<Item> allColumns = getAllColumns(); persistenceManager.commit(); return allColumns; } catch (Exception e) { 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 testGetAllColumnsWithTransaction() { final String sql = "select c from Column c order by c.name"; final List<Column> columnList = new ArrayList<>(); columnList.add((Column) new ColumnBuilder().name("test_me").build()); final Query query = mock(Query.class); when(persistenceManager.createQuery(sql)).thenReturn(query); when(query.getResultList()).thenReturn(columnList); final List<? extends Item> allColumns = columnStorage.getAllColumnsWithTransaction(); assertNotNull(allColumns); assertEquals(1, allColumns.size()); assertEquals("test_me", allColumns.get(0).getName()); verify(persistenceManager, times(1)).transaction(); verify(persistenceManager, times(1)).createQuery(sql); verify(persistenceManager, times(1)).commit(); verifyNoMoreInteractions(persistenceManager); verify(query, times(1)).getResultList(); verifyNoMoreInteractions(query); }
@Test public void testGetAllColumnsWithTransaction_fails() { final String sql = "select c from Column c order by c.name"; final Query query = mock(Query.class); when(persistenceManager.createQuery(sql)).thenReturn(query); doThrow(new PersistenceException(null, null, null, true)).when(query).getResultList(); try { columnStorage.getAllColumnsWithTransaction(); fail("ToolException expected"); } catch (ToolException expected) { } verify(persistenceManager, times(1)).transaction(); verify(persistenceManager, times(1)).createQuery(sql); verifyNoMoreInteractions(persistenceManager); verify(query, times(1)).getResultList(); verifyNoMoreInteractions(query); }