<commit_before>package com.codeaffine.extras.jdt.internal.junitstatus;

import static com.codeaffine.extras.jdt.internal.prefs.PreferencePropertyTester.PROP_IS_TRUE;
import static com.codeaffine.extras.jdt.internal.prefs.WorkspaceScopePreferences.PREF_SHOW_JUNIT_STATUS_BAR;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collection;

import org.junit.Test;

import com.codeaffine.eclipse.core.runtime.Extension;
import com.codeaffine.eclipse.core.runtime.Predicate;
import com.codeaffine.eclipse.core.runtime.RegistryAdapter;

public class JUnitStatusContributionItemPDETest {

  private static final String LOCATION
    = "toolbar:org.eclipse.ui.trim.status";

  @Test
  public void testExtension() {
    Extension extension = new RegistryAdapter()
      .readExtension( "org.eclipse.ui.menus" )
      .thatMatches( new LocationUriPredicate() )
      .process();

    Extension toolbarElement = getToolBarElement( extension );
    Extension controlElement = getControlElement( extension );
    Extension visibleWhenElement = getVisibleWhenElement( extension );
    Extension visibleTestElement = getVisibleTestElement( extension );
    assertThat( extension.getChildren( "toolbar" ) ).hasSize( 1 );
    assertThat( toolbarElement.getChildren( "control" ) ).hasSize( 1 );
    assertThat( toolbarElement.getAttribute( "label" ) ).isEqualTo( "JUnit" );
    assertThat( controlElement.getAttribute( "id" ) ).isNotNull();
    assertThat( controlElement.createExecutableExtension( JUnitStatusContributionItem.class ) ).isNotNull();
    assertThat( visibleWhenElement.getAttribute( "checkEnabled" ) ).isEqualTo( "false" );
    assertThat( visibleTestElement.getAttribute( "args" ) ).isEqualTo( PREF_SHOW_JUNIT_STATUS_BAR );
    assertThat( visibleTestElement.getAttribute( "forcePluginActivation" ) ).isEqualTo( "true" );
    assertThat( visibleTestElement.getAttribute( "property" ) ).isEqualTo( PROP_IS_TRUE );
    assertThat( visibleTestElement.getAttribute( "value" ) ).isEqualTo( "true" );
  }

  private static Extension getControlElement( Extension extension ) {
    return getFirst( getToolBarElement( extension ).getChildren( "control" ) );
  }

  private static Extension getToolBarElement( Extension extension ) {
    return getFirst( extension.getChildren( "toolbar" ) );
  }

  private static Extension getVisibleWhenElement( Extension extension ) {
    return getFirst( getControlElement( extension ).getChildren( "visibleWhen" ) );
  }

  private static Extension getVisibleTestElement( Extension extension ) {
    Extension withElement = getFirst( getVisibleWhenElement( extension ).getChildren( "with" ) );
    return getFirst( withElement.getChildren( "test" ) );
  }

  private static <T> T getFirst( Collection<T> collection ) {
    return collection.stream().findFirst().orElse( null );
  }

  private static class LocationUriPredicate implements Predicate {
    @Override
    public boolean apply( Extension input ) {
      String attribute = input.getAttribute( "locationURI" );
      return LOCATION.equals( attribute );
    }
  }
}<commit_msg>Fix: test fails when similar but unrelated extensions present<commit_after>package com.codeaffine.extras.jdt.internal.junitstatus;

import static com.codeaffine.extras.jdt.internal.prefs.PreferencePropertyTester.PROP_IS_TRUE;
import static com.codeaffine.extras.jdt.internal.prefs.WorkspaceScopePreferences.PREF_SHOW_JUNIT_STATUS_BAR;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collection;

import org.junit.Test;

import com.codeaffine.eclipse.core.runtime.Extension;
import com.codeaffine.eclipse.core.runtime.Predicate;
import com.codeaffine.eclipse.core.runtime.RegistryAdapter;

public class JUnitStatusContributionItemPDETest {

  private static final String LOCATION = "toolbar:org.eclipse.ui.trim.status";
  private static final String TOOL_BAR_ID = "com.codeaffine.extras.jdt.internal.JUnitStatusToolBar";

  @Test
  public void testExtension() {
    Extension extension = new RegistryAdapter()
      .readExtension( "org.eclipse.ui.menus" )
      .thatMatches( new JUnitStatusBarPredicate() )
      .process();

    Extension toolbarElement = getToolBarElement( extension );
    Extension controlElement = getControlElement( extension );
    Extension visibleWhenElement = getVisibleWhenElement( extension );
    Extension visibleTestElement = getVisibleTestElement( extension );
    assertThat( extension.getChildren( "toolbar" ) ).hasSize( 1 );
    assertThat( toolbarElement.getChildren( "control" ) ).hasSize( 1 );
    assertThat( toolbarElement.getAttribute( "label" ) ).isEqualTo( "JUnit" );
    assertThat( controlElement.getAttribute( "id" ) ).isNotNull();
    assertThat( controlElement.createExecutableExtension( JUnitStatusContributionItem.class ) ).isNotNull();
    assertThat( visibleWhenElement.getAttribute( "checkEnabled" ) ).isEqualTo( "false" );
    assertThat( visibleTestElement.getAttribute( "args" ) ).isEqualTo( PREF_SHOW_JUNIT_STATUS_BAR );
    assertThat( visibleTestElement.getAttribute( "forcePluginActivation" ) ).isEqualTo( "true" );
    assertThat( visibleTestElement.getAttribute( "property" ) ).isEqualTo( PROP_IS_TRUE );
    assertThat( visibleTestElement.getAttribute( "value" ) ).isEqualTo( "true" );
  }

  private static Extension getControlElement( Extension extension ) {
    return getFirst( getToolBarElement( extension ).getChildren( "control" ) );
  }

  private static Extension getToolBarElement( Extension extension ) {
    return getFirst( extension.getChildren( "toolbar" ) );
  }

  private static Extension getVisibleWhenElement( Extension extension ) {
    return getFirst( getControlElement( extension ).getChildren( "visibleWhen" ) );
  }

  private static Extension getVisibleTestElement( Extension extension ) {
    Extension withElement = getFirst( getVisibleWhenElement( extension ).getChildren( "with" ) );
    return getFirst( withElement.getChildren( "test" ) );
  }

  private static <T> T getFirst( Collection<T> collection ) {
    return collection.stream().findFirst().orElse( null );
  }

  private static class JUnitStatusBarPredicate implements Predicate {
    @Override
    public boolean apply( Extension input ) {
      return isToolBarContribution( input ) && containsJUnitSttausBar( input );
    }

    private static boolean isToolBarContribution( Extension extension ) {
      return LOCATION.equals( extension.getAttribute( "locationURI" ) );
    }

    private static boolean containsJUnitSttausBar( Extension extension ) {
      Collection<Extension> toolBars = extension.getChildren( "toolbar" );
      return toolBars.stream().anyMatch( element -> TOOL_BAR_ID.equals( getId( element ) ) );
    }

    private static String getId( Extension element ) {
      return element.getAttribute( "id" );
    }
  }

}
{'fraction_non_alphanumeric': 0.1029174607828764, 'fraction_numerical': 0.0005864242779651077, 'mean_word_length': 4.911611785095321, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5942067', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1871, 'n_words': 423}