package uk.ac.horizon.artcodes;

import com.google.gson.Gson;
import org.junit.Test;
import uk.ac.horizon.artcodes.model.Action;
import uk.ac.horizon.artcodes.model.Experience;
import uk.ac.horizon.artcodes.scanner.process.ImageProcessor;
import uk.ac.horizon.artcodes.scanner.process.TileThresholder;

import java.io.IOException;

public class ExperienceParserTest
{
	@Test
	public void testExperienceRoundTrip() throws IOException
	{
		final Experience experience = new Experience();
		final Action action = new Action();
		experience.getActions().add(action);

		final Gson gson = ExperienceParser.createGson(null);
		final String json1 = gson.toJson(experience);
		final Experience parsed = gson.fromJson(json1, Experience.class);
		final String json2 = gson.toJson(parsed);

		assert json1.equals(json2);
	}

	@Test
	public void testParseOld() throws IOException
	{
//		URL url = getClass().getResource("test_old.json");
//		assert url != null;
//
//		final JsonParser<Experience> parser = new ExperienceParserFactory(null).parserFor(Experience.class);
//		Experience experience = parser.parse(new FileReader(new File(url.getFile())));
//
//		assert experience.getName().equals("Test");
//		assert !experience.getActions().isEmpty();
	}

	@Test
	public void testParser() throws IOException
	{
//		URL url = getClass().getResource("test.json");
//		assert url != null;
//
//		final JsonParser<Experience> parser = new ExperienceParserFactory(null).parserFor(Experience.class);
//		Experience experience = parser.parse(new FileReader(new File(url.getFile())));
//
//		assert experience.getName().equals("Test");
//		assert !experience.getActions().isEmpty();
	}

	@Test
	public void testThresholderParse()
	{
		ImageProcessor imageProcessor = new TileThresholder();

		final Gson gson = ExperienceParser.createGson(null);

		String json = gson.toJson(imageProcessor);

		ImageProcessor parsed = gson.fromJson(json, ImageProcessor.class);
		assert parsed != null;
		assert parsed.getClass().equals(TileThresholder.class);
	}
}
@@ -1694,16 +1694,26 @@
 esholder
+Experience
 Parse()%0A
@@ -1717,21 +1717,74 @@
 ()%0A%09%7B%0A%09%09
-Ima
+Experience experience = new Experience();%0A%09%09experience.
 ge
+t
 Processo
@@ -1788,14 +1788,37 @@
 ssor
- ima
+s().clear();%0A%09%09experience.
 ge
+t
 Proc
@@ -1822,19 +1822,24 @@
 rocessor
- = 
+s().add(
 new Tile
@@ -1851,16 +1851,17 @@
 holder()
+)
 ;%0A%0A%09%09fin
@@ -1943,42 +1943,62 @@
 son(
-imageProcessor
+experience);%0A%09%09System.out.println(json
 );%0A%0A%09%09
-ImageProcessor
+Experience
  par
@@ -2023,30 +2023,26 @@
 n(json, 
-ImageProcessor
+Experience
 .class);
@@ -2083,16 +2083,39 @@
  parsed.
+getProcessors().get(0).
 getClass

Fix test