Search in sources :

Example 1 with IssueModelInterface

use of easytests.core.models.IssueModelInterface in project easy-tests by malinink.

the class QuizzesServiceTest method testFindByIssuePresentList.

@Test
public void testFindByIssuePresentList() throws Exception {
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    final List<QuizEntity> quizzesEntities = this.getQuizzesFixturesEntities();
    when(this.quizzesMapper.findByIssueId(issueModel.getId())).thenReturn(quizzesEntities);
    final List<QuizModelInterface> quizzesModels = this.getQuizzesFixturesModels();
    final List<QuizModelInterface> quizzesFoundedModels = this.quizzesService.findByIssue(issueModel);
    this.quizzesSupport.assertModelsListEquals(quizzesModels, quizzesFoundedModels);
}
Also used : QuizEntity(easytests.core.entities.QuizEntity) QuizModelInterface(easytests.core.models.QuizModelInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with IssueModelInterface

use of easytests.core.models.IssueModelInterface in project easy-tests by malinink.

the class QuizzesServiceTest method testFindByIssueAbsentList.

@Test
public void testFindByIssueAbsentList() throws Exception {
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    when(this.quizzesMapper.findByIssueId(issueModel.getId())).thenReturn(new ArrayList<>(0));
    final List<QuizModelInterface> quizzesFoundedModels = this.quizzesService.findByIssue(issueModel);
    Assert.assertEquals(0, quizzesFoundedModels.size());
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with IssueModelInterface

use of easytests.core.models.IssueModelInterface in project easy-tests by malinink.

the class QuizzesOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final QuizModelInterface quizModelFirst = Mockito.mock(QuizModelInterface.class);
    quizModelFirst.setId(1);
    given(quizModelFirst.getIssue()).willReturn(new IssueModelEmpty(1));
    final QuizModelInterface quizModelSecond = Mockito.mock(QuizModelInterface.class);
    quizModelSecond.setId(2);
    given(quizModelSecond.getIssue()).willReturn(new IssueModelEmpty(2));
    final List<QuizModelInterface> quizzesModels = new ArrayList<>(2);
    quizzesModels.add(quizModelFirst);
    quizzesModels.add(quizModelSecond);
    final QuizzesOptionsInterface quizzesOptions = new QuizzesOptions();
    final TesteesServiceInterface testeesService = Mockito.mock(TesteesServiceInterface.class);
    final TesteesOptionsInterface testeesOptions = Mockito.mock(TesteesOptionsInterface.class);
    final PointsServiceInterface pointsService = Mockito.mock(PointsServiceInterface.class);
    final PointsOptionsInterface pointsOptions = Mockito.mock(PointsOptionsInterface.class);
    final IssuesServiceInterface issuesService = Mockito.mock(IssuesServiceInterface.class);
    final IssuesOptionsInterface issueOptions = Mockito.mock(IssuesOptionsInterface.class);
    quizzesOptions.setTesteesService(testeesService);
    quizzesOptions.setPointsService(pointsService);
    quizzesOptions.setIssuesService(issuesService);
    quizzesOptions.withTestee(testeesOptions);
    quizzesOptions.withPoints(pointsOptions);
    quizzesOptions.withIssue(issueOptions);
    final List<PointModelInterface> pointsModelsFirst = new ArrayList<>();
    pointsModelsFirst.add(Mockito.mock(PointModelInterface.class));
    final List<PointModelInterface> pointsModelsSecond = new ArrayList<>();
    pointsModelsSecond.add(Mockito.mock(PointModelInterface.class));
    pointsModelsSecond.add(Mockito.mock(PointModelInterface.class));
    given(pointsService.findByQuiz(quizModelFirst, pointsOptions)).willReturn(pointsModelsFirst);
    given(pointsService.findByQuiz(quizModelSecond, pointsOptions)).willReturn(pointsModelsSecond);
    final IssueModelInterface issueModelFirst = Mockito.mock(IssueModelInterface.class);
    final IssueModelInterface issueModelSecond = Mockito.mock(IssueModelInterface.class);
    given(issuesService.find(1, issueOptions)).willReturn(issueModelFirst);
    given(issuesService.find(2, issueOptions)).willReturn(issueModelSecond);
    final TesteeModelInterface testeeModelFirst = Mockito.mock(TesteeModelInterface.class);
    final TesteeModelInterface testeeModelSecond = Mockito.mock(TesteeModelInterface.class);
    given(testeesService.findByQuiz(quizModelFirst, testeesOptions)).willReturn(testeeModelFirst);
    given(testeesService.findByQuiz(quizModelSecond, testeesOptions)).willReturn(testeeModelSecond);
    final List<QuizModelInterface> quizzesModelsWithRelations = quizzesOptions.withRelations(quizzesModels);
    Assert.assertEquals(quizzesModelsWithRelations, quizzesModels);
    verify(testeesService).findByQuiz(quizModelFirst, testeesOptions);
    verify(pointsService).findByQuiz(quizModelFirst, pointsOptions);
    verify(issuesService).find(1, issueOptions);
    verify(quizzesModels.get(0)).setPoints(pointsModelsFirst);
    verify(quizzesModels.get(0)).setPoints(Mockito.anyList());
    verify(quizzesModels.get(0)).setIssue(issueModelFirst);
    verify(quizzesModels.get(0)).setTestee(testeeModelFirst);
    verify(testeesService).findByQuiz(quizModelSecond, testeesOptions);
    verify(pointsService).findByQuiz(quizModelSecond, pointsOptions);
    verify(issuesService).find(2, issueOptions);
    verify(quizzesModels.get(1)).setPoints(pointsModelsSecond);
    verify(quizzesModels.get(1)).setPoints(Mockito.anyList());
    verify(quizzesModels.get(1)).setIssue(issueModelSecond);
    verify(quizzesModels.get(1)).setTestee(testeeModelSecond);
}
Also used : IssuesServiceInterface(easytests.core.services.IssuesServiceInterface) ArrayList(java.util.ArrayList) PointModelInterface(easytests.core.models.PointModelInterface) IssueModelEmpty(easytests.core.models.empty.IssueModelEmpty) QuizModelInterface(easytests.core.models.QuizModelInterface) PointsServiceInterface(easytests.core.services.PointsServiceInterface) TesteesServiceInterface(easytests.core.services.TesteesServiceInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) TesteeModelInterface(easytests.core.models.TesteeModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with IssueModelInterface

use of easytests.core.models.IssueModelInterface in project easy-tests by malinink.

the class IssuesOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final IssueModelInterface issueModelFirst = Mockito.mock(IssueModelInterface.class);
    issueModelFirst.setId(1);
    given(issueModelFirst.getSubject()).willReturn(new SubjectModelEmpty(1));
    final IssueModelInterface issueModelSecond = Mockito.mock(IssueModelInterface.class);
    issueModelSecond.setId(2);
    given(issueModelSecond.getSubject()).willReturn(new SubjectModelEmpty(2));
    final List<IssueModelInterface> issuesModels = new ArrayList<>(2);
    issuesModels.add(issueModelFirst);
    issuesModels.add(issueModelSecond);
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withSubject(subjectsOptions);
    issuesOptions.withQuizzes(quizzesOptions);
    final List<QuizModelInterface> quizzesModelsFirst = new ArrayList<>();
    quizzesModelsFirst.add(Mockito.mock(QuizModelInterface.class));
    final List<QuizModelInterface> quizzesModelsSecond = new ArrayList<>();
    quizzesModelsSecond.add(Mockito.mock(QuizModelInterface.class));
    quizzesModelsSecond.add(Mockito.mock(QuizModelInterface.class));
    given(quizzesService.findByIssue(issueModelFirst, quizzesOptions)).willReturn(quizzesModelsFirst);
    given(quizzesService.findByIssue(issueModelSecond, quizzesOptions)).willReturn(quizzesModelsSecond);
    final SubjectModelInterface subjectModelFirst = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelSecond = Mockito.mock(SubjectModelInterface.class);
    given(subjectsService.find(1, subjectsOptions)).willReturn(subjectModelFirst);
    given(subjectsService.find(2, subjectsOptions)).willReturn(subjectModelSecond);
    final List<IssueModelInterface> issuesModelsWithRelations = issuesOptions.withRelations(issuesModels);
    Assert.assertEquals(issuesModelsWithRelations, issuesModels);
    verify(quizzesService).findByIssue(issueModelFirst, quizzesOptions);
    verify(subjectsService).find(1, subjectsOptions);
    verify(issuesModels.get(0)).setQuizzes(quizzesModelsFirst);
    verify(issuesModels.get(0)).setQuizzes(Mockito.anyList());
    verify(issuesModels.get(0)).setSubject(subjectModelFirst);
    verify(quizzesService).findByIssue(issueModelSecond, quizzesOptions);
    verify(subjectsService).find(2, subjectsOptions);
    verify(issuesModels.get(1)).setQuizzes(quizzesModelsSecond);
    verify(issuesModels.get(1)).setQuizzes(Mockito.anyList());
    verify(issuesModels.get(1)).setSubject(subjectModelSecond);
}
Also used : SubjectModelEmpty(easytests.core.models.empty.SubjectModelEmpty) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with IssueModelInterface

use of easytests.core.models.IssueModelInterface in project easy-tests by malinink.

the class IssuesOptionsTest method testSaveWithRelations.

@Test
public void testSaveWithRelations() throws Exception {
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final IssuesServiceInterface issuesService = Mockito.mock(IssuesServiceInterface.class);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    issuesOptions.setIssuesService(issuesService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withQuizzes(quizzesOptions);
    final List<QuizModelInterface> quizzesModels = new ArrayList<>();
    quizzesModels.add(Mockito.mock(QuizModelInterface.class));
    given(issueModel.getQuizzes()).willReturn(quizzesModels);
    final InOrder inOrder = Mockito.inOrder(quizzesService, issuesService);
    issuesOptions.saveWithRelations(issueModel);
    inOrder.verify(issuesService).save(issueModel);
    inOrder.verify(quizzesService).save(quizzesModels, quizzesOptions);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) InOrder(org.mockito.InOrder) IssuesServiceInterface(easytests.core.services.IssuesServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) ArrayList(java.util.ArrayList) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

IssueModelInterface (easytests.core.models.IssueModelInterface)32 Test (org.junit.Test)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 QuizModelInterface (easytests.core.models.QuizModelInterface)11 ArrayList (java.util.ArrayList)11 IssueEntity (easytests.core.entities.IssueEntity)6 IssuesOptionsInterface (easytests.core.options.IssuesOptionsInterface)6 IssuesServiceInterface (easytests.core.services.IssuesServiceInterface)5 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)5 SubjectModelInterface (easytests.core.models.SubjectModelInterface)4 SubjectModelEmpty (easytests.core.models.empty.SubjectModelEmpty)4 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)4 QuizEntity (easytests.core.entities.QuizEntity)3 IssueModel (easytests.core.models.IssueModel)3 PointModelInterface (easytests.core.models.PointModelInterface)2 TesteeModelInterface (easytests.core.models.TesteeModelInterface)2 IssueModelEmpty (easytests.core.models.empty.IssueModelEmpty)2 PointsServiceInterface (easytests.core.services.PointsServiceInterface)2 TesteesServiceInterface (easytests.core.services.TesteesServiceInterface)2 InOrder (org.mockito.InOrder)2