package model;

import static org.junit.Assert.*;
import controllers.MiniProjectController;
import demonstrateur.MiniProject;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by neowutran on 22/01/14.
 */
public class EquipmentTest {

    @BeforeClass
    public static void onlyOnce() {

        try {
            final Method m = MiniProject.class.getDeclaredMethod("loadConfigFile",
                    Path.class);
            m.setAccessible(true);
            m.invoke(null, Paths.get(MiniProject.FOLDER, MiniProject.CONFIG));

        } catch (IllegalAccessException | IllegalArgumentException
                | InvocationTargetException | NoSuchMethodException
                | SecurityException e) {
            e.printStackTrace();
        }

        try {

            SaveLoad.load( SaveLoad.DATA );
        } catch( final MiniProjectException e ) {
            MiniProjectController.LOGGER.severe( java.util.Arrays.toString( e
                    .getStackTrace( ) ) );
        }
    }



    @Test
    public void testSetHealth() throws Exception {
        Health h = new Health(HealthState.OK);
        Equipment e = new Equipment("tablet", new ArrayList<Feature>(), new Health(HealthState.NOT_OK), false);
        e.setHealth(h);
        assertEquals(h, e.getHealth());
    }

    @Test
    public void testSetUnderRepair() throws Exception {
        //TODO
    }

    @Test
    public void testCheckExistence() throws Exception {
        //TODO
    }

    @Test
    public void testEquals() throws Exception {
        //TODO
    }

    @Test
    public void testSetFeatures() throws Exception {
        //TODO
    }

}

@@ -43,16 +43,37 @@
 sert.*;%0A
+import config.Error;%0A
 import c
@@ -359,16 +359,64 @@
 .Paths;%0A
+import java.security.InvalidParameterException;%0A
 import j
@@ -1301,16 +1301,84 @@
     %7D%0A%0A%0A
+    /**%0A     * @author Fabien Pinel%0A     * @throws Exception%0A     */
 %0A    @Te
@@ -1739,102 +1739,673 @@
     
-//TODO%0A    %7D%0A%0A    @Test%0A    public void testCheckExistence() throws Exception %7B%0A        //TODO
+ Equipment e = new Equipment(%22tablet%22, new ArrayList%3CFeature%3E(), new Health(HealthState.NOT_OK), false);%0A         e.setUnderRepair(true);%0A         assertEquals(true, e.getUnderRepair());%0A    %7D%0A%0A    @Test%0A    public void testCheckExistence() throws Exception %7B%0A    %09 Equipment e = new Equipment(%22tablet%22, new ArrayList%3CFeature%3E(), new Health(HealthState.NOT_OK), false);%0A    %09 Equipment second = e;%0A    %09 try%7B%0A    %09 %09second.checkExistence(second.getId());%0A    %09 %7Dcatch(InvalidParameterException ex)%7B%0A    %09%09 InvalidParameterException test = new InvalidParameterException(Error.EQUIPMENT_ALREADY_EXIST);%0A    %09%09 assertEquals(ex.getMessage(), test.getMessage());%0A    %09 %7D
 %0A   

test checkexistence