package org.tiatus.service;

import mockit.Mock;
import mockit.MockUp;
import org.junit.Test;
import org.tiatus.dao.DaoException;
import org.tiatus.dao.RaceDaoImpl;
import org.tiatus.entity.Race;

/**
 * Created by johnreynolds on 14/09/2016.
 */
public class RaceServiceImplTest {

    @Test
    public void testConstructor() {
        RaceServiceImpl service = new RaceServiceImpl(new RaceDaoImpl());
    }

    @Test
    public void testAddRace() throws Exception {
        new MockUp<RaceDaoImpl>() {
            @Mock
            Race addRace(Race race) throws DaoException {
                return race;
            }
        };
        RaceServiceImpl service = new RaceServiceImpl(new RaceDaoImpl());
        Race race = new Race();
        service.addRace(race);
    }

    @Test (expected = ServiceException.class)
    public void testAddRaceExcepton() throws Exception {
        new MockUp<RaceDaoImpl>() {
            @Mock
            Race addRace(Race race) throws DaoException {
                throw new DaoException("message");
            }
        };
        RaceServiceImpl service = new RaceServiceImpl(new RaceDaoImpl());
        Race race = new Race();
        service.addRace(race);
    }

    @Test
    public void testDeleteRace() throws Exception {
        RaceServiceImpl service = new RaceServiceImpl(new RaceDaoImpl());
        Race race = new Race();
        service.deleteRace(race);
    }
}

@@ -190,16 +190,68 @@
 .Race;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * C
@@ -1466,11 +1466,569 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testGetRaces() throws Exception %7B%0A        new MockUp%3CRaceDaoImpl%3E() %7B%0A            @Mock%0A            public List%3CRace%3E getRaces() %7B%0A                List%3CRace%3E races = new ArrayList%3C%3E();%0A                Race race = new Race();%0A                race.setId(1L);%0A                race.setRaceOrder(1);%0A                race.setName(%22Race 1%22);%0A                races.add(race);%0A                return races;%0A            %7D%0A        %7D;%0A        RaceServiceImpl service = new RaceServiceImpl(new RaceDaoImpl());%0A        service.getRaces();%0A    %7D
 %0A%7D%0A

Copy race for ghorr.