### Question:
TerraformMojo extends AbstractMojo { protected final void execute(TerraformOperation<T> tfOperation, Properties properties) throws MojoExecutionException { try { tfOperation.execute(properties); } catch (TerraformException e) { throw new MojoExecutionException("Failed to execute terraform operation", e); } }    }### Answer:
@Test public void executeOnTerraformOperationWithStringReturnValueWritesToInfoLog() throws TerraformException, MojoFailureException, MojoExecutionException { Mockito.when(terraformOperation.execute(Mockito.any())).thenReturn("Testing!"); TerraformMojo<String> terraformMojo = new TerraformMojo<String>() { @Override @SuppressWarnings("unchecked") public void execute() throws MojoExecutionException, MojoFailureException { execute((TerraformOperation<String>)terraformOperation, properties); } }; terraformMojo.execute(); Mockito.verify(terraformOperation, Mockito.times(1)).execute(properties); }
@Test public void executeOnTerraformOperationDelegatesToTerraformOperation() throws TerraformException, MojoFailureException, MojoExecutionException { Mockito.when(terraformOperation.execute(Mockito.any())).thenReturn(new Object()); TerraformMojo terraformMojo = new TerraformMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { execute(terraformOperation, properties); } }; terraformMojo.execute(); Mockito.verify(terraformOperation, Mockito.times(1)).execute(properties); }
@Test(expected = MojoExecutionException.class) public void terraformExceptionIsThrownAsMojoExecutionException() throws TerraformException, MojoExecutionException, MojoFailureException { Mockito.when(terraformOperation.execute(Mockito.any())).thenThrow(new TerraformException("boom!")); TerraformMojo terraformMojo = new TerraformMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { execute(terraformOperation, properties); } }; terraformMojo.execute(); }