use of easytests.core.models.QuestionModelInterface 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);
}
use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.
the class TopicsOptionsTest method testSaveWithRelationsQuestions.
@Test
public void testSaveWithRelationsQuestions() 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(topicsService, questionsService);
topicsOptions.saveWithRelations(topicModel);
inOrder.verify(topicsService).save(topicModel);
inOrder.verify(questionsService).save(topicModel.getQuestions(), questionsOptions);
}
use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.
the class TopicsOptionsTest method testSaveDeleteWithRelationsQuestion.
@Test
public void testSaveDeleteWithRelationsQuestion() 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);
topicsOptions.saveWithRelations((topicModel));
verify(topicsService).save(topicModel);
topicsOptions.deleteWithRelations(topicModel);
verify(topicsService).delete(topicModel);
verify(questionsService, times(2)).save(topicModel.getQuestions(), questionsOptions);
}
use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.
the class QuestionsSupport method getModelMock.
private QuestionModelInterface getModelMock(Integer id, String text, Integer questionTypeId, Integer topicId) {
final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
Mockito.when(questionModel.getId()).thenReturn(id);
Mockito.when(questionModel.getText()).thenReturn(text);
Mockito.when(questionModel.getQuestionType()).thenReturn(new QuestionTypeModelEmpty(questionTypeId));
Mockito.when(questionModel.getTopic()).thenReturn(new TopicModelEmpty(topicId));
Mockito.when(questionModel.getAnswers()).thenReturn(new ModelsListEmpty());
return questionModel;
}
use of easytests.core.models.QuestionModelInterface in project easy-tests by malinink.
the class QuestionsService method map.
private QuestionModelInterface map(QuestionEntity questionEntity) {
if (questionEntity == null) {
return null;
}
final QuestionModelInterface questionModel = new QuestionModel();
questionModel.map(questionEntity);
return questionModel;
}
Aggregations