package com.codeaffine.extras.internal.launch;

import static com.codeaffine.extras.launch.test.LaunchManagerHelper.createLaunchConfig;
import static com.codeaffine.extras.launch.test.LaunchManagerHelper.deleteLaunchConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyZeroInteractions;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.XMLMemento;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LaunchConfigSelectionHistoryPDETest {

  private LaunchConfigSelectionHistory history;
  private ILaunchConfiguration launchConfig;

  @Test
  public void testRestoreFromMemento() {
    Object restoredItem = history.restoreItemFromMemento( XMLMemento.createWriteRoot( "foo" ) );

    assertThat( restoredItem ).isNull();
  }

  @Test
  public void testStoreItemToMemento() {
    IMemento memento = mock( IMemento.class );

    history.storeItemToMemento( new Object(), memento );

    verifyZeroInteractions( memento );
  }

  @Test
  public void testGetHistoryItems() {
    addLaunchConfigToHistory();

    Object[] historyItems = history.getHistoryItems();

    assertThat( historyItems ).containsOnly( launchConfig );
  }

  @Test
  public void testGetHistoryItemsWhenNoHistory() {
    Object[] historyItems = history.getHistoryItems();

    assertThat( historyItems ).isEmpty();
  }

  @Test
  public void testIsEmpty() {
    addLaunchConfigToHistory();

    boolean empty = history.isEmpty();

    assertThat( empty ).isFalse();
  }

  @Test
  public void testIsEmptyWhenNoHistory() {
    boolean empty = history.isEmpty();

    assertThat( empty ).isTrue();
  }

  @Test
  public void testContains() {
    addLaunchConfigToHistory();

    boolean contains = history.contains( launchConfig );

    assertThat( contains ).isTrue();
  }

  @Test
  public void testContainsWhenNoHistory() {
    boolean contains = history.contains( launchConfig );

    assertThat( contains ).isFalse();
  }

  @Test
  public void testContainsWithNullArgument() {
    boolean contains = history.contains( null );

    assertThat( contains ).isFalse();
  }

  @Before
  public void setUp() throws Exception {
    launchConfig = createLaunchConfig().doSave();
    history = new LaunchConfigSelectionHistory();
  }

  @After
  public void tearDown() throws CoreException {
    deleteLaunchConfig( launchConfig.getName() );
  }

  private void addLaunchConfigToHistory() {
    DebugUITools.launch( launchConfig, ILaunchManager.RUN_MODE );
  }
}

@@ -275,16 +275,142 @@
 rtThat;%0A
+import static org.eclipse.debug.core.ILaunchManager.DEBUG_MODE;%0Aimport static org.eclipse.debug.core.ILaunchManager.RUN_MODE;%0A
 import s
@@ -441,16 +441,16 @@
 o.mock;%0A
-
 import s
@@ -603,54 +603,8 @@
 on;%0A
-import org.eclipse.debug.core.ILaunchManager;%0A
 impo
@@ -1360,35 +1360,35 @@
 ryItems() %7B%0A    
-add
+run
 LaunchConfigToHi
@@ -1379,33 +1379,273 @@
 LaunchConfig
-ToHistory
+();%0A%0A    Object%5B%5D historyItems = history.getHistoryItems();%0A%0A    assertThat( historyItems ).containsOnly( launchConfig );%0A  %7D%0A%0A  @Test%0A  public void testGetHistoryItemsAfterRunAndDebugSameLaunchConfig() %7B%0A    runLaunchConfig();%0A    debugLaunchConfig
 ();%0A%0A    Obj
@@ -1955,35 +1955,35 @@
 IsEmpty() %7B%0A    
-add
+run
 LaunchConfigToHi
@@ -1974,33 +1974,24 @@
 LaunchConfig
-ToHistory
 ();%0A%0A    boo
@@ -2236,19 +2236,19 @@
 ) %7B%0A    
-add
+run
 LaunchCo
@@ -2251,25 +2251,16 @@
 chConfig
-ToHistory
 ();%0A%0A   
@@ -2944,11 +2944,11 @@
 oid 
-add
+run
 Laun
@@ -2959,17 +2959,8 @@
 nfig
-ToHistory
 () %7B
@@ -2999,34 +2999,114 @@
 Config, 
-ILaunchManager.RUN
+RUN_MODE );%0A  %7D%0A%0A  private void debugLaunchConfig() %7B%0A    DebugUITools.launch( launchConfig, DEBUG
 _MODE );

Add further test for LaunchConfigSelectionHistory