package org.scm4j.releaser.actions;

import org.junit.Test;
import org.scm4j.commons.progress.IProgress;
import org.scm4j.commons.progress.ProgressConsole;
import org.scm4j.releaser.WorkflowTestBase;
import org.scm4j.releaser.exceptions.EReleaserException;

import java.util.Arrays;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class ActionAbstractTest extends WorkflowTestBase {

	@Test
	public void testExceptions() throws Exception {
		ActionAbstract aa = mock(ActionAbstract.class);
		Exception testException = new Exception("test exeption");
		doThrow(testException).when(aa).executeAction(any(IProgress.class));
		try {
			aa.execute(new ProgressConsole());
		} catch (EReleaserException e) {
			assertEquals(testException, e.getCause());
		}
		EReleaserException testReleaserException = new EReleaserException("test releaser exception");
		doThrow(testReleaserException).when(aa).executeAction(any(IProgress.class));
		try {
			aa.execute(new ProgressConsole());
		} catch (EReleaserException e) {
			assertNull(e.getCause());
		}
	}

	@Test
	public void testSkipNonExecutableChildActions() {
		IAction doneAction = mock(ActionAbstract.class);
		doReturn(false).when(doneAction).isExecutable();
		doReturn(false).when(doneAction).isUrlProcessed(anyString());

		ActionAbstract aa = spy(new ActionAbstract(compUnTill, Arrays.asList(doneAction), repoUnTill) {
			@Override
			protected void executeAction(IProgress progress) throws Exception {
			}

			@Override
			public String toStringAction() {
				return null;
			}

			@Override
			public boolean isExecutable() {
				return false;
			}
		});
		IProgress progress = mock(IProgress.class);
		aa.execute(progress);
		verify(progress, never()).createNestedProgress(anyString());
		verify(doneAction, never()).execute(any(IProgress.class));
	}
}
@@ -193,16 +193,104 @@
 stBase;%0A
+import org.scm4j.releaser.conf.Component;%0Aimport org.scm4j.releaser.conf.VCSRepository;%0A
 import o
@@ -339,16 +339,44 @@
 ption;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -391,16 +391,39 @@
 .Arrays;
+%0Aimport java.util.List;
 %0A%0Aimport
@@ -548,16 +548,419 @@
 Base %7B%0A%0A
+%09static class TestAction extends ActionAbstract %7B%0A%09%09public TestAction(Component comp, List%3CIAction%3E childActions, VCSRepository repo) %7B%0A%09%09%09super(comp, childActions, repo);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09protected void executeAction(IProgress progress) throws Exception %7B%0A%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public String toStringAction() %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public boolean isExecutable() %7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%7D%0A%0A
 %09@Test%0A%09
@@ -1033,33 +1033,69 @@
 a = 
-mock(ActionAbstract.class
+spy(new TestAction(compUnTill, new ArrayList%3C%3E(), repoUnTill)
 );%0A%09
@@ -1262,32 +1262,43 @@
 ressConsole());%0A
+%09%09%09fail();%0A
 %09%09%7D catch (ERele
@@ -1587,16 +1587,27 @@
 ole());%0A
+%09%09%09fail();%0A
 %09%09%7D catc
@@ -1925,30 +1925,26 @@
 spy(new 
+Test
 Action
-Abstract
 (compUnT
@@ -1990,247 +1990,8 @@
 ill)
- %7B%0A%09%09%09@Override%0A%09%09%09protected void executeAction(IProgress progress) throws Exception %7B%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public String toStringAction() %7B%0A%09%09%09%09return null;%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public boolean isExecutable() %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D
 );%0A%09

test update