package model;

import org.junit.Test;

import static org.junit.Assert.*;

import java.io.File;

public class TitanDSMTest {

    @Test
    public void testTitanDSM() throws Exception {
        int size = 10;
        String filePath = "./sample/titan/titan.dsm";
        File file = new File(filePath);

        TitanDSM newDSM = new TitanDSM(size);
        assertNotNull(newDSM);
        TitanDSM loadDSM = new TitanDSM(file);
        assertNotNull(loadDSM);
    }

    @Test(expected=NotPositiveException.class)
    public void testTitanDSMWithException() throws Exception {
        int size = -1;
        TitanDSM newDSM = new TitanDSM(size);
    }

    @Test
    public void testGetSize() throws Exception {
        TitanDSM dsm = new TitanDSM(30);
        assertEquals(30, dsm.getSize());
    }

    @Test
    public void testGetData() throws Exception {
        TitanDSM dsm = new TitanDSM(30);
        assertEquals(false, dsm.getData("entity_1","entity_2"));
    }

    @Test
    public void testSetData() throws Exception {
        TitanDSM dsm = new TitanDSM(30);
        dsm.setData(true,"entity_1", "entity_2");
        assertTrue(dsm.getData("entity_1","entity_2"));
    }

    @Test
    public void testDeleteData() throws Exception {
        TitanDSM dsm = new TitanDSM(30);
        dsm.deleteData("entity_1");
        assertEquals(29,dsm.getSize());
    }

    @Test
    public void testGetName() throws Exception {
        TitanDSM dsm = new TitanDSM(30);
        assertEquals("entity_1",dsm.getName(0));
    }

    @Test
    public void testSetName() throws Exception {
        TitanDSM dsm = new TitanDSM(30);
        dsm.setName("NewName","entity_1");
        assertEquals("NewName",dsm.getName(0));
    }

    @Test(expected=ItemAlreadyExistException.class)
    public void testSetNameWithException() throws Exception {
        int size = 10;
        String newClassName = "entity_1";
        String oldClassName = "entity_2";
        TitanDSM dsm = new TitanDSM(size);
        dsm.setName(newClassName, oldClassName);
    }

    @Test
    public void testIsExist() throws Exception {
        int size = 10;
        String existingString = "entity_10";
        String nonExistingString = "test";
        TitanDSM dsm = new TitanDSM(size);
        assertEquals(true, dsm.isExist(existingString));
        assertEquals(false, dsm.isExist(nonExistingString));
    }

    @Test
    public void testAddEntity() throws Exception {
        int size = 10;
        TitanDSM dsm = new TitanDSM(size);
        dsm.addEntity();
        assertEquals(size + 1, dsm.getSize());
    }

    @Test
    public void testLoadFromFile() throws Exception {
        int size = 10;
        String testString = "edu.drexel.cs.rise.titan.action.RedrawAction";
        String pathName = "./sample/titan/titan.dsm";
        File file = new File(pathName);
        TitanDSM dsm = new TitanDSM(size);
        dsm.loadFromFile(file);
        assertEquals(true, dsm.isExist(testString));
    }

    @Test
    public void testSaveToFile() throws Exception {
        TitanDSM dsm = new TitanDSM(30);
        File file = new File("a");
        dsm.setData(true,"entity_1","entity_2");
        dsm.saveToFile(file);
        TitanDSM dsm2 = new TitanDSM(file);
        assertEquals(dsm.getData("entity_1","entity_2"),dsm2.getData("entity_1","entity_2"));
    }
}
@@ -88,16 +88,57 @@
 io.File;
+%0Aimport java.util.NoSuchElementException;
 %0A%0Apublic
@@ -1212,32 +1212,367 @@
 ty_2%22));%0A    %7D%0A%0A
+    @Test(expected=NoSuchElementException.class)%0A    public void testSetDataWithException() throws Exception %7B%0A        int size = 10;%0A        String existingString = %22entity_2%22;%0A        String nonExistingString = %22entity%22;%0A%0A        TitanDSM dsm = new TitanDSM(size);%0A        dsm.setData(true,nonExistingString, existingString);%0A    %7D%0A%0A
     @Test%0A    pu
@@ -2638,37 +2638,29 @@
       assert
-Equals(true, 
+True(
 dsm.isExist(
@@ -2687,38 +2687,30 @@
       assert
-Equals(f
+F
 alse
-, 
+(
 dsm.isExist(

add dsm test code with Exception