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

import static com.codeaffine.eclipse.core.runtime.Predicates.attribute;
import static com.codeaffine.extras.jdt.internal.junitstatus.JUnitStatusBarPreferencePage.ID;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.function.Predicate;

import org.eclipse.jface.preference.IPreferenceStore;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.codeaffine.eclipse.core.runtime.Extension;
import com.codeaffine.eclipse.core.runtime.RegistryAdapter;
import com.codeaffine.eclipse.core.runtime.test.util.ExtensionAssert;
import com.codeaffine.extras.jdt.internal.JDTExtrasPlugin;

public class JUnitStatusBarPreferencePagePDETest {

  private JUnitStatusBarPreferencePage preferencePage;

  @Before
  public void setUp() {
    preferencePage = new JUnitStatusBarPreferencePage();
  }

  @After
  public void tearDown() {
    preferencePage.dispose();
  }

  @Test
  public void testExtension() {
    Extension actual = readPreferencePageExtension();

    ExtensionAssert.assertThat( actual )
      .hasAttributeValue( "category", "org.eclipse.jdt.junit.preferences" )
      .hasAttributeValue( "class", JUnitStatusBarPreferencePage.class.getName() )
      .hasChildWithAttributeValue( "id", "org.eclipse.jdt.junit.JUnit" )
      .hasNonEmptyAttributeValueFor( "name" )
      .isInstantiable( JUnitStatusBarPreferencePage.class );
  }

  @Test
  public void testDoGetPreferenceStore() {
    IPreferenceStore preferenceStore = preferencePage.doGetPreferenceStore();

    assertThat( preferenceStore ).isEqualTo( JDTExtrasPlugin.getInstance().getPreferenceStore() );
  }

  @Test
  public void testGetTitle() {
    String title = preferencePage.getTitle();

    assertThat( title ).isNotEmpty();
  }

  private static Extension readPreferencePageExtension() {
    return readExtension( "org.eclipse.ui.preferencePages", attribute( "id", ID ) );
  }

  private static Extension readExtension( String extensionPoint, Predicate<Extension> predicate ) {
    return new RegistryAdapter().readExtension( extensionPoint ).thatMatches( predicate ).process();
  }
}

@@ -736,16 +736,97 @@
 Test %7B%0A%0A
+  private static final String JUNIT_KEYWORD_ID = %22org.eclipse.jdt.junit.JUnit%22;%0A%0A
   privat
@@ -1379,37 +1379,24 @@
 d%22, 
-%22org.eclipse.jdt.junit.JUnit%22
+JUNIT_KEYWORD_ID
  )%0A 
@@ -1436,24 +1436,24 @@
 r( %22name%22 )%0A
-
       .isIns
@@ -1498,32 +1498,243 @@
 e.class );%0A  %7D%0A%0A
+  @Test%0A  public void testExtensionKeywordReferences() %7B%0A    Extension extension = readExtension( %22org.eclipse.ui.keywords%22, attribute( %22id%22, JUNIT_KEYWORD_ID ) );%0A%0A    assertThat( extension ).isNotNull();%0A  %7D%0A%0A
   @Test%0A  public

Add test to verify referenced keyword