Search in sources :

Example 26 with QuizModelInterface

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

the class TesteesOptionsTest method testSaveWithRelations.

@Test
public void testSaveWithRelations() throws Exception {
    final TesteeModelInterface testeeModel = Mockito.mock(TesteeModelInterface.class);
    final TesteesOptionsInterface testeesOptions = new TesteesOptions();
    final TesteesServiceInterface testeesService = Mockito.mock(TesteesServiceInterface.class);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final Integer quizId = 3;
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(quizId);
    Mockito.when(testeeModel.getQuiz()).thenReturn(quizModel);
    testeesOptions.setTesteesService(testeesService);
    testeesOptions.setQuizzesService(quizzesService);
    testeesOptions.withQuiz(quizzesOptions);
    final InOrder inOrder = Mockito.inOrder(quizzesService, testeesService);
    testeesOptions.saveWithRelations(testeeModel);
    inOrder.verify(quizzesService, times(1)).save(testeeModel.getQuiz(), quizzesOptions);
    inOrder.verify(testeesService, times(1)).save(testeeModel);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) InOrder(org.mockito.InOrder) TesteesServiceInterface(easytests.core.services.TesteesServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) TesteeModelInterface(easytests.core.models.TesteeModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 27 with QuizModelInterface

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

the class TesteesOptionsTest method testDeleteWithRelations.

@Test
public void testDeleteWithRelations() throws Exception {
    final TesteeModelInterface testeeModel = Mockito.mock(TesteeModelInterface.class);
    final TesteesOptionsInterface testeesOptions = new TesteesOptions();
    final TesteesServiceInterface testeesService = Mockito.mock(TesteesServiceInterface.class);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final Integer quizId = 3;
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(quizId);
    Mockito.when(testeeModel.getQuiz()).thenReturn(quizModel);
    testeesOptions.setTesteesService(testeesService);
    testeesOptions.setQuizzesService(quizzesService);
    testeesOptions.withQuiz(quizzesOptions);
    final InOrder inOrder = Mockito.inOrder(quizzesService, testeesService);
    testeesOptions.deleteWithRelations(testeeModel);
    inOrder.verify(quizzesService, times(1)).delete(testeeModel.getQuiz(), quizzesOptions);
    inOrder.verify(testeesService, times(1)).delete(testeeModel);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) InOrder(org.mockito.InOrder) TesteesServiceInterface(easytests.core.services.TesteesServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) TesteeModelInterface(easytests.core.models.TesteeModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 28 with QuizModelInterface

use of easytests.core.models.QuizModelInterface 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 29 with QuizModelInterface

use of easytests.core.models.QuizModelInterface 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 30 with QuizModelInterface

use of easytests.core.models.QuizModelInterface 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

QuizModelInterface (easytests.core.models.QuizModelInterface)48 Test (org.junit.Test)42 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)42 ArrayList (java.util.ArrayList)17 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)15 IssueModelInterface (easytests.core.models.IssueModelInterface)11 PointModelInterface (easytests.core.models.PointModelInterface)11 TesteeModelInterface (easytests.core.models.TesteeModelInterface)11 QuizzesOptionsInterface (easytests.core.options.QuizzesOptionsInterface)9 InOrder (org.mockito.InOrder)8 QuizEntity (easytests.core.entities.QuizEntity)7 PointsServiceInterface (easytests.core.services.PointsServiceInterface)7 TesteesServiceInterface (easytests.core.services.TesteesServiceInterface)7 IssuesServiceInterface (easytests.core.services.IssuesServiceInterface)6 SolutionModelInterface (easytests.core.models.SolutionModelInterface)4 IssueModelEmpty (easytests.core.models.empty.IssueModelEmpty)4 QuizModelEmpty (easytests.core.models.empty.QuizModelEmpty)4 SolutionsServiceInterface (easytests.core.services.SolutionsServiceInterface)4 QuestionModelInterface (easytests.core.models.QuestionModelInterface)3 QuizModel (easytests.core.models.QuizModel)2