/**
 * 
 */
package org.corpus_tools.atomic.tagset.impl;

import static org.junit.Assert.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


import java.nio.file.Files;
import java.nio.file.Paths;

import org.corpus_tools.atomic.tagset.Tagset;
import org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl;
import org.eclipse.emf.common.util.URI;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Before;
import org.junit.Test;

/**
 * Unit tests for {@link JavaTagsetImplTest}.
 *
 * @author Stephan Druskat <[mail@sdruskat.net](mailto:mail@sdruskat.net)>
 * 
 */
public class JavaTagsetImplTest {
	
	private JavaTagsetImpl fixture = null;
	
	/**
	 * Sets up the fixture.
	 */
	@Before
	public void setUp() {
		this.setFixture(new JavaTagsetImpl());
	}

	/**
	 * Test method for {@link org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl#addEntry(org.corpus_tools.atomic.tagset.TagsetEntry)}.
	 */
	@Test
	public final void testAddEntry() {
		// FIXME fail("Not yet implemented");
	}

	/**
	 * Test method for {@link org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl#removeEntry(org.corpus_tools.atomic.tagset.TagsetEntry)}.
	 */
	@Test
	public final void testRemoveEntry() {
		// FIXME fail("Not yet implemented");
	}

	/**
	 * Test method for {@link org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl#getEntries()}.
	 */
	@Test
	public final void testGetEntries() {
		// FIXME fail("Not yet implemented");
	}

	/**
	 * Test method for {@link org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl#load(org.eclipse.emf.common.util.URI)}.
	 */
	@Test
	public final void testSaveAndLoad() {
		testSave();
		String userHome = System.getProperty("user.home");
		String path = userHome + "/atomic-tagset.ats";
		Tagset success = getFixture().load(URI.createFileURI(path));
		assertThat(success, IsInstanceOf.instanceOf(Tagset.class));
	}

	/**
	 * Test method for {@link org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl#save(org.eclipse.emf.common.util.URI)}.
	 */
	@Test
	public final void testSave() {
		String userHome = System.getProperty("user.home");
		String path = userHome + "/atomic-tagset.ats";
		boolean success = getFixture().save(URI.createFileURI(path));
		assertTrue(Files.exists(Paths.get(path)));
		assertTrue(success);
	}

	/**
	 * Test method for {@link org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl#getName()}.
	 */
	@Test
	public final void testGetName() {
		assertEquals(null, getFixture().getName());
		getFixture().setName("name");
		assertEquals("name", getFixture().getName());
	}

	/**
	 * Test method for {@link org.corpus_tools.atomic.tagset.impl.JavaTagsetImpl#setName(java.lang.String)}.
	 */
	@Test
	public final void testSetName() {
		getFixture().setName("name");
		assertEquals("name", getFixture().getName());
	}

	/**
	 * @return the fixture
	 */
	private final JavaTagsetImpl getFixture() {
		return fixture;
	}

	/**
	 * @param fixture the fixture to set
	 */
	private final void setFixture(JavaTagsetImpl fixture) {
		this.fixture = fixture;
	}

}

@@ -213,35 +213,153 @@
 l;%0A%0A
-%0Aimport java.nio.file.Files
+import java.io.IOException;%0Aimport java.nio.file.DirectoryNotEmptyException;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.NoSuchFileException
 ;%0Aim
@@ -1780,22 +1780,8 @@
 ) %7B%0A
-%09%09testSave();%0A
 %09%09St
@@ -1878,16 +1878,62 @@
 t.ats%22;%0A
+%09%09getFixture().save(URI.createFileURI(path));%0A
 %09%09Tagset
@@ -2045,24 +2045,338 @@
 et.class));%0A
+%09%09try %7B%0A%09%09%09Files.delete(Paths.get(path));%0A%09%09%7D%0A%09%09catch (%0A%0A%09%09NoSuchFileException x) %7B%0A%09%09%09fail(path + %22: no such file or directory%22);%0A%09%09%7D%0A%09%09catch (DirectoryNotEmptyException x) %7B%0A%09%09%09fail(path + %22 not empty%22);%0A%09%09%7D%0A%09%09catch (IOException x) %7B%0A%09%09%09// File permission problems are caught here.%0A%09%09%09System.err.println(x);%0A%09%09%7D%0A
 %09%7D%0A%0A%09/**%0A%09 *
@@ -2768,16 +2768,330 @@
 ccess);%0A
+%09%09try %7B%0A%09%09%09Files.delete(Paths.get(path));%0A%09%09%7D%0A%09%09catch (%0A%0A%09%09NoSuchFileException x) %7B%0A%09%09%09fail(path + %22: no such file or directory%22);%0A%09%09%7D%0A%09%09catch (DirectoryNotEmptyException x) %7B%0A%09%09%09fail(path + %22 not empty%22);%0A%09%09%7D%0A%09%09catch (IOException x) %7B%0A%09%09%09// File permission problems are caught here.%0A%09%09%09System.err.println(x);%0A%09%09%7D%0A
 %09%7D%0A%0A%09/**

Delete file after test