package sg.ncl.service.team;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Assert;
import org.junit.Test;
import sg.ncl.service.team.data.jpa.entities.TeamEntity;
import sg.ncl.service.team.data.jpa.repositories.TeamRepository;
import sg.ncl.service.team.domain.Team;

import javax.inject.Inject;
import java.time.ZonedDateTime;

/**
 * Created by Desmond/Te Ye
 */
public class TeamServiceTest extends AbstractTest {
    @Inject
    private TeamRepository teamRepository;

    @Test
    public void saveTeamTest() {
        TeamEntity teamEntity = new TeamEntity();

        teamEntity.setName(RandomStringUtils.randomAlphabetic(20));
        teamEntity.setDescription(RandomStringUtils.randomAlphabetic(20));
        teamEntity.setApplicationDate(ZonedDateTime.now());

        TeamService teamService = new TeamService(teamRepository);
        Team team = teamService.save(teamEntity);

        Assert.assertEquals(teamEntity.getName(), team.getName());
        Assert.assertEquals(teamEntity.getDescription(), team.getDescription());
        Assert.assertEquals(teamEntity.getApplicationDate(), team.getApplicationDate());
    }

    @Test
    public void findTeamTest() {
        TeamEntity teamEntity = new TeamEntity();

        teamEntity.setName(RandomStringUtils.randomAlphabetic(20));
        teamEntity.setDescription(RandomStringUtils.randomAlphabetic(20));
        teamEntity.setApplicationDate(ZonedDateTime.now());

        TeamService teamService = new TeamService(teamRepository);
        Team team = teamService.save(teamEntity);

        Team getTeam = teamService.find(team.getId());

        Assert.assertEquals(teamEntity.getName(), getTeam.getName());
        Assert.assertEquals(teamEntity.getDescription(), getTeam.getDescription());
        Assert.assertEquals(teamEntity.getApplicationDate(), getTeam.getApplicationDate());
    }
}

@@ -74,16 +74,79 @@
 gUtils;%0A
+import org.hamcrest.collection.IsIterableContainingInAnyOrder;%0A
 import o
@@ -407,16 +407,39 @@
 ateTime;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -635,55 +635,71 @@
 Team
-Entity teamEntity = new TeamEntity(
+Service teamService = new TeamService(teamRepository
 );%0A
-%0A
         
 team
@@ -698,318 +698,615 @@
     
-teamEntity.setName(RandomStringUtils.randomAlphabetic(20));%0A        teamEntity.setDescription(RandomStringUtils.randomAlphabetic(20));%0A        teamEntity.setApplicationDate(ZonedDateTime.now());%0A%0A        TeamService teamService = new TeamService(teamRepository);%0A        Team team = teamService.save(teamEntity
+Team createdTeam = createTeam();%0A        Team saveTeam = teamService.save(createdTeam);%0A%0A        Assert.assertEquals(createdTeam.getName(), saveTeam.getName());%0A        Assert.assertEquals(createdTeam.getDescription(), saveTeam.getDescription());%0A        Assert.assertEquals(createdTeam.getApplicationDate(), saveTeam.getApplicationDate());%0A    %7D%0A%0A    @Test%0A    public void findTeamTest() %7B%0A        TeamService teamService = new TeamService(teamRepository);%0A        Team createdTeam = new TeamEntity();%0A        Team team = teamService.save(createdTeam);%0A%0A        Team getTeam = teamService.find(team.getId()
 );%0A%0A
@@ -1329,34 +1329,35 @@
 ssertEquals(
-teamEntity
+createdTeam
 .getName(), 
@@ -1352,25 +1352,28 @@
 .getName(), 
-t
+getT
 eam.getName(
@@ -1400,34 +1400,35 @@
 ssertEquals(
-teamEntity
+createdTeam
 .getDescript
@@ -1430,25 +1430,28 @@
 cription(), 
-t
+getT
 eam.getDescr
@@ -1485,34 +1485,35 @@
 ssertEquals(
-teamEntity
+createdTeam
 .getApplicat
@@ -1523,17 +1523,20 @@
 Date(), 
-t
+getT
 eam.getA
@@ -1591,72 +1591,109 @@
 oid 
-find
+getAll
 Team
+s
 Test() 
-%7B%0A        TeamEntity teamEntity = new TeamEntity(
+throws Exception %7B%0A        TeamService teamService = new TeamService(teamRepository
 );%0A%0A
@@ -1704,151 +1704,88 @@
     
-teamEntity.setName(RandomStringUtils.randomAlphabetic(20));%0A        teamEntity.setDescription(RandomStringUtils.randomAlphabetic(20));%0A
+Team%5B%5D teamArray = new Team%5B3%5D;%0A%0A        for (int i = 0; i %3C 3; i++) %7B%0A 
         
 team
@@ -1784,136 +1784,127 @@
     
+   
 team
-Entity.setApplicationDate(ZonedDateTime.now());%0A%0A        TeamService teamService = new TeamService(teamRepository
+Array%5Bi%5D = teamService.save(createTeam());%0A        %7D%0A%0A        List%3CTeam%3E teamList = teamService.get(
 );%0A
+%0A
         
 Team
@@ -1903,135 +1903,197 @@
     
-Team team = teamService.save(teamEntity
+Assert.assertThat(teamList, IsIterableContainingInAnyOrder.containsInAnyOrder(teamArray)
 );%0A
-%0A
     
+%7D%0A%0A
     
-Team getTeam = teamService.find(team.getId());%0A%0A        Assert.assertEquals(
+private Team createTeam() %7B%0A        TeamEntity teamEntity = new TeamEntity();%0A%0A        
 team
@@ -2103,67 +2103,65 @@
 ity.
-g
+s
 etName(
-), getTeam.getName());%0A        Assert.assertEquals(
+RandomStringUtils.randomAlphabetic(20));%0A        
 team
@@ -2167,17 +2167,17 @@
 mEntity.
-g
+s
 etDescri
@@ -2186,66 +2186,57 @@
 ion(
-), getTeam.getDescription());%0A        Assert.assertEquals(
+RandomStringUtils.randomAlphabetic(20));%0A        
 team
@@ -2242,17 +2242,17 @@
 mEntity.
-g
+s
 etApplic
@@ -2265,40 +2265,56 @@
 ate(
-), getTeam.getApplicationDate())
+ZonedDateTime.now());%0A%0A        return teamEntity
 ;%0A  

Add getAllTeamsTest