/*
* 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.RaceDAO;
import cz.muni.fi.pa165.ddtroops.dto.DTOFactory;
import cz.muni.fi.pa165.ddtroops.dto.RaceDTO;
import cz.muni.fi.pa165.ddtroops.entities.EntityBuilder;
import cz.muni.fi.pa165.ddtroops.entities.Race;
import cz.muni.fi.pa165.ddtroops.serviceclasses.RaceServiceImpl;
import cz.muni.fi.pa165.ddtroops.serviceinterfaces.RaceService;
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;
/**
*
* @author Erik
*/
@RunWith(MockitoJUnitRunner.class)
@ContextConfiguration(locations = { "classpath:testAppContext.xml" })
public class RaceTest extends TestCase{
private Race race;
private RaceDTO raceDTO;
@Mock RaceDAO dao;
private RaceService service;
@Before
public void init(){
service = new RaceServiceImpl();
ReflectionTestUtils.setField(service, "dao", dao);
race = new EntityBuilder<Race>(Race.class)
.withProperty("Name", "jmeno")
.withProperty("Description", "popis")
.withProperty("Strength", (byte)(5))
.withProperty("Dexterity", (byte)(12))
.withProperty("Constitution", (byte)(3))
.withProperty("Intelligence", (byte)(1))
.withProperty("Wisdom", (byte)(5))
.withProperty("Charisma", (byte)(6))
.Build();
raceDTO = DTOFactory.createRaceDTO(race);
}
@Test
public void testCreateRace(){
service.create(raceDTO);
verify(dao).create(race);
}
@Test
public void testCreateNewRace(){
RaceDTO newRaceDTO = service.createNewRace("name", "desc", Byte.MIN_VALUE,
Byte.MIN_VALUE, Byte.MIN_VALUE, Byte.MIN_VALUE,
Byte.MIN_VALUE, Byte.MIN_VALUE);
assertNotNull(newRaceDTO);
}
@Test
public void testGetAll(){
service.create(raceDTO);
verify(dao).create(race);
service.getAll();
verify(dao).getAll();
}
}