package com.codeaffine.extras.jdt.internal.prefs;

import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.services.IEvaluationService;
import org.junit.Before;
import org.junit.Test;

public class ExpressionEvaluatorTest {

  private IWorkbench workbench;

  @Before
  public void setUp() {
    workbench = mock( IWorkbench.class );
  }

  @Test
  public void testEvaluate() {
    IEvaluationService evaluationService = mock( IEvaluationService.class );
    when( workbench.getService( IEvaluationService.class ) ).thenReturn( evaluationService );

    new ExpressionEvaluator( workbench ).evaluate();

    verify( evaluationService ).requestEvaluation( PreferencePropertyTester.PROP_IS_TRUE );
  }

  @Test
  public void testEvaluateWithNullworkbench() {
    try {
      new ExpressionEvaluator( null ).evaluate();
    } catch( RuntimeException notExpected ) {
      fail();
    }
  }

  @Test
  public void testEvaluateWithoutEvaluationService() {
    new ExpressionEvaluator( workbench ).evaluate();

    verify( workbench ).getService( IEvaluationService.class );
  }

}

@@ -62,29 +62,120 @@
 tic 
-org.junit.Assert.fail
+com.codeaffine.test.util.lang.ThrowableCaptor.thrownBy;%0Aimport static org.assertj.core.api.Assertions.assertThat
 ;%0Aim
@@ -987,17 +987,17 @@
 WithNull
-w
+W
 orkbench
@@ -1009,19 +1009,45 @@
     
-try %7B%0A     
+Throwable throwable = thrownBy( () -%3E
  new
@@ -1089,75 +1089,50 @@
 te()
-;
+ );%0A
 %0A    
-%7D catch( RuntimeException notExpected ) %7B%0A      fail();%0A    %7D
+assertThat( throwable ).isNull();
 %0A  %7D

Rewrite test to use ThrowableCaptor