### Question:
DefaultWriter extends BaseNeo4jWriter { @Override public <T> T write(Callable<T> task, String id, int waitMillis) { T result; try (Transaction tx = database.beginTx()) { result = task.call(); tx.success(); } catch (Exception e) { LOG.warn("Execution threw and exception.", e); if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException(e); } return result; } DefaultWriter(GraphDatabaseService database); @Override T write(Callable<T> task, String id, int waitMillis);  }### Answer:
@Test public void shouldExecuteRunnable() { writer.write(new Runnable() { @Override public void run() { getDatabase().createNode(); } }); try (Transaction tx = getDatabase().beginTx()) { assertEquals(1, IterableUtils.countNodes(getDatabase())); tx.success(); } }
@Test public void shouldWaitForResult() { Boolean result = writer.write(new Callable<Boolean>() { @Override public Boolean call() throws Exception { getDatabase().createNode(); return true; } }, "test", 50); assertTrue(result); try (Transaction tx = getDatabase().beginTx()) { assertEquals(1, IterableUtils.countNodes(getDatabase())); tx.success(); } }
@Test(expected = RuntimeException.class) public void runtimeExceptionFromTaskGetsPropagated() { writer.write(new Callable<Boolean>() { @Override public Boolean call() throws Exception { throw new RuntimeException("Deliberate Testing Exception"); } }, "test", 50); }
@Test(expected = RuntimeException.class) public void checkedExceptionFromTaskGetsTranslated() { writer.write(new Callable<Boolean>() { @Override public Boolean call() throws Exception { throw new IOException("Deliberate Testing Exception"); } }, "test", 10); }