package cafetcraftteam.rpgsoftware.equipment_test;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.EnumSet;
import java.util.Set;

import cafetcraftteam.rpgsoftware.equipment.Equipment;
import cafetcraftteam.rpgsoftware.equipment.MissilesWeapon;
import cafetcraftteam.rpgsoftware.equipment.Weapon;

import static junit.framework.Assert.assertEquals;

/**
 * Created by Gautier on 11/02/2016.
 */

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MissilesWeaponTest
{
    private String mName = "Bottle";
    private int mEncumbering = 10;
    private int mPrice = 100;
    private Equipment.Quality mQuality = Equipment.Quality.COMMON;
    private String mDescription = "It's a simple bottle";
    private Weapon.Group mGroup = Weapon.Group.LONGBOW;
    private Set<Weapon.Qualities> mQualities = EnumSet.of(Weapon.Qualities.DEFENSIVE);

    private int mShortRange = 24;
    private int mLongRange = 48;
    private double mReload = 1;

    private MissilesWeapon mMissilesWeapon = new MissilesWeapon(mName, mEncumbering, mPrice, mQuality,
            mDescription, mGroup, mQualities, mShortRange, mLongRange, mReload);

    @Test
    public void creationTest()
    {
        Equipment equipment = new Equipment(mName, mEncumbering, mPrice, mQuality, mDescription);
        assertEquals(equipment, mMissilesWeapon);
        assertEquals(mGroup, mMissilesWeapon.getGroup());
        assertEquals(mQualities, mMissilesWeapon.getQualities());
        assertEquals(mShortRange, mMissilesWeapon.getShortRange());
        assertEquals(mLongRange, mMissilesWeapon.getLongRange());
        assertEquals(mReload, mMissilesWeapon.getReload());
    }
}

@@ -475,16 +475,59 @@
 tEquals;
+%0Aimport static junit.framework.Assert.fail;
 %0A%0A/**%0A *
@@ -1815,11 +1815,2438 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void contractRespectShortRange()%0A    %7B%0A        // short range must be positive%0A        try%0A        %7B%0A            new MissilesWeapon(mName, mEncumbering, mPrice, mQuality, mDescription, mGroup, mQualities,%0A                    -mShortRange, mLongRange, mReload);%0A            fail(%22Negative short range don't generate an exception%22);%0A        %7D catch (IllegalArgumentException e)%0A        %7B%0A            // success%0A        %7D%0A%0A        // short range could be zero%0A        MissilesWeapon missilesWeapon = new MissilesWeapon(mName, mEncumbering, mPrice, mQuality,%0A                mDescription, mGroup, mQualities, 0, mLongRange, mReload);%0A        assertEquals(0, missilesWeapon.getShortRange());%0A    %7D%0A%0A    @Test%0A    public void contractRespectLongRange()%0A    %7B%0A        // long range must be positive%0A        try%0A        %7B%0A            new MissilesWeapon(mName, mEncumbering, mPrice, mQuality, mDescription, mGroup, mQualities,%0A                    mShortRange, -mLongRange, mReload);%0A            fail(%22Negative long range don't generate an exception%22);%0A        %7D catch (IllegalArgumentException e)%0A        %7B%0A            // success%0A        %7D%0A%0A        // long range could be zero%0A        MissilesWeapon missilesWeapon = new MissilesWeapon(mName, mEncumbering, mPrice, mQuality,%0A                mDescription, mGroup, mQualities, 0, 0, mReload);%0A        assertEquals(0, missilesWeapon.getLongRange());%0A%0A        // long range must be greater than short range or it will be swap%0A        MissilesWeapon missilesWeapon1 = new MissilesWeapon(mName, mEncumbering, mPrice, mQuality,%0A                mDescription, mGroup, mQualities, mShortRange, 0, mReload);%0A        assertEquals(mShortRange, missilesWeapon1.getLongRange());%0A    %7D%0A%0A    @Test%0A    public void contractRespectReload() %7B%0A        // Reload must not be null%0A        try%0A        %7B%0A            new MissilesWeapon(mName, mEncumbering, mPrice, mQuality, mDescription, mGroup, mQualities,%0A                    mShortRange, mLongRange, -mReload);%0A            fail(%22Negative Reload don't generate an exception%22);%0A        %7D catch (IllegalArgumentException e)%0A        %7B%0A            // success%0A        %7D%0A%0A        // Reload could be zero%0A        MissilesWeapon missilesWeapon = new MissilesWeapon(mName, mEncumbering, mPrice, mQuality,%0A                mDescription, mGroup, mQualities, mShortRange, mLongRange, 0);%0A        assertEquals(0.0, missilesWeapon.getReload());%0A    %7D
 %0A%7D%0A

Test du contrat du constructeur de MissilesWeapon