Search in sources :

Example 6 with QuestionsServiceInterface

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

the class AnswersOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final AnswerModelInterface answerModelFirst = Mockito.mock(AnswerModelInterface.class);
    answerModelFirst.setId(1);
    given(answerModelFirst.getQuestion()).willReturn(new QuestionModelEmpty(1));
    final AnswerModelInterface answerModelSecond = Mockito.mock(AnswerModelInterface.class);
    answerModelSecond.setId(2);
    given(answerModelSecond.getQuestion()).willReturn(new QuestionModelEmpty(2));
    final List<AnswerModelInterface> answersModels = new ArrayList<>(2);
    answersModels.add(answerModelFirst);
    answersModels.add(answerModelSecond);
    final AnswersOptionsInterface answersOptions = new AnswersOptions();
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final QuestionsOptionsInterface questionOptions = Mockito.mock(QuestionsOptionsInterface.class);
    answersOptions.setQuestionsService(questionsService);
    answersOptions.withQuestion(questionOptions);
    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<AnswerModelInterface> answersModelsWithRelations = answersOptions.withRelations(answersModels);
    Assert.assertEquals(answersModelsWithRelations, answersModels);
    verify(questionsService).find(1, questionOptions);
    verify(answersModels.get(0)).setQuestion(questionModelFirst);
    verify(questionsService).find(2, questionOptions);
    verify(answersModels.get(1)).setQuestion(questionModelSecond);
}
Also used : QuestionModelEmpty(easytests.core.models.empty.QuestionModelEmpty) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) ArrayList(java.util.ArrayList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with QuestionsServiceInterface

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

the class AnswersOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final AnswerModelInterface answerModel = Mockito.mock(AnswerModelInterface.class);
    answerModel.setId(1);
    given(answerModel.getQuestion()).willReturn(new QuestionModelEmpty(1));
    final AnswersOptionsInterface answersOptions = new AnswersOptions();
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    answersOptions.setQuestionsService(questionsService);
    answersOptions.withQuestion(questionsOptions);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    given(questionsService.find(answerModel.getQuestion().getId(), questionsOptions)).willReturn(questionModel);
    final AnswerModelInterface answerModelWithRelations = answersOptions.withRelations(answerModel);
    Assert.assertEquals(answerModel, answerModelWithRelations);
    verify(questionsService).find(1, questionsOptions);
    verify(answerModel).setQuestion(questionModel);
}
Also used : QuestionModelEmpty(easytests.core.models.empty.QuestionModelEmpty) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with QuestionsServiceInterface

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

the class AnswersOptionsTest method testSaveDeleteWithQuestion.

@Test
public void testSaveDeleteWithQuestion() {
    final AnswersOptionsInterface answersOptions = new AnswersOptions();
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    answersOptions.setQuestionsService(questionsService);
    answersOptions.withQuestion(questionsOptions);
    final AnswerModelInterface answerModel = Mockito.mock(AnswerModelInterface.class);
    final AnswersOptionsInterface answersOptionsSpy = Mockito.spy(answersOptions);
    answersOptionsSpy.deleteWithRelations(answerModel);
    verify(questionsOptions, times(1)).deleteWithRelations(answerModel.getQuestion());
    answersOptionsSpy.saveWithRelations(answerModel);
    verify(questionsOptions, times(1)).saveWithRelations(answerModel.getQuestion());
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with QuestionsServiceInterface

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

the class AnswersOptionsTest method testWithRelationsOnNull.

@Test
public void testWithRelationsOnNull() throws Exception {
    final AnswersOptionsInterface answersOptions = new AnswersOptions();
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final QuestionsOptionsInterface questionOptions = Mockito.mock(QuestionsOptionsInterface.class);
    answersOptions.setQuestionsService(questionsService);
    answersOptions.withQuestion(questionOptions);
    final AnswerModelInterface nullAnswerModel = null;
    final AnswerModelInterface answerModelWithRelations = answersOptions.withRelations(nullAnswerModel);
    Assert.assertNull(answerModelWithRelations);
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with QuestionsServiceInterface

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

the class TopicsOptionsTest method testWithRelationsQuestionsOnList.

@Test
public void testWithRelationsQuestionsOnList() throws Exception {
    final TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
    final TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
    final List<TopicModelInterface> topicsModels = new ArrayList<>(2);
    topicsModels.add(topicModelFirst);
    topicsModels.add(topicModelSecond);
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.setTopicsService(topicsService);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModelsFirst = new ArrayList<>();
    questionsModelsFirst.add(Mockito.mock(QuestionModelInterface.class));
    final List<QuestionModelInterface> questionsModelsSecond = new ArrayList<>();
    questionsModelsSecond.add(Mockito.mock(QuestionModelInterface.class));
    given(questionsService.findByTopic(topicModelFirst, questionsOptions)).willReturn(questionsModelsFirst);
    given(questionsService.findByTopic(topicModelSecond, questionsOptions)).willReturn(questionsModelsSecond);
    final List<TopicModelInterface> topicsModelsWithRelations = topicsOptions.withRelations(topicsModels);
    Assert.assertEquals(topicsModelsWithRelations, topicsModels);
    verify(questionsService).findByTopic(topicModelFirst, questionsOptions);
    verify(topicsModels.get(0)).setQuestions(questionsModelsFirst);
    verify(questionsService).findByTopic(topicModelSecond, questionsOptions);
    verify(topicsModels.get(1)).setQuestions(questionsModelsSecond);
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) 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