Search in sources :

Example 46 with QuizModelInterface

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

the class IssuesOptionsTest method testDeleteWithRelations.

@Test
public void testDeleteWithRelations() 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.deleteWithRelations(issueModel);
    inOrder.verify(quizzesService).delete(quizzesModels, quizzesOptions);
    inOrder.verify(issuesService).delete(issueModel);
}
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 47 with QuizModelInterface

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

the class PointEntityTest method testMap.

@Test
public void testMap() throws Exception {
    final Integer pointId = 3;
    final Integer questionId = 1;
    final Integer quizId = 2;
    final PointModelInterface pointModel = Mockito.mock(PointModelInterface.class);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    Mockito.when(questionModel.getId()).thenReturn(questionId);
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(quizId);
    Mockito.when(pointModel.getId()).thenReturn(pointId);
    Mockito.when(pointModel.getQuestion()).thenReturn(questionModel);
    Mockito.when(pointModel.getQuiz()).thenReturn(quizModel);
    final PointEntity pointEntity = new PointEntity();
    pointEntity.map(pointModel);
    Assert.assertEquals(pointId, pointEntity.getId());
    Assert.assertEquals(questionId, pointEntity.getQuestionId());
    Assert.assertEquals(quizId, pointEntity.getQuizId());
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) PointModelInterface(easytests.core.models.PointModelInterface) Test(org.junit.Test)

Example 48 with QuizModelInterface

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

the class TesteesOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final TesteeModelInterface testeeModelFirst = Mockito.mock(TesteeModelInterface.class);
    testeeModelFirst.setId(1);
    final TesteeModelInterface testeeModelSecond = Mockito.mock(TesteeModelInterface.class);
    testeeModelSecond.setId(2);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final Integer quizIdFirst = 3;
    final Integer quizIdSecond = 5;
    Mockito.when(testeeModelFirst.getQuiz()).thenReturn(new QuizModelEmpty(quizIdFirst));
    Mockito.when(testeeModelSecond.getQuiz()).thenReturn(new QuizModelEmpty(quizIdSecond));
    final List<TesteeModelInterface> testeesModels = new ArrayList<>(2);
    testeesModels.add(testeeModelFirst);
    testeesModels.add(testeeModelSecond);
    final TesteesOptionsInterface testeesOptions = new TesteesOptions();
    final QuizModelInterface quizModelFirst = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModelFirst.getId()).thenReturn(quizIdFirst);
    final QuizModelInterface quizModelSecond = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModelSecond.getId()).thenReturn(quizIdSecond);
    given(quizzesService.find(quizIdFirst, quizzesOptions)).willReturn(quizModelFirst);
    given(quizzesService.find(quizIdSecond, quizzesOptions)).willReturn(quizModelSecond);
    // options не заданы
    List<TesteeModelInterface> testeeModelsWithoutRelations = testeesOptions.withRelations(testeesModels);
    verify(quizzesService, times(0)).find(quizIdFirst, quizzesOptions);
    verify(quizzesService, times(0)).find(quizIdSecond, quizzesOptions);
    Assert.assertEquals(testeesModels, testeeModelsWithoutRelations);
    verify(testeeModelFirst, times(0)).setQuiz(quizModelFirst);
    verify(testeeModelSecond, times(0)).setQuiz(quizModelSecond);
    testeesOptions.setQuizzesService(quizzesService);
    testeesOptions.withQuiz(quizzesOptions);
    final List<TesteeModelInterface> testeesModelsWithRelations = testeesOptions.withRelations(testeesModels);
    verify(quizzesService, times(1)).find(quizIdFirst, quizzesOptions);
    verify(quizzesService, times(1)).find(quizIdSecond, quizzesOptions);
    Assert.assertEquals(testeesModelsWithRelations, testeesModels);
    verify(testeeModelFirst, times(1)).setQuiz(quizModelFirst);
    verify(testeeModelSecond, times(1)).setQuiz(quizModelSecond);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) QuizModelEmpty(easytests.core.models.empty.QuizModelEmpty) ArrayList(java.util.ArrayList) TesteeModelInterface(easytests.core.models.TesteeModelInterface) 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