
package sc.fiji.kymographBuilder;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import net.imagej.Dataset;

import org.junit.Test;
import org.scijava.command.CommandModule;

import ij.gui.Line;
import ij.plugin.frame.RoiManager;

public class TestKymographBuilder extends AbstractTest {

	@Test
		public void TestKymographBuilderCommand() throws IOException, InterruptedException,
			ExecutionException
		{
			final String sampleImage =
				"8bit-unsigned&pixelType=uint8&indexed=true&lengths=10,10,5&axes=X,Y,Time.fake";
	
			Dataset dataset = (Dataset) io.open(sampleImage);
	
			Map<String, Object> inputs = new HashMap<>();
			inputs.put("input", dataset);
	
			// Add a line
			RoiManager rm = RoiManager.getRoiManager();
			Line line = new Line(1, 1, 5, 5);
			rm.addRoi(line);
	
			CommandModule module = command.run(KymographBuilder.class, true, inputs).get();
			Dataset output = (Dataset) module.getOutput("kymograph");
	
			assertEquals(output.numDimensions(), dataset.numDimensions() - 1);
		}

	@Test
	public void TestKymographBuilderCommandException() throws IOException, InterruptedException,
		ExecutionException
	{
		final String sampleImage =
			"8bit-unsigned&pixelType=uint8&indexed=true&lengths=10,10,5&axes=X,Y,Time.fake";

		Dataset dataset = (Dataset) io.open(sampleImage);

		Map<String, Object> inputs = new HashMap<>();
		inputs.put("input", dataset);

		// Don't add line.

		CommandModule module = command.run(KymographBuilder.class, true, inputs).get();
		Dataset output = (Dataset) module.getOutput("kymograph");

		assertNull(output);
	}

	@Test
	public void TestKymographBuilderCommandTwoDimensions() throws IOException, InterruptedException,
		ExecutionException
	{
		final String sampleImage =
			"8bit-unsigned&pixelType=uint8&lengths=10,10&axes=X,Y.fake";

		Dataset dataset = (Dataset) io.open(sampleImage);

		Map<String, Object> inputs = new HashMap<>();
		inputs.put("input", dataset);
		
		// Don't add line.

		CommandModule module = command.run(KymographBuilder.class, true, inputs).get();
		Dataset output = (Dataset) module.getOutput("kymograph");

		assertNull(output);
	}

}

@@ -33,53 +33,8 @@
 r;%0A%0A
-import static org.junit.Assert.assertEquals;%0A
 impo
@@ -72,16 +72,16 @@
 rtNull;%0A
+
 %0Aimport 
@@ -296,64 +296,8 @@
 e;%0A%0A
-import ij.gui.Line;%0Aimport ij.plugin.frame.RoiManager;%0A%0A
 publ
@@ -350,23 +350,27 @@
 Test %7B%0A%0A
+%09/*
 %09@Test%0A
+%09
 %09%09public
@@ -450,16 +450,17 @@
 ion,%0A%09%09%09
+%09
 Executio
@@ -472,18 +472,20 @@
 ption%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09final
@@ -510,16 +510,17 @@
 e =%0A%09%09%09%09
+%09
 %228bit-un
@@ -593,17 +593,19 @@
 fake%22;%0A%09
-%0A
+%09%0A%09
 %09%09%09Datas
@@ -650,20 +650,22 @@
 mage);%0A%09
+%09
 %0A%09%09%09
+%09
 Map%3CStri
@@ -705,16 +705,17 @@
 %3E();%0A%09%09%09
+%09
 inputs.p
@@ -737,20 +737,22 @@
 aset);%0A%09
+%09
 %0A%09%09%09
+%09
 // Add a
@@ -757,16 +757,103 @@
  a line%0A
+%09%09%09%09// TODO: I can't run this test on Travis because ROIManager can't run headless...%0A%09
 %09%09%09RoiMa
@@ -894,16 +894,17 @@
 r();%0A%09%09%09
+%09
 Line lin
@@ -932,16 +932,17 @@
  5);%0A%09%09%09
+%09
 rm.addRo
@@ -951,20 +951,22 @@
 line);%0A%09
+%09
 %0A%09%09%09
+%09
 CommandM
@@ -1040,16 +1040,17 @@
 t();%0A%09%09%09
+%09
 Dataset 
@@ -1100,17 +1100,19 @@
 aph%22);%0A%09
-%0A
+%09%0A%09
 %09%09%09asser
@@ -1175,17 +1175,20 @@
 - 1);%0A%09%09
-%7D
+%09%7D*/
 %0A%0A%09@Test

Disable test that needs UI