<commit_before>package com.codeaffine.extras.launch.internal.dialog;

import static com.codeaffine.extras.launch.internal.dialog.LaunchConfigLabelProvider.LabelMode.DETAIL;
import static com.codeaffine.extras.launch.internal.dialog.LaunchConfigLabelProvider.LabelMode.LIST;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.codeaffine.eclipse.swt.test.util.DisplayHelper;
import com.codeaffine.extras.launch.internal.dialog.LaunchConfigLabelProvider.LabelMode;
import com.codeaffine.extras.launch.test.LaunchConfigRule;
import com.codeaffine.extras.test.util.ProjectHelper;

public class LaunchConfigLabelProviderPDETest {

  @Rule
  public final LaunchConfigRule launchConfigRule = new LaunchConfigRule();
  @Rule
  public final DisplayHelper displayHelper = new DisplayHelper();
  @Rule
  public final ProjectHelper projectHelper = new ProjectHelper();

  private DuplicatesDetector duplicatesDetector;
  private Collection<LaunchConfigLabelProvider> labelProviders;

  @Before
  public void setUp() {
    duplicatesDetector = mock( DuplicatesDetector.class );
  }

  @After
  public void tearDown() {
    for( LaunchConfigLabelProvider labelProvider : labelProviders ) {
      labelProvider.dispose();
    }
  }

  @Test
  public void testGetImage() throws CoreException {
    ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );

    Image image = labelProvider.getImage( launchConfig );

    assertThat( image ).isNotNull();
  }

  @Test
  public void testGetImageForDeletedLaunchConfig() throws CoreException {
    ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
    launchConfig.delete();
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );

    Image image = labelProvider.getImage( launchConfig );

    assertThat( image ).isNull();
  }

  @Test
  public void testGetImageForArbitraryObject() {
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );

    Image image = labelProvider.getImage( new Object() );

    assertThat( image ).isNull();
  }

  @Test
  public void testGetListText() throws CoreException {
    ILaunchConfigurationWorkingCopy launchConfig = launchConfigRule.createPublicLaunchConfig();
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );<commit_msg>Test LaunchConfigLabelProvider::getImage() with running launch config<commit_after>package com.codeaffine.extras.launch.internal.dialog;

import static com.codeaffine.extras.launch.internal.dialog.LaunchConfigLabelProvider.LabelMode.DETAIL;
import static com.codeaffine.extras.launch.internal.dialog.LaunchConfigLabelProvider.LabelMode.LIST;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.debug.core.ILaunchManager.RUN_MODE;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.codeaffine.eclipse.swt.test.util.DisplayHelper;
import com.codeaffine.extras.launch.internal.dialog.LaunchConfigLabelProvider.LabelMode;
import com.codeaffine.extras.launch.test.LaunchConfigRule;
import com.codeaffine.extras.test.util.ProjectHelper;

public class LaunchConfigLabelProviderPDETest {

  @Rule
  public final LaunchConfigRule launchConfigRule = new LaunchConfigRule();
  @Rule
  public final DisplayHelper displayHelper = new DisplayHelper();
  @Rule
  public final ProjectHelper projectHelper = new ProjectHelper();

  private DuplicatesDetector duplicatesDetector;
  private Collection<LaunchConfigLabelProvider> labelProviders;

  @Before
  public void setUp() {
    duplicatesDetector = mock( DuplicatesDetector.class );
  }

  @After
  public void tearDown() {
    for( LaunchConfigLabelProvider labelProvider : labelProviders ) {
      labelProvider.dispose();
    }
  }

  @Test
  public void testGetImage() throws CoreException {
    ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );

    Image image = labelProvider.getImage( launchConfig );

    assertThat( image ).isNotNull();
  }

  @Test
  public void testGetImageForDeletedLaunchConfig() throws CoreException {
    ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
    launchConfig.delete();
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );

    Image image = labelProvider.getImage( launchConfig );

    assertThat( image ).isNull();
  }

  @Test
  public void testGetImageForRunningLaunchConfig() throws CoreException {
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );
    ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();

    Image image = labelProvider.getImage( launchConfig );
    launchConfig.launch( RUN_MODE, null );
    Image runningImage = labelProvider.getImage( launchConfig );

    assertThat( runningImage ).isNotNull();
    assertThat( runningImage ).isNotEqualTo( image );
  }

  @Test
  public void testGetImageForArbitraryObject() {
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );

    Image image = labelProvider.getImage( new Object() );

    assertThat( image ).isNull();
  }

  @Test
  public void testGetListText() throws CoreException {
    ILaunchConfigurationWorkingCopy launchConfig = launchConfigRule.createPublicLaunchConfig();
    LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );
{'fraction_non_alphanumeric': 0.08615863141524106, 'fraction_numerical': 0.0, 'mean_word_length': 5.5091093117408905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1897345', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1728, 'n_words': 365}