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);
}
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);
}
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());
}
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);
}
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);
}
Aggregations