package me.pagarme;

import java.util.Collection;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import me.pagar.model.Plan;
import me.pagarme.factory.PlanFactory;

public class PlanTest extends BaseTest {

    private PlanFactory planFactory = new PlanFactory();

    @Before
    public void setUp() {
        super.setUp();
    }

    @Test
    public void testCreatePlan() throws Throwable {
        Plan plan = planFactory.create();
        plan.save();
        Assert.assertNotNull(plan.getId());
        Assert.assertEquals(Integer.valueOf(PlanFactory.DEFAULT_AMOUNT), plan.getAmount());
        Assert.assertEquals(PlanFactory.DEFAULT_NAME, plan.getName());
        Assert.assertEquals(Integer.valueOf(PlanFactory.DEFAULT_DAYS), plan.getDays());
        Assert.assertEquals(Integer.valueOf(PlanFactory.DEFAULT_CHARGES), plan.getCharges());
        Assert.assertEquals(Integer.valueOf(PlanFactory.DEFAULT_INSTALLMENTS), plan.getInstallments());
        Assert.assertEquals(Integer.valueOf(PlanFactory.DEFAULT_TRIAL_DAYS), plan.getTrialDays());
        Assert.assertNotNull(plan.getCreatedAt());
    }

    @Test
    public void testFindPlan() throws Throwable {
        Plan plan = planFactory.create();
        plan.save();

        Plan searchPlan = new Plan();
        searchPlan.find(plan.getId());

        Assert.assertEquals(searchPlan.getId(), plan.getId());
    }

    @Test
    public void testSetName() throws Throwable {
        Plan plan = planFactory.create();

        plan.setName("Plano teste 2");
        plan.save();

        Assert.assertEquals("Plano teste 2", plan.getName());
    }

    @Test
    public void testSetDays() throws Throwable {
        Plan plan = planFactory.create();

        plan.setDays(12);
        plan.save();

        Assert.assertEquals(12,plan.getDays(),0);
    }
 
    @Test
    public void testSetAmount() throws Throwable {
        Plan plan = planFactory.create();

        plan.setAmount(200);
        plan.save();

        Assert.assertEquals(200, plan.getAmount(),0);
    }

    /*
    @Test
    public void testListPlan() throws Throwable {
        Plan plan1 = planFactory.create();
        plan1.save();

        Plan plan2 = planFactory.create();
        plan2.save();

        //There's a delay between the response and the db insertion...
        Thread.sleep(2000);
        Collection<Plan> plans = new Plan().findCollection(10, 1);
        Assert.assertEquals(2, plans.size());
    }
    */

}
@@ -1405,664 +1405,8 @@
  %7D%0A%0A
-    @Test%0A    public void testSetName() throws Throwable %7B%0A        Plan plan = planFactory.create();%0A%0A        plan.setName(%22Plano teste 2%22);%0A        plan.save();%0A%0A        Assert.assertEquals(%22Plano teste 2%22, plan.getName());%0A    %7D%0A%0A    @Test%0A    public void testSetDays() throws Throwable %7B%0A        Plan plan = planFactory.create();%0A%0A        plan.setDays(12);%0A        plan.save();%0A%0A        Assert.assertEquals(12,plan.getDays(),0);%0A    %7D%0A %0A    @Test%0A    public void testSetAmount() throws Throwable %7B%0A        Plan plan = planFactory.create();%0A%0A        plan.setAmount(200);%0A        plan.save();%0A%0A        Assert.assertEquals(200, plan.getAmount(),0);%0A    %7D%0A%0A
     

remove tests setAmount, setDays and setName