package org.musetest.core.resultstorage;

import org.junit.*;
import org.musetest.builtins.step.*;
import org.musetest.core.context.*;
import org.musetest.core.project.*;
import org.musetest.core.step.*;
import org.musetest.core.steptest.*;
import org.musetest.core.util.*;

import java.io.*;
import java.util.*;

/**
 * @author Christopher L Merrill (see LICENSE.txt for license details)
 */
public class SaveTestResultsToDiskTests
	{
	@Test
	public void storeFile() throws IOException
		{
		final File folder = FileUtils.createTempFolder("musetest", null);
		MockStorageLocationProvider location_plugin = new MockStorageLocationProvider(folder, folder);
		SteppedTestExecutionContext context = new DefaultSteppedTestExecutionContext(new SimpleProject(), new SteppedTest(new StepConfiguration(LogMessage.TYPE_ID)));
		context.addPlugin(location_plugin);

		SaveTestResultsToDisk save_plugin = new SaveTestResultsToDiskConfiguration().createPlugin();
		context.addPlugin(save_plugin);

		context.addPlugin(new MockTestResultProducer(Collections.singletonList(new MockTestResultData("saved.txt", "result-data".getBytes()))));

		save_plugin.initialize(context);
		save_plugin.shutdown();

		final File saved = new File(folder, "saved.txt");
		Assert.assertTrue(saved.exists());
		Assert.assertEquals("result-data", FileUtils.readFileAsString(saved));
	    }
	}



@@ -458,16 +458,17 @@
 toreFile
+s
 () throw
@@ -1118,16 +1118,156 @@
 s()))));
+%0A%09%09context.addPlugin(new MockTestResultProducer(Collections.singletonList(new MockTestResultData(%22saved.txt%22, %22result-data2%22.getBytes()))));
 %0A%0A%09%09save
@@ -1483,16 +1483,184 @@
 saved));
+%0A%0A%09%09final File saved2 = new File(folder, %22saved2.txt%22);%0A%09%09Assert.assertTrue(saved2.exists());%0A%09%09Assert.assertEquals(%22result-data2%22, FileUtils.readFileAsString(saved2));
 %0A%09    %7D%0A

improve test: saving duplicate-named TestResultData