package ru.matevosyan;

import org.junit.Test;

import java.util.NoSuchElementException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * Test MajorStore class.
 * Created on 16.05.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class MajorStoreTest {

    /**
     * whenAddBaseAndGetObjectThanCheckAddedObject() method created to test {@link MajorStore#add(Base)} method.
     */

    @Test
    public void whenAddBaseAndGetObjectThanCheckAddedObject() {
        Base user = new User("Vova", 12, "1");
        Base role = new Role("2");

        MajorStore majorStore = new MajorStore(2);

        majorStore.add(user);
        majorStore.add(role);

        assertThat(majorStore.get("1"), is(user));
    }

    /**
     * whenAddBaseAndUpdateAndGetObjectThanCheckUpdatedObject() method created to test.
     * {@link MajorStore#update(String, Base)} )} method.
     */

    @Test
    public void whenAddBaseAndUpdateAndGetObjectThanCheckUpdatedObject() {
        Base user = new User("Vova", 12, "1");
        Base role = new Role("2");
        Base userToUpdate = new User("Ivan", 22, "1");

        MajorStore majorStore = new MajorStore(2);

        majorStore.add(user);
        majorStore.add(role);

        majorStore.update("1", userToUpdate);

        assertThat(majorStore.get("1"), is(userToUpdate));
    }

    /**
     * whenAddBaseAndDeleteObjectThanCheckBaseObject() method created to test.
     * {@link MajorStore#delete(String)} )} method.
     */

    @Test
    public void whenAddBaseAndDeleteObjectThanCheckBaseObject() {
        Throwable e = null;
        User user = new User("Vova", 12, "1");
        User user2 = new User("Tom", 12, "2");

        SimpleArray<Base> simpleArray = new SimpleArray<>(2);
        UserStore userStore = new UserStore(simpleArray);

        try {
            userStore.add(user);
            userStore.add(user2);
            userStore.delete("4");
        } catch (Throwable exp) {
            e = exp;
        }

        assertTrue(e instanceof NoSuchElementException);

    }

    /**
     * whenAddBaseAndGetObjectThanCheckGetObject() method created to test.
     * {@link MajorStore#get(String)} )} method.
     */

    @Test
    public void whenAddBaseAndGetObjectThanCheckGetObject() {
        Base user = new User("Vova", 12, "1");
        Base role = new Role("2");

        MajorStore majorStore = new MajorStore(2);

        majorStore.add(user);
        majorStore.add(role);

        assertThat(majorStore.get("2"), is(role));
        assertFalse(majorStore.get("2").equals(user));
    }

}
@@ -2177,32 +2177,770 @@
 ption);%0A%0A    %7D%0A%0A
+    /**%0A     * whenAddBaseAndDeleteObjectInRoleStoreThanCheckBaseObject() method created to test.%0A     * %7B@link MajorStore#delete(String)%7D )%7D method from %7B@link RoleStore%7D.%0A     */%0A%0A    @Test%0A    public void whenAddBaseAndDeleteObjectInRoleStoreThanCheckBaseObject() %7B%0A        Throwable e = null;%0A        Role role = new Role(%221%22);%0A        Role role2 = new Role(%222%22);%0A%0A        SimpleArray%3CBase%3E simpleArray = new SimpleArray%3C%3E(2);%0A        RoleStore roleStore = new RoleStore(simpleArray);%0A%0A        try %7B%0A            roleStore.add(role);%0A            roleStore.add(role2);%0A            roleStore.delete(%224%22);%0A        %7D catch (Throwable exp) %7B%0A            e = exp;%0A        %7D%0A%0A        assertTrue(e instanceof NoSuchElementException);%0A%0A    %7D%0A%0A%0A
     /**%0A     * w

add one method to MajorStoreTest.java