Package cz.muni.fi.pa165.ddtroops.business

Source Code of cz.muni.fi.pa165.ddtroops.business.SkillTest

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cz.muni.fi.pa165.ddtroops.business;

import cz.muni.fi.pa165.ddtroops.daointerfaces.SkillDAO;
import cz.muni.fi.pa165.ddtroops.dto.DTOFactory;
import cz.muni.fi.pa165.ddtroops.dto.SkillDTO;
import cz.muni.fi.pa165.ddtroops.entities.EntityBuilder;
import cz.muni.fi.pa165.ddtroops.entities.Skill;
import cz.muni.fi.pa165.ddtroops.serviceclasses.SkillServiceImpl;
import cz.muni.fi.pa165.ddtroops.serviceinterfaces.SkillService;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.*;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.annotation.Transactional;

/**
*
* @author Erik
*/
@RunWith(MockitoJUnitRunner.class)
@ContextConfiguration(locations = { "classpath:testAppContext.xml" })
@Transactional
public class SkillTest extends TestCase{

    private Skill skill;
    private SkillDTO skillDTO;
    @Mock SkillDAO mockDao;
    private SkillService ss;
    @Before
    public void init(){
        ss = new SkillServiceImpl();
        ReflectionTestUtils.setField(ss, "dao", mockDao);
        skill = new EntityBuilder<Skill>(Skill.class)
                .withProperty("Name", "Umeni vetru")
                .withProperty("Description", "nejsilnejsi kouzlisko")
                .withProperty("Profession", "cockokneznik")
                .withProperty("minXP", 0L)
                .Build();
        skillDTO = DTOFactory.createSkillDTO(skill);
    }
    @Test
    public void testAddSkill(){
        ss.create(skillDTO);
        verify(mockDao).create(skill);

    }
    @Test
    public void testRemoveSkill(){
        ss.create(skillDTO);
        verify(mockDao).create(skill);
        ss.delete(skillDTO);
        verify(mockDao).delete(skill);
    }

    @Test
    public void testGetById(){
        ss.create(skillDTO);
        verify(mockDao).create(skill);
        ss.getById(skill.getId());
        verify(mockDao).getById(skill.getId());
    }

    @Test
    public void testGetAll(){
        Skill skill2 = new EntityBuilder<Skill>(Skill.class)
                .withProperty("Name", "Umeni ohne")
                .withProperty("Description", "druhe nejsilnejsi kouzlisko")
                .withProperty("Profession", "RUMburak")
                .withProperty("minXP", 0L)
                .Build();
        ss.create(skillDTO);
        ss.create(DTOFactory.createSkillDTO(skill2));
        ss.getAll();
        verify(mockDao).getAll();
    }

}
TOP

Related Classes of cz.muni.fi.pa165.ddtroops.business.SkillTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.