Search in sources :

Example 11 with QuizModelEmpty

use of easytests.core.models.empty.QuizModelEmpty 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)

Example 12 with QuizModelEmpty

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

the class TesteeModelTest method testMap.

@Test
public void testMap() throws Exception {
    final Integer testeeId = 3;
    final String firstName = "FirstName";
    final String lastName = "LastName";
    final String surname = "Surname";
    final Integer groupNumber = 307;
    final Integer quizId = 5;
    final TesteeEntity testeeEntity = Mockito.mock(TesteeEntity.class);
    Mockito.when(testeeEntity.getId()).thenReturn(testeeId);
    Mockito.when(testeeEntity.getFirstName()).thenReturn(firstName);
    Mockito.when(testeeEntity.getLastName()).thenReturn(lastName);
    Mockito.when(testeeEntity.getSurname()).thenReturn(surname);
    Mockito.when(testeeEntity.getGroupNumber()).thenReturn(groupNumber);
    Mockito.when(testeeEntity.getQuizId()).thenReturn(quizId);
    final TesteeModel testeeModel = new TesteeModel();
    testeeModel.map(testeeEntity);
    Assert.assertEquals(testeeId, testeeModel.getId());
    Assert.assertEquals(firstName, testeeModel.getFirstName());
    Assert.assertEquals(lastName, testeeModel.getLastName());
    Assert.assertEquals(surname, testeeModel.getSurname());
    Assert.assertEquals(groupNumber, testeeModel.getGroupNumber());
    Assert.assertEquals(new QuizModelEmpty(quizId), testeeModel.getQuiz());
}
Also used : TesteeEntity(easytests.core.entities.TesteeEntity) QuizModelEmpty(easytests.core.models.empty.QuizModelEmpty) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 13 with QuizModelEmpty

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

QuizModelEmpty (easytests.core.models.empty.QuizModelEmpty)13 Test (org.junit.Test)7 QuestionModelEmpty (easytests.core.models.empty.QuestionModelEmpty)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 QuizModelInterface (easytests.core.models.QuizModelInterface)4 TesteeModelInterface (easytests.core.models.TesteeModelInterface)4 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)4 PointModelInterface (easytests.core.models.PointModelInterface)3 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)3 ArrayList (java.util.ArrayList)3 QuestionModelInterface (easytests.core.models.QuestionModelInterface)2 SolutionModelInterface (easytests.core.models.SolutionModelInterface)2 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)2 SolutionsServiceInterface (easytests.core.services.SolutionsServiceInterface)2 PointEntity (easytests.core.entities.PointEntity)1 TesteeEntity (easytests.core.entities.TesteeEntity)1