Search in sources :

Example 1 with QuestionsServiceInterface

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

the class TopicsOptionsTest method testWithRelationsQuestionsOnSingleModel.

@Test
public void testWithRelationsQuestionsOnSingleModel() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.setTopicsService(topicsService);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    questionsModels.add(Mockito.mock(QuestionModelInterface.class));
    given(questionsService.findByTopic(topicModel, questionsOptions)).willReturn(questionsModels);
    final TopicModelInterface topicModelWithRelations = topicsOptions.withRelations(topicModel);
    Assert.assertEquals(topicModel, topicModelWithRelations);
    verify(questionsService).findByTopic(topicModel, questionsOptions);
    verify(topicModel).setQuestions(questionsModels);
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) ArrayList(java.util.ArrayList) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with QuestionsServiceInterface

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

the class TopicsOptionsTest method testDeleteWithRelationsQuestion.

@Test
public void testDeleteWithRelationsQuestion() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.setTopicsService(topicsService);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    topicModel.setQuestions(questionsModels);
    final InOrder inOrder = Mockito.inOrder(questionsService, topicsService);
    topicsOptions.deleteWithRelations(topicModel);
    inOrder.verify(questionsService).save(topicModel.getQuestions(), questionsOptions);
    inOrder.verify(topicsService).delete(topicModel);
}
Also used : InOrder(org.mockito.InOrder) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) ArrayList(java.util.ArrayList) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with QuestionsServiceInterface

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

the class PointsOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final PointModelInterface pointModel = Mockito.mock(PointModelInterface.class);
    final PointsOptionsInterface pointsOptions = new PointsOptions();
    pointModel.setId(1);
    given(pointModel.getQuiz()).willReturn(new QuizModelEmpty(1));
    given(pointModel.getQuestion()).willReturn(new QuestionModelEmpty(1));
    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 quizModel = Mockito.mock(QuizModelInterface.class);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    final List<SolutionModelInterface> solutionsModels = new ArrayList<>();
    solutionsModels.add(Mockito.mock(SolutionModelInterface.class));
    given(quizzesService.find(pointModel.getQuiz().getId(), quizOptions)).willReturn(quizModel);
    given(questionsService.find(pointModel.getQuestion().getId(), questionOptions)).willReturn(questionModel);
    given(solutionsService.findByPoint(pointModel, solutionsOptions)).willReturn(solutionsModels);
    final PointModelInterface pointModelWithRelations = pointsOptions.withRelations(pointModel);
    Assert.assertEquals(pointModel, pointModelWithRelations);
    verify(quizzesService).find(1, quizOptions);
    verify(questionsService).find(1, questionOptions);
    verify(solutionsService).findByPoint(pointModel, solutionsOptions);
    verify(pointModel).setQuiz(quizModel);
    verify(pointModel).setQuestion(questionModel);
    verify(pointModel).setSolutions(solutionsModels);
}
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 4 with QuestionsServiceInterface

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

the class PointsOptionsTest method testWithRelationsOnNull.

@Test
public void testWithRelationsOnNull() throws Exception {
    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).withQuestion(questionOptions).withSolutions(solutionsOptions);
    final PointModelInterface nullPointModel = null;
    final PointModelInterface pointModelWithRelations = pointsOptions.withRelations(nullPointModel);
    Assert.assertNull(pointModelWithRelations);
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) PointModelInterface(easytests.core.models.PointModelInterface) SolutionsServiceInterface(easytests.core.services.SolutionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with QuestionsServiceInterface

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

the class QuestionsOptionsTest method testDeleteWithRelations.

@Test
public void testDeleteWithRelations() throws Exception {
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    final QuestionsOptionsInterface questionsOptions = new QuestionsOptions();
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final AnswersServiceInterface answersService = Mockito.mock(AnswersServiceInterface.class);
    final AnswersOptionsInterface answersOptions = Mockito.mock(AnswersOptionsInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final TopicsOptionsInterface topicsOptions = Mockito.mock(TopicsOptionsInterface.class);
    questionsOptions.setQuestionsService(questionsService);
    questionsOptions.setAnswersService(answersService);
    questionsOptions.withAnswers(answersOptions);
    questionsOptions.setTopicsService(topicsService);
    questionsOptions.withTopic(topicsOptions);
    final List<AnswerModelInterface> answersModels = new ArrayList<>();
    answersModels.add(Mockito.mock(AnswerModelInterface.class));
    TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    given(questionModel.getAnswers()).willReturn(answersModels);
    given(questionModel.getTopic()).willReturn(topicModel);
    final InOrder inOrder = Mockito.inOrder(answersService, questionsService, topicsService);
    questionsOptions.deleteWithRelations(questionModel);
    inOrder.verify(answersService).delete(answersModels, answersOptions);
    inOrder.verify(questionsService).delete(questionModel);
    inOrder.verify(topicsService).delete(topicModel, topicsOptions);
}
Also used : InOrder(org.mockito.InOrder) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) AnswersServiceInterface(easytests.core.services.AnswersServiceInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) AnswerModelInterface(easytests.core.models.AnswerModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)14 Test (org.junit.Test)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 ArrayList (java.util.ArrayList)10 QuestionModelInterface (easytests.core.models.QuestionModelInterface)9 TopicModelInterface (easytests.core.models.TopicModelInterface)7 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)7 QuestionModelEmpty (easytests.core.models.empty.QuestionModelEmpty)4 InOrder (org.mockito.InOrder)4 PointModelInterface (easytests.core.models.PointModelInterface)3 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)3 SolutionsServiceInterface (easytests.core.services.SolutionsServiceInterface)3 AnswerModelInterface (easytests.core.models.AnswerModelInterface)2 QuizModelInterface (easytests.core.models.QuizModelInterface)2 SolutionModelInterface (easytests.core.models.SolutionModelInterface)2 QuizModelEmpty (easytests.core.models.empty.QuizModelEmpty)2 AnswersServiceInterface (easytests.core.services.AnswersServiceInterface)2