package com.readytalk.swt.effects;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

/**
 */
public class LinkableEffectTest {

  @MockitoAnnotations.Mock
  private LinkableEffect parent;

  @MockitoAnnotations.Mock
  private LinkableEffect child;

  private int TIME_INTERVAL = 200;

  @Before
  public void setUp() throws IllegalArgumentException{
    MockitoAnnotations.initMocks(this);
    Mockito.when(parent.linkEffect(Mockito.any(LinkableEffect.class))).thenCallRealMethod();
    Mockito.when(parent.getEffectList()).thenCallRealMethod();
  }

  @Test
  public void testConstructorWithParent() {
    try {
      // mocking an abstract classes constructor is not something do-able as far as i found, so we just make a dummy one
      LinkableEffect effect = new DummyLinkableEffect(parent, TIME_INTERVAL);

      Assert.assertTrue(parent.getEffectList().contains(effect));
      Assert.assertNotSame(TIME_INTERVAL, effect.getTimeInterval());
      Assert.assertNull(effect.getExecutor());
    } catch (InvalidEffectArgumentException iea) {
      Assert.fail(iea.getMessage());
    }
  }


  /**
   * Can't mock abstract classes, but for this problem this really is the best solution (making LinkableEffect an abstract class)... or the best I found.  :-(
   */
  private class DummyLinkableEffect extends LinkableEffect {

    public DummyLinkableEffect(LinkableEffect parent,
                               int timeInterval, LinkableEffect ... linkableEffects) throws InvalidEffectArgumentException {
      super(parent, null, timeInterval, linkableEffects);
    }

    @Override
    public boolean isEffectComplete() {
      return false;
    }

    @Override
    public void effectStep() {
    }

    @Override
    public void effectComplete() {
    }
  }

}

@@ -29,16 +29,56 @@
 fects;%0A%0A
+import com.readytalk.swt.util.Executor;%0A
 import o
@@ -94,16 +94,16 @@
 Assert;%0A
-
 import o
@@ -214,16 +214,8 @@
 s;%0A%0A
-/**%0A */%0A
 publ
@@ -245,16 +245,73 @@
 Test %7B%0A%0A
+  @MockitoAnnotations.Mock%0A  private Executor executor;%0A%0A
   @Mocki
@@ -969,16 +969,22 @@
 (parent,
+ null,
  TIME_IN
@@ -1274,16 +1274,1151 @@
  %7D%0A  %7D%0A%0A
+  @Test%0A  public void testConstructorWithExecutor() %7B%0A    try %7B%0A      // mocking an abstract classes constructor is not something do-able as far as i found, so we just make a dummy one%0A      LinkableEffect effect = new DummyLinkableEffect(null, executor, TIME_INTERVAL, parent);%0A%0A      Assert.assertEquals(executor, effect.getExecutor());%0A      Assert.assertTrue(effect.getEffectList().contains(parent));%0A      Assert.assertEquals(TIME_INTERVAL, effect.getTimeInterval());%0A    %7D catch (InvalidEffectArgumentException iea) %7B%0A      Assert.fail(iea.getMessage());%0A    %7D%0A  %7D%0A%0A  @Test%0A  public void testConstructorWithExecutorAndDefaultTimeInterval() %7B%0A    try %7B%0A      // mocking an abstract classes constructor is not something do-able as far as i found, so we just make a dummy one%0A      LinkableEffect effect = new DummyLinkableEffect(null, executor, 0);%0A%0A      Assert.assertEquals(executor, effect.getExecutor());%0A      Assert.assertFalse(effect.getEffectList().contains(parent));%0A      Assert.assertNotSame(0, effect.getTimeInterval());%0A    %7D catch (InvalidEffectArgumentException iea) %7B%0A      Assert.fail(iea.getMessage());%0A    %7D%0A  %7D%0A
 %0A  /**%0A 
@@ -2696,16 +2696,35 @@
  parent,
+ Executor executor,
 %0A       
@@ -2861,20 +2861,24 @@
 parent, 
-null
+executor
 , timeIn

Add LinkableEffectTest from core_nativeclient.