package seedu.address.commons.util;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileNotFoundException;

import javax.xml.bind.JAXBException;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import seedu.address.model.AddressBook;
import seedu.address.storage.XmlSerializableAddressBook;
import seedu.address.testutil.AddressBookBuilder;
import seedu.address.testutil.TestUtil;

public class XmlUtilTest {

    private static final String TEST_DATA_FOLDER = FileUtil.getPath("src/test/data/XmlUtilTest/");
    private static final File EMPTY_FILE = new File(TEST_DATA_FOLDER + "empty.xml");
    private static final File MISSING_FILE = new File(TEST_DATA_FOLDER + "missing.xml");
    private static final File VALID_FILE = new File(TEST_DATA_FOLDER + "validAddressBook.xml");
    private static final File TEMP_FILE = new File(TestUtil.getFilePathInSandboxFolder("tempAddressBook.xml"));

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void getDataFromFile_nullFile_AssertionError() throws Exception {
        thrown.expect(AssertionError.class);
        XmlUtil.getDataFromFile(null, AddressBook.class);
    }

    @Test
    public void getDataFromFile_nullClass_AssertionError() throws Exception {
        thrown.expect(AssertionError.class);
        XmlUtil.getDataFromFile(VALID_FILE, null);
    }

    @Test
    public void getDataFromFile_missingFile_FileNotFoundException() throws Exception {
        thrown.expect(FileNotFoundException.class);
        XmlUtil.getDataFromFile(MISSING_FILE, AddressBook.class);
    }

    @Test
    public void getDataFromFile_emptyFile_DataFormatMismatchException() throws Exception {
        thrown.expect(JAXBException.class);
        XmlUtil.getDataFromFile(EMPTY_FILE, AddressBook.class);
    }

    @Test
    public void getDataFromFile_validFile_validResult() throws Exception {
        XmlSerializableAddressBook dataFromFile = XmlUtil.getDataFromFile(VALID_FILE, XmlSerializableAddressBook.class);
        assertEquals(9, dataFromFile.getPersonList().size());
        assertEquals(0, dataFromFile.getTagList().size());
    }

    @Test
    public void saveDataToFile_nullFile_AssertionError() throws Exception {
        thrown.expect(AssertionError.class);
        XmlUtil.saveDataToFile(null, new AddressBook());
    }

    @Test
    public void saveDataToFile_nullClass_AssertionError() throws Exception {
        thrown.expect(AssertionError.class);
        XmlUtil.saveDataToFile(VALID_FILE, null);
    }

    @Test
    public void saveDataToFile_missingFile_FileNotFoundException() throws Exception {
        thrown.expect(FileNotFoundException.class);
        XmlUtil.saveDataToFile(MISSING_FILE, new AddressBook());
    }

    @Test
    public void saveDataToFile_validFile_dataSaved() throws Exception {
        TEMP_FILE.createNewFile();
        XmlSerializableAddressBook dataToWrite = new XmlSerializableAddressBook(new AddressBook());
        XmlUtil.saveDataToFile(TEMP_FILE, dataToWrite);
        XmlSerializableAddressBook dataFromFile = XmlUtil.getDataFromFile(TEMP_FILE, XmlSerializableAddressBook.class);
        assertEquals((new AddressBook(dataToWrite)).toString(), (new AddressBook(dataFromFile)).toString());
        //TODO: use equality instead of string comparisons

        AddressBookBuilder builder = new AddressBookBuilder(new AddressBook());
        dataToWrite = new XmlSerializableAddressBook(
                builder.withPerson(TestUtil.generateSamplePersonData().get(0)).withTag("Friends").build());

        XmlUtil.saveDataToFile(TEMP_FILE, dataToWrite);
        dataFromFile = XmlUtil.getDataFromFile(TEMP_FILE, XmlSerializableAddressBook.class);
        assertEquals((new AddressBook(dataToWrite)).toString(), (new AddressBook(dataFromFile)).toString());
    }
}

@@ -290,27 +290,27 @@
 s.model.
-AddressBook
+TaskManager
 ;%0Aimport
@@ -347,27 +347,27 @@
 alizable
-AddressBook
+TaskManager
 ;%0Aimport
@@ -390,27 +390,27 @@
 estutil.
-AddressBook
+TaskManager
 Builder;
@@ -829,27 +829,27 @@
 + %22valid
-AddressBook
+TaskManager
 .xml%22);%0A
@@ -940,27 +940,27 @@
 er(%22temp
-AddressBook
+TaskManager
 .xml%22));
@@ -1206,27 +1206,27 @@
 e(null, 
-AddressBook
+TaskManager
 .class);
@@ -1615,35 +1615,35 @@
 SSING_FILE, 
-AddressBook
+TaskManager
 .class);%0A   
@@ -1835,27 +1835,27 @@
 Y_FILE, 
-AddressBook
+TaskManager
 .class);
@@ -1966,35 +1966,35 @@
 Serializable
-AddressBook
+TaskManager
  dataFromFil
@@ -2044,35 +2044,35 @@
 Serializable
-AddressBook
+TaskManager
 .class);%0A   
@@ -2108,22 +2108,20 @@
 File.get
-Person
+Task
 List().s
@@ -2362,35 +2362,35 @@
 e(null, new 
-AddressBook
+TaskManager
 ());%0A    %7D%0A%0A
@@ -2771,35 +2771,35 @@
 G_FILE, new 
-AddressBook
+TaskManager
 ());%0A    %7D%0A%0A
@@ -2934,35 +2934,35 @@
 Serializable
-AddressBook
+TaskManager
  dataToWrite
@@ -2987,35 +2987,35 @@
 able
-AddressBook(new AddressBook
+TaskManager(new TaskManager
 ());
@@ -3094,27 +3094,27 @@
 alizable
-AddressBook
+TaskManager
  dataFro
@@ -3167,35 +3167,35 @@
 Serializable
-AddressBook
+TaskManager
 .class);%0A   
@@ -3213,35 +3213,35 @@
 Equals((new 
-AddressBook
+TaskManager
 (dataToWrite
@@ -3256,35 +3256,35 @@
 ing(), (new 
-AddressBook
+TaskManager
 (dataFromFil
@@ -3368,27 +3368,27 @@
         
-AddressBook
+TaskManager
 Builder 
@@ -3401,27 +3401,27 @@
 r = new 
-AddressBook
+TaskManager
 Builder(
@@ -3424,27 +3424,27 @@
 der(new 
-AddressBook
+TaskManager
 ());%0A   
@@ -3481,27 +3481,27 @@
 alizable
-AddressBook
+TaskManager
 (%0A      
@@ -3522,22 +3522,20 @@
 der.with
-Person
+Task
 (TestUti
@@ -3554,14 +3554,12 @@
 mple
-Person
+Task
 Data
@@ -3728,27 +3728,27 @@
 alizable
-AddressBook
+TaskManager
 .class);
@@ -3770,35 +3770,35 @@
 Equals((new 
-AddressBook
+TaskManager
 (dataToWrite
@@ -3821,19 +3821,19 @@
 new 
-AddressBook
+TaskManager
 (dat

Modify XmlUtilTest class