HsqlDatabaseManagerSwingTask extends Task { @Override public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception { Preconditions.checkState(ok, "Registered without calling shouldRegister() or when returned false"); execution.run(); } HsqlDatabaseManagerSwingTask(String url); @Override void execute(ImmutableMultimap<String, String> parameters, PrintWriter output); boolean shouldRegister(Map<String, String> properties);  }
@Test public void whenExecuteValidItShouldRunExecution() throws Exception { task = new HsqlDatabaseManagerSwingTask(URL_HSQLDB); task.execution = mock(Runnable.class); task.ok = true; task.execute(mock(ImmutableMultimap.class), mock(PrintWriter.class)); verify(task.execution).run(); }
@Test public void whenExecuteInvalidItShouldThrow() throws Exception { task = new HsqlDatabaseManagerSwingTask(URL_HSQLDB); task.execution = mock(Runnable.class); task.ok = false; try { task.execute(mock(ImmutableMultimap.class), mock(PrintWriter.class)); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException e) { verify(task.execution, never()).run(); } }