Search in sources :

Example 11 with QuizzesServiceInterface

use of easytests.core.services.QuizzesServiceInterface in project easy-tests by malinink.

the class TesteesOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final TesteeModelInterface testeeModel = Mockito.mock(TesteeModelInterface.class);
    final TesteesOptionsInterface testeesOptions = new TesteesOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final Integer quizId = 3;
    Mockito.when(testeeModel.getQuiz()).thenReturn(new QuizModelEmpty(quizId));
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(quizId);
    given(quizzesService.find(quizId, quizzesOptions)).willReturn(quizModel);
    final TesteeModelInterface testeeModelWithoutRelations = testeesOptions.withRelations(testeeModel);
    verify(quizzesService, times(0)).find(quizId, quizzesOptions);
    Assert.assertEquals(testeeModel, testeeModelWithoutRelations);
    verify(testeeModel, times(0)).setQuiz(quizModel);
    testeesOptions.setQuizzesService(quizzesService);
    testeesOptions.withQuiz(quizzesOptions);
    final TesteeModelInterface testeeModelWithRelations = testeesOptions.withRelations(testeeModel);
    verify(quizzesService, times(1)).find(quizId, quizzesOptions);
    Assert.assertEquals(testeeModel, testeeModelWithRelations);
    verify(testeeModel, times(1)).setQuiz(quizModel);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) QuizModelEmpty(easytests.core.models.empty.QuizModelEmpty) TesteeModelInterface(easytests.core.models.TesteeModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with QuizzesServiceInterface

use of easytests.core.services.QuizzesServiceInterface 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 13 with QuizzesServiceInterface

use of easytests.core.services.QuizzesServiceInterface 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)

Example 14 with QuizzesServiceInterface

use of easytests.core.services.QuizzesServiceInterface in project easy-tests by malinink.

the class IssuesOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    issueModel.setId(1);
    given(issueModel.getSubject()).willReturn(new SubjectModelEmpty(1));
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withSubject(subjectsOptions);
    issuesOptions.withQuizzes(quizzesOptions);
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    final List<QuizModelInterface> quizzesModels = new ArrayList<>();
    quizzesModels.add(Mockito.mock(QuizModelInterface.class));
    given(subjectsService.find(issueModel.getSubject().getId(), subjectsOptions)).willReturn(subjectModel);
    given(quizzesService.findByIssue(issueModel, quizzesOptions)).willReturn(quizzesModels);
    final IssueModelInterface issueModelWithRelations = issuesOptions.withRelations(issueModel);
    Assert.assertEquals(issueModel, issueModelWithRelations);
    verify(subjectsService).find(1, subjectsOptions);
    verify(quizzesService).findByIssue(issueModel, quizzesOptions);
    verify(issueModel).setQuizzes(quizzesModels);
    verify(issueModel).setQuizzes(Mockito.anyList());
}
Also used : SubjectModelEmpty(easytests.core.models.empty.SubjectModelEmpty) QuizModelInterface(easytests.core.models.QuizModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) ArrayList(java.util.ArrayList) IssueModelInterface(easytests.core.models.IssueModelInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with QuizzesServiceInterface

use of easytests.core.services.QuizzesServiceInterface in project easy-tests by malinink.

the class PointsOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final PointModelInterface pointModelFirst = Mockito.mock(PointModelInterface.class);
    final PointModelInterface pointModelSecond = Mockito.mock(PointModelInterface.class);
    pointModelFirst.setId(1);
    pointModelSecond.setId(2);
    given(pointModelFirst.getQuiz()).willReturn(new QuizModelEmpty(1));
    given(pointModelSecond.getQuiz()).willReturn(new QuizModelEmpty(2));
    given(pointModelFirst.getQuestion()).willReturn(new QuestionModelEmpty(1));
    given(pointModelSecond.getQuestion()).willReturn(new QuestionModelEmpty(2));
    final List<PointModelInterface> pointsModels = new ArrayList<>();
    pointsModels.add(pointModelFirst);
    pointsModels.add(pointModelSecond);
    final PointsOptionsInterface pointsOptions = new PointsOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final SolutionsServiceInterface solutionsService = Mockito.mock(SolutionsServiceInterface.class);
    pointsOptions.setQuizzesService(quizzesService);
    pointsOptions.setQuestionsService(questionsService);
    pointsOptions.setSolutionsService(solutionsService);
    final QuizzesOptionsInterface quizOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final QuestionsOptionsInterface questionOptions = Mockito.mock(QuestionsOptionsInterface.class);
    final SolutionsOptionsInterface solutionsOptions = Mockito.mock(SolutionsOptionsInterface.class);
    pointsOptions.withQuiz(quizOptions);
    pointsOptions.withQuestion(questionOptions);
    pointsOptions.withSolutions(solutionsOptions);
    final QuizModelInterface quizModelFirst = Mockito.mock(QuizModelInterface.class);
    final QuizModelInterface quizModelSecond = Mockito.mock(QuizModelInterface.class);
    given(quizzesService.find(1, quizOptions)).willReturn(quizModelFirst);
    given(quizzesService.find(2, quizOptions)).willReturn(quizModelSecond);
    final QuestionModelInterface questionModelFirst = Mockito.mock(QuestionModelInterface.class);
    final QuestionModelInterface questionModelSecond = Mockito.mock(QuestionModelInterface.class);
    given(questionsService.find(1, questionOptions)).willReturn(questionModelFirst);
    given(questionsService.find(2, questionOptions)).willReturn(questionModelSecond);
    final List<SolutionModelInterface> solutionsModelsFirst = new ArrayList<>();
    solutionsModelsFirst.add(Mockito.mock(SolutionModelInterface.class));
    final List<SolutionModelInterface> solutionsModelsSecond = new ArrayList<>();
    solutionsModelsSecond.add(Mockito.mock(SolutionModelInterface.class));
    solutionsModelsSecond.add(Mockito.mock(SolutionModelInterface.class));
    given(solutionsService.findByPoint(pointModelFirst, solutionsOptions)).willReturn(solutionsModelsFirst);
    given(solutionsService.findByPoint(pointModelSecond, solutionsOptions)).willReturn(solutionsModelsSecond);
    final List<PointModelInterface> pointsModelsWithRelations = pointsOptions.withRelations(pointsModels);
    Assert.assertEquals(pointsModels, pointsModelsWithRelations);
    verify(quizzesService).find(1, quizOptions);
    verify(questionsService).find(1, questionOptions);
    verify(solutionsService).findByPoint(pointModelFirst, solutionsOptions);
    verify(pointsModels.get(0)).setQuiz(quizModelFirst);
    verify(pointsModels.get(0)).setQuestion(questionModelFirst);
    verify(pointsModels.get(0)).setSolutions(solutionsModelsFirst);
    verify(pointsModels.get(0)).setSolutions(Mockito.anyList());
    verify(quizzesService).find(2, quizOptions);
    verify(questionsService).find(2, questionOptions);
    verify(solutionsService).findByPoint(pointModelSecond, solutionsOptions);
    verify(pointsModels.get(1)).setQuiz(quizModelSecond);
    verify(pointsModels.get(1)).setQuestion(questionModelSecond);
    verify(pointsModels.get(1)).setSolutions(solutionsModelsSecond);
    verify(pointsModels.get(1)).setSolutions(Mockito.anyList());
}
Also used : SolutionModelInterface(easytests.core.models.SolutionModelInterface) QuestionModelEmpty(easytests.core.models.empty.QuestionModelEmpty) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) PointModelInterface(easytests.core.models.PointModelInterface) QuizModelInterface(easytests.core.models.QuizModelInterface) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuizModelEmpty(easytests.core.models.empty.QuizModelEmpty) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) SolutionsServiceInterface(easytests.core.services.SolutionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)19 Test (org.junit.Test)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 QuizModelInterface (easytests.core.models.QuizModelInterface)15 ArrayList (java.util.ArrayList)11 PointModelInterface (easytests.core.models.PointModelInterface)8 InOrder (org.mockito.InOrder)8 TesteeModelInterface (easytests.core.models.TesteeModelInterface)7 IssueModelInterface (easytests.core.models.IssueModelInterface)5 PointsServiceInterface (easytests.core.services.PointsServiceInterface)5 SolutionsServiceInterface (easytests.core.services.SolutionsServiceInterface)5 SolutionModelInterface (easytests.core.models.SolutionModelInterface)4 QuizModelEmpty (easytests.core.models.empty.QuizModelEmpty)4 TesteesServiceInterface (easytests.core.services.TesteesServiceInterface)4 IssuesServiceInterface (easytests.core.services.IssuesServiceInterface)3 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)3 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)3 QuestionModelInterface (easytests.core.models.QuestionModelInterface)2 SubjectModelInterface (easytests.core.models.SubjectModelInterface)2 QuestionModelEmpty (easytests.core.models.empty.QuestionModelEmpty)2