Search in sources :

Example 6 with Participation

use of com.viadee.sonarQuest.entities.Participation in project sonarQuest by viadee.

the class QuestServiceTest method testGetAllQuestsForWorldAndDeveloper.

@Test
public void testGetAllQuestsForWorldAndDeveloper() {
    // create mock developer
    final Developer mockDeveloper = new Developer();
    mockDeveloper.setUsername("mock");
    // create mock world
    final World mockWorld = new World();
    // create mock quests
    final Quest mockQuest1 = new Quest();
    final Quest mockQuest2 = new Quest();
    final Quest mockQuest3 = new Quest();
    mockQuest1.setTitle("mockQuest1");
    mockQuest2.setTitle("mockQuest2");
    mockQuest3.setTitle("mockQuest3");
    mockQuest1.setWorld(mockWorld);
    mockQuest2.setWorld(mockWorld);
    mockQuest3.setWorld(mockWorld);
    final List<Quest> mockQuests = new ArrayList<>();
    mockQuests.add(mockQuest1);
    mockQuests.add(mockQuest2);
    mockQuests.add(mockQuest3);
    // create mock participations
    final Participation mockParticipation1 = new Participation(mockQuest1, mockDeveloper);
    final Participation mockParticipation2 = new Participation(mockQuest2, mockDeveloper);
    final List<Participation> mockParticipations = new ArrayList<>();
    mockParticipations.add(mockParticipation1);
    mockParticipations.add(mockParticipation2);
    // init mock repos
    when(participationRepository.findByDeveloper(mockDeveloper)).thenReturn(mockParticipations);
    when(questRepository.findByWorld(mockWorld)).thenReturn(mockQuests);
    // call method to be tested
    final List<List<Quest>> result = questService.getAllQuestsForWorldAndDeveloper(mockWorld, mockDeveloper);
    // verify result
    assertTrue(result.get(0).contains(mockQuest1));
    assertTrue(result.get(0).contains(mockQuest2));
    assertTrue(result.get(1).contains(mockQuest3));
}
Also used : Participation(com.viadee.sonarQuest.entities.Participation) ArrayList(java.util.ArrayList) Developer(com.viadee.sonarQuest.entities.Developer) ArrayList(java.util.ArrayList) List(java.util.List) World(com.viadee.sonarQuest.entities.World) Quest(com.viadee.sonarQuest.entities.Quest) Test(org.junit.Test)

Aggregations

Participation (com.viadee.sonarQuest.entities.Participation)6 Developer (com.viadee.sonarQuest.entities.Developer)4 Quest (com.viadee.sonarQuest.entities.Quest)4 Task (com.viadee.sonarQuest.entities.Task)2 Test (org.junit.Test)2 SpecialTask (com.viadee.sonarQuest.entities.SpecialTask)1 World (com.viadee.sonarQuest.entities.World)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1