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

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

/*
* 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.SquadDAO;
import cz.muni.fi.pa165.ddtroops.dto.DTOFactory;
import cz.muni.fi.pa165.ddtroops.dto.SquadDTO;
import cz.muni.fi.pa165.ddtroops.entities.EntityBuilder;
import cz.muni.fi.pa165.ddtroops.entities.Gender;
import cz.muni.fi.pa165.ddtroops.entities.Hero;
import cz.muni.fi.pa165.ddtroops.entities.Race;
import cz.muni.fi.pa165.ddtroops.entities.Skill;
import cz.muni.fi.pa165.ddtroops.entities.Squad;
import cz.muni.fi.pa165.ddtroops.entities.User;
import cz.muni.fi.pa165.ddtroops.serviceclasses.SquadServiceImpl;
import cz.muni.fi.pa165.ddtroops.serviceinterfaces.SquadService;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Mockito.*;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.util.ReflectionTestUtils;

/**
*
* @author Erik
*/
@RunWith(MockitoJUnitRunner.class)
@ContextConfiguration(locations = { "classpath:testAppContext.xml" })
public class SquadTest extends TestCase
{
    private Squad squad;
    private SquadDTO squadDTO;
    @Mock SquadDAO dao;
    private SquadService service;
    @Before
    public void init(){
        service = new SquadServiceImpl();
        ReflectionTestUtils.setField(service, "dao", dao);
        Hero member = new Hero();
        member.setRace(mock(Race.class));
        member.setUser(mock(User.class));
        List<Hero> members = new ArrayList<Hero>();
        members.add(member);
        squad = new EntityBuilder<Squad>(Squad.class)
                .withProperty("Name", "suprKluci")
                .withProperty("Description", "nazev vse rika")
                .withProperty("Task", "")
                .withProperty("Members", members)
                .withProperty("Leader", member)
                .withProperty("Gold", 0L)
                .Build();
        squadDTO = DTOFactory.createSquadDTO(squad);
    }
    @Test
    public void testCreateSquad(){
        service.create(squadDTO);
        verify(dao).create(squad);
        verifyNoMoreInteractions(dao);
    }
    @Test
    public void testUpdateSquad(){
        service.create(squadDTO);
        verify(dao).create(squad);
        service.update(squadDTO);
        verify(dao).update(squad);
        verifyNoMoreInteractions(dao);
    }
    @Test
    public void testDeleteSquad(){
        service.create(squadDTO);
        verify(dao).create(squad);
        service.delete(squadDTO);
        verify(dao).delete(squad);
        verifyNoMoreInteractions(dao);
    }
    @Test
    public void testGetByName(){
        service.create(squadDTO);
        verify(dao).create(squad);
        service.getByName(squad.getName());
        verify(dao).getAll();
        verifyNoMoreInteractions(dao);
    }
    @Test
    public void testGetById(){
        service.create(squadDTO);
        verify(dao).create(squad);
        service.getById(squad.getId());
        verify(dao).getById(squad.getId());
        verifyNoMoreInteractions(dao);
    }
    @Test
    public void testGetAll(){
        service.create(squadDTO);
        verify(dao).create(squad);
        service.getAll();
        verify(dao).getAll();
        verifyNoMoreInteractions(dao);
    }

    public Race getRace(){
        Race race = new Race();
        race.setName("SimpleRace");
        race.setDescription("Descript");
        race.setStrength(new Byte("61"));
        race.setDexterity(new Byte("61"));
        race.setConstitution(new Byte("15"));
        race.setIntelligence(new Byte("51"));
        race.setWisdom(new Byte("41"));
        race.setCharisma(new Byte("14"));
        return race;
    }

    public Hero getHero(Race race, Skill skill){
        Hero leader = new Hero();
        leader.setName("Híro");
        leader.setGender(Gender.MALE);
        leader.setBelief("althurist");
        leader.setProfession("Gunter");
        leader.setRace(race);
        leader.setStrength(Byte.MIN_VALUE);
        leader.setDexterity(Byte.MIN_VALUE);
        leader.setConstitution(Byte.MIN_VALUE);
        leader.setIntelligence(Byte.MIN_VALUE);
        leader.setStrength(Byte.MIN_VALUE);
        leader.setWisdom(Byte.MIN_VALUE);
        leader.setCharisma(Byte.MIN_VALUE);
        leader.addSkill(skill);
        leader.setXp(500L);

        return leader;
    }

    public Skill getSkill(){
    Skill skill = new Skill();
        skill.setDescription("Skillerx");
        skill.setName("DescSkillerx");
        skill.setMinXP(50L);
        skill.setProfession("Proff");
        return skill;
    }


}
TOP

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

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.