### Question:
JpaColumnStorage implements ColumnStorage { @Override public List<String> getAllColumnNamesWithTransaction() { try { persistenceManager.transaction(); final List<String> columnNames = getAllColumnNames(); persistenceManager.commit(); return columnNames; } 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 testGetAllColumnNamesWithTransaction() { final String sql = "select c.name from Column c"; final List<String> columnNameList = new ArrayList<>(); columnNameList.add("Johanna"); columnNameList.add("Uwe"); final Query query = mock(Query.class); when(persistenceManager.createQuery(sql)).thenReturn(query); when(query.getResultList()).thenReturn(columnNameList); final List<String> namesFromStorage = columnStorage.getAllColumnNamesWithTransaction(); assertNotNull(namesFromStorage); 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 testGetAllColumnNamesWithTransaction_failure() { final String sql = "select c.name from Column c"; final Query query = mock(Query.class); when(persistenceManager.createQuery(sql)).thenReturn(query); doThrow(new PersistenceException(null, null, null, true)).when(query).getResultList(); try { columnStorage.getAllColumnNamesWithTransaction(); 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); }